From 2d1fcee1bef76ee558ca687ad3c9053f1329e361 Mon Sep 17 00:00:00 2001 From: Fabio Ventura Date: Sun, 23 May 2021 01:11:25 +0200 Subject: [PATCH 01/13] #146 refactory Provision --- data/Migrations/Version20210522230437.php | 37 +++++++++++++ .../src/Application/Entity/Provision.php | 54 +++++++++---------- .../Application/test/Entity/ProvisionTest.php | 18 +++++++ .../Controller/CategoryController.php | 6 +-- .../view/money-log/provision/index.phtml | 6 +-- 5 files changed, 86 insertions(+), 35 deletions(-) create mode 100644 data/Migrations/Version20210522230437.php create mode 100644 module/Application/test/Entity/ProvisionTest.php diff --git a/data/Migrations/Version20210522230437.php b/data/Migrations/Version20210522230437.php new file mode 100644 index 00000000..778513c4 --- /dev/null +++ b/data/Migrations/Version20210522230437.php @@ -0,0 +1,37 @@ +abortIf( + $this->connection->getDatabasePlatform()->getName() !== 'mysql', + 'Migration can only be executed safely on \'mysql\'.' + ); + + $this->addSql('ALTER TABLE provision + CHANGE valuta date DATE NOT NULL, + CHANGE importo amount NUMERIC(8, 2) NOT NULL, + CHANGE descrizione description VARCHAR(255) NOT NULL'); + } + + public function down(Schema $schema): void + { + $this->abortIf( + $this->connection->getDatabasePlatform()->getName() !== 'mysql', + 'Migration can only be executed safely on \'mysql\'.' + ); + + $this->addSql('ALTER TABLE provision + CHANGE date valuta DATE NOT NULL, + CHANGE amount importo NUMERIC(8, 2) NOT NULL, + CHANGE description descrizione VARCHAR(255) CHARACTER SET utf8 NOT NULL COLLATE `utf8_unicode_ci`'); + } +} diff --git a/module/Application/src/Application/Entity/Provision.php b/module/Application/src/Application/Entity/Provision.php index d54cda80..77d8853f 100644 --- a/module/Application/src/Application/Entity/Provision.php +++ b/module/Application/src/Application/Entity/Provision.php @@ -36,22 +36,22 @@ class Provision implements InputFilterAwareInterface private $user; /** - * @ORM\Column(name="valuta", type="date", nullable=false) + * @ORM\Column(name="date", type="date", nullable=false) * @var \DateTime */ - private $valuta; + private $date; /** - * @ORM\Column(name="importo", type="decimal", precision=8, scale=2, nullable=false) + * @ORM\Column(name="amount", type="decimal", precision=8, scale=2, nullable=false) * @var float */ - private $importo; + private $amount; /** - * @ORM\Column(name="descrizione", type="string", nullable=false) + * @ORM\Column(name="description", type="string", nullable=false) * @var string */ - private $descrizione; + private $description; public function getId(): int { @@ -63,34 +63,34 @@ public function setUser(User $user): void $this->user = $user; } - public function getValuta(): \DateTime + public function getDate(): \DateTime { - return $this->valuta; + return $this->date; } - public function setValuta(\DateTime $valuta): void + public function setDate(\DateTime $date): void { - $this->valuta = $valuta; + $this->date = $date; } - public function getImporto(): float + public function getAmount(): float { - return $this->importo; + return $this->amount; } - public function setImporto(float $importo): void + public function setAmount(float $amount): void { - $this->importo = $importo; + $this->amount = $amount; } - public function getDescrizione(): string + public function getDescription(): string { - return $this->descrizione; + return $this->description; } - public function setDescrizione(string $descrizione): void + public function setDescription(string $description): void { - $this->descrizione = $descrizione; + $this->description = $description; } public function getArrayCopy(): array @@ -98,9 +98,6 @@ public function getArrayCopy(): array return get_object_vars($this); } - /** - * @throws \Exception - */ public function exchangeArray(array $data = []): void { if (isset($data['id'])) { @@ -110,17 +107,16 @@ public function exchangeArray(array $data = []): void $this->user = $data['userId']; } if (isset($data['valuta'])) { - $this->valuta = new \DateTime($data['valuta']); + $this->date = new \DateTime($data['valuta']); + } + if (isset($data['importo'])) { + $this->amount = $data['importo']; + } + if (isset($data['descrizione'])) { + $this->description = $data['descrizione']; } - $this->importo = $data['importo'] ?? null; - $this->descrizione = $data['descrizione'] ?? null; } - /** - * @param \Laminas\InputFilter\InputFilterInterface $inputFilter - * @return \Laminas\InputFilter\InputFilterAwareInterface - * @throws \Exception - */ public function setInputFilter(InputFilterInterface $inputFilter): InputFilterAwareInterface { throw new \Exception('Not used'); diff --git a/module/Application/test/Entity/ProvisionTest.php b/module/Application/test/Entity/ProvisionTest.php new file mode 100644 index 00000000..f3c8cd63 --- /dev/null +++ b/module/Application/test/Entity/ProvisionTest.php @@ -0,0 +1,18 @@ +setInputFilter(new InputFilter()); + } +} diff --git a/module/MoneyLog/src/MoneyLog/Controller/CategoryController.php b/module/MoneyLog/src/MoneyLog/Controller/CategoryController.php index 0a8b304c..295b151a 100644 --- a/module/MoneyLog/src/MoneyLog/Controller/CategoryController.php +++ b/module/MoneyLog/src/MoneyLog/Controller/CategoryController.php @@ -121,9 +121,9 @@ public function deleteAction(): Response if ($sum) { $provision = new Provision(); $provision->setUser($category->getUser()); - $provision->setDescrizione('Conguaglio rimozione categoria ' . $category->getDescription()); - $provision->setImporto($sum); - $provision->setValuta(new \DateTime()); + $provision->setDescription('Conguaglio rimozione categoria ' . $category->getDescription()); + $provision->setAmount($sum); + $provision->setDate(new \DateTime()); $this->em->persist($provision); } $this->em->remove($category); diff --git a/module/MoneyLog/view/money-log/provision/index.phtml b/module/MoneyLog/view/money-log/provision/index.phtml index 0a1bc00c..748e3018 100644 --- a/module/MoneyLog/view/money-log/provision/index.phtml +++ b/module/MoneyLog/view/money-log/provision/index.phtml @@ -54,9 +54,9 @@ echo $this->pageHeader('Accantonati'); - dateForma($row->getValuta()); ?> - currencyForma($row->getImporto()); ?> - getDescrizione(); ?> + dateForma($row->getDate()); ?> + currencyForma($row->getAmount()); ?> + getDescription(); ?> From 6696444fea5a2e8f904a95e13c48f88a0346dd04 Mon Sep 17 00:00:00 2001 From: Fabio Ventura Date: Sun, 23 May 2021 16:03:09 +0200 Subject: [PATCH 02/13] #146 refactory provision entity --- .../src/Application/Entity/Provision.php | 25 ++++++------ .../Repository/ProvisionRepository.php | 12 +++--- .../Application/test/Entity/ProvisionTest.php | 39 +++++++++++++++++++ .../src/MoneyLog/Form/AccantonatoForm.php | 8 ++-- .../view/money-log/provision/add.phtml | 8 ++-- .../view/money-log/provision/edit.phtml | 6 +-- 6 files changed, 67 insertions(+), 31 deletions(-) diff --git a/module/Application/src/Application/Entity/Provision.php b/module/Application/src/Application/Entity/Provision.php index 77d8853f..2fbed4a8 100644 --- a/module/Application/src/Application/Entity/Provision.php +++ b/module/Application/src/Application/Entity/Provision.php @@ -100,20 +100,17 @@ public function getArrayCopy(): array public function exchangeArray(array $data = []): void { - if (isset($data['id'])) { - $this->id = $data['id']; + if (isset($data['user'])) { + $this->user = $data['user']; } - if (isset($data['userId'])) { - $this->user = $data['userId']; + if (isset($data['date'])) { + $this->date = new \DateTime($data['date']); } - if (isset($data['valuta'])) { - $this->date = new \DateTime($data['valuta']); + if (isset($data['amount'])) { + $this->amount = $data['amount']; } - if (isset($data['importo'])) { - $this->amount = $data['importo']; - } - if (isset($data['descrizione'])) { - $this->description = $data['descrizione']; + if (isset($data['description'])) { + $this->description = $data['description']; } } @@ -128,17 +125,17 @@ public function getInputFilter(): InputFilterInterface $inputFilter = new InputFilter(); $inputFilter->add([ - 'name' => 'valuta', + 'name' => 'date', 'required' => true, 'filters' => [['name' => StringTrim::class]], ]); $inputFilter->add([ - 'name' => 'importo', + 'name' => 'amount', 'required' => true, 'filters' => [['name' => StringTrim::class]], ]); $inputFilter->add([ - 'name' => 'descrizione', + 'name' => 'description', 'required' => true, 'filters' => [['name' => StringTrim::class]], ]); diff --git a/module/Application/src/Application/Repository/ProvisionRepository.php b/module/Application/src/Application/Repository/ProvisionRepository.php index d4ff3c11..36e6f99a 100644 --- a/module/Application/src/Application/Repository/ProvisionRepository.php +++ b/module/Application/src/Application/Repository/ProvisionRepository.php @@ -4,8 +4,8 @@ namespace Application\Repository; -use Application\Entity\Provision; use Application\Entity\Movement; +use Application\Entity\Provision; use Doctrine\ORM\EntityRepository; class ProvisionRepository extends EntityRepository @@ -15,7 +15,7 @@ public function getBalance(int $userId): float $em = $this->getEntityManager(); $qb = $em ->createQueryBuilder() - ->select('COALESCE(SUM(Provision.importo), 0) AS total') + ->select('COALESCE(SUM(Provision.amount), 0) AS total') ->from(Provision::class, 'Provision') ->where('Provision.user=:userId') ->setParameter(':userId', $userId); @@ -40,11 +40,11 @@ public function search(array $params = []): array $cleanParams['userId'] = $params['userId']; } if (!empty($params['dateMin'])) { - $qb->andWhere('Provision.valuta >= :dateMin'); + $qb->andWhere('Provision.date >= :dateMin'); $cleanParams['dateMin'] = $params['dateMin']; } if (!empty($params['dateMax'])) { - $qb->andWhere('Provision.valuta <= :dateMax'); + $qb->andWhere('Provision.date <= :dateMax'); $cleanParams['dateMax'] = $params['dateMax']; } if (!empty($params['description'])) { @@ -52,7 +52,7 @@ public function search(array $params = []): array $cleanParams['description'] = '%' . $params['description'] . '%'; } - $query = $qb->setParameters($cleanParams)->orderBy('Provision.valuta', 'DESC')->getQuery(); + $query = $qb->setParameters($cleanParams)->orderBy('Provision.date', 'DESC')->getQuery(); return $query->getResult(); } @@ -66,7 +66,7 @@ public function getSum(int $userId): float { $em = $this->getEntityManager(); $qb = $em->createQueryBuilder() - ->select('COALESCE(SUM(Provision.importo), 0) AS total') + ->select('COALESCE(SUM(Provision.amount), 0) AS total') ->from(Provision::class, 'Provision') ->where('Provision.user=:userId') ->setParameter(':userId', $userId); diff --git a/module/Application/test/Entity/ProvisionTest.php b/module/Application/test/Entity/ProvisionTest.php index f3c8cd63..a42752b5 100644 --- a/module/Application/test/Entity/ProvisionTest.php +++ b/module/Application/test/Entity/ProvisionTest.php @@ -4,6 +4,7 @@ use Application\Entity\Provision; use Laminas\InputFilter\InputFilter; +use Laminas\InputFilter\InputFilterInterface; use PHPUnit\Framework\TestCase; class ProvisionTest extends TestCase @@ -12,7 +13,45 @@ public function testGettersAndSetters(): void { $provision = new Provision(); + $amount = 67.65; + $provision->setAmount($amount); + self::assertSame($amount, $provision->getAmount()); + + $date = new \DateTime(); + $provision->setDate($date); + self::assertSame($date, $provision->getDate()); + + $description = 'Description'; + $provision->setDescription($description); + self::assertSame($description, $provision->getDescription()); + + self::assertInstanceOf(InputFilterInterface::class, $provision->getInputFilter()); + self::expectException(\Exception::class); $provision->setInputFilter(new InputFilter()); } + + public function testArrayExchangeAndCopy(): void + { + $provision = new Provision(); + + $amount = 23.34; + $date = '2021-04-13'; + $description = 'Description'; + $user = 1; + + $provision->exchangeArray([ + 'amount' => $amount, + 'date' => $date, + 'description' => $description, + 'user' => $user, + ]); + + $copy = $provision->getArrayCopy(); + + self::assertSame($amount, $copy['amount']); + self::assertSame($date, $copy['date']->format('Y-m-d')); + self::assertSame($description, $copy['description']); + self::assertSame($user, $copy['user']); + } } diff --git a/module/MoneyLog/src/MoneyLog/Form/AccantonatoForm.php b/module/MoneyLog/src/MoneyLog/Form/AccantonatoForm.php index 0fa153e8..847f1252 100644 --- a/module/MoneyLog/src/MoneyLog/Form/AccantonatoForm.php +++ b/module/MoneyLog/src/MoneyLog/Form/AccantonatoForm.php @@ -13,8 +13,8 @@ public function __construct($name = 'accantona') $this->add([ 'attributes' => ['class' => 'form-control', 'value' => date('Y-m-d')], - 'name' => 'valuta', - 'options' => ['label' => 'Valuta'], + 'name' => 'date', + 'options' => ['label' => 'Data'], 'required' => true, 'type' => 'Date', ]); @@ -25,7 +25,7 @@ public function __construct($name = 'accantona') 'placeholder' => '0.00', 'step' => 0.01 ], - 'name' => 'importo', + 'name' => 'amount', 'options' => ['label' => 'Importo'], 'required' => true, 'type' => 'Number', @@ -33,7 +33,7 @@ public function __construct($name = 'accantona') $this->add([ 'attributes' => ['class' => 'form-control', 'maxlength' => 255, 'placeholder' => 'Descrizione'], 'filters' => [['name' => 'Laminas\Filter\StringTrim']], - 'name' => 'descrizione', + 'name' => 'description', 'options' => ['label' => 'Descrizione'], 'required' => true, 'type' => 'Text', diff --git a/module/MoneyLog/view/money-log/provision/add.phtml b/module/MoneyLog/view/money-log/provision/add.phtml index 30d67e14..b98d9aa5 100644 --- a/module/MoneyLog/view/money-log/provision/add.phtml +++ b/module/MoneyLog/view/money-log/provision/add.phtml @@ -14,11 +14,11 @@ echo $this->pageHeader('Aggiungi accantonamento'); Aggiungi accantonamento
- setAttribute('action', $this->url('accantona_accantonato', array('action' => 'add')))->prepare(); ?> + setAttribute('action', $this->url('accantona_accantonato', ['action' => 'add']))->prepare(); ?> form()->openTag($form); ?> - sbaFormRow($form->get('valuta')); ?> - sbaFormRow($form->get('importo')); ?> - sbaFormRow($form->get('descrizione')); ?> + sbaFormRow($form->get('date')); ?> + sbaFormRow($form->get('amount')); ?> + sbaFormRow($form->get('description')); ?>
Annulla diff --git a/module/MoneyLog/view/money-log/provision/edit.phtml b/module/MoneyLog/view/money-log/provision/edit.phtml index 2988e513..68f7db98 100644 --- a/module/MoneyLog/view/money-log/provision/edit.phtml +++ b/module/MoneyLog/view/money-log/provision/edit.phtml @@ -17,9 +17,9 @@ echo $this->pageHeader('Modifica accantonamento'); prepare(); ?> form()->openTag($form); ?> - sbaFormRow($form->get('valuta')); ?> - sbaFormRow($form->get('importo')); ?> - sbaFormRow($form->get('descrizione')); ?> + sbaFormRow($form->get('date')); ?> + sbaFormRow($form->get('amount')); ?> + sbaFormRow($form->get('description')); ?>
Annulla From 7ca6810cf8a18ae4938d735c39174f28a2341d32 Mon Sep 17 00:00:00 2001 From: Fabio Ventura Date: Sun, 23 May 2021 18:48:54 +0200 Subject: [PATCH 03/13] #146 add strict_types on setting --- module/Application/src/Application/Entity/Setting.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/module/Application/src/Application/Entity/Setting.php b/module/Application/src/Application/Entity/Setting.php index 1fabe62d..dc0c1287 100644 --- a/module/Application/src/Application/Entity/Setting.php +++ b/module/Application/src/Application/Entity/Setting.php @@ -1,5 +1,7 @@ Date: Sun, 23 May 2021 20:32:20 +0200 Subject: [PATCH 04/13] #147 setting entity refactory --- data/Migrations/Version20210523181349.php | 37 +++++++++ .../src/Application/Entity/Setting.php | 83 ++++++++----------- module/Auth/src/Auth/Service/UserData.php | 6 +- .../Controller/DashboardController.php | 10 +-- .../Controller/SettingsController.php | 6 +- .../src/MoneyLog/Form/SettingForm.php | 46 ++++++++++ .../src/MoneyLog/Form/SettingsForm.php | 43 ---------- .../view/money-log/settings/index.phtml | 8 +- 8 files changed, 133 insertions(+), 106 deletions(-) create mode 100644 data/Migrations/Version20210523181349.php create mode 100644 module/MoneyLog/src/MoneyLog/Form/SettingForm.php delete mode 100644 module/MoneyLog/src/MoneyLog/Form/SettingsForm.php diff --git a/data/Migrations/Version20210523181349.php b/data/Migrations/Version20210523181349.php new file mode 100644 index 00000000..4da1c538 --- /dev/null +++ b/data/Migrations/Version20210523181349.php @@ -0,0 +1,37 @@ +abortIf( + $this->connection->getDatabasePlatform()->getName() !== 'mysql', + 'Migration can only be executed safely on \'mysql\'.' + ); + + $this->addSql('ALTER TABLE setting + CHANGE payday paypay SMALLINT UNSIGNED DEFAULT 1 NOT NULL, + CHANGE monthsretrospective months SMALLINT UNSIGNED DEFAULT 12 NOT NULL, + CHANGE stored provisioning TINYINT(1) DEFAULT 0 NOT NULL'); + } + + public function down(Schema $schema): void + { + $this->abortIf( + $this->connection->getDatabasePlatform()->getName() !== 'mysql', + 'Migration can only be executed safely on \'mysql\'.' + ); + + $this->addSql('ALTER TABLE setting + CHANGE paypay payDay SMALLINT UNSIGNED DEFAULT 1 NOT NULL, + CHANGE months monthsRetrospective SMALLINT UNSIGNED DEFAULT 12 NOT NULL, + CHANGE provisioning stored TINYINT(1) DEFAULT 0 NOT NULL'); + } +} diff --git a/module/Application/src/Application/Entity/Setting.php b/module/Application/src/Application/Entity/Setting.php index dc0c1287..0182b62b 100644 --- a/module/Application/src/Application/Entity/Setting.php +++ b/module/Application/src/Application/Entity/Setting.php @@ -30,59 +30,59 @@ class Setting implements InputFilterAwareInterface protected $user; /** - * @ORM\Column(name="payDay", type="smallint", nullable=false, options={"unsigned"=true, "default"=1}) + * @ORM\Column(name="paypay", type="smallint", nullable=false, options={"unsigned"=true, "default"=1}) * @var int */ - protected $payDay = 1; + protected $payday = 1; /** - * @ORM\Column(name="monthsRetrospective", type="smallint", nullable=false, options={"unsigned"=true, "default"=12}) + * @ORM\Column(name="months", type="smallint", nullable=false, options={"unsigned"=true, "default"=12}) * @var int */ - protected $monthsRetrospective = 12; + protected $months = 12; /** - * @ORM\Column(name="`stored`", type="boolean", nullable=false, options={"default"=false}) + * @ORM\Column(name="provisioning", type="boolean", nullable=false, options={"default"=false}) * @var boolean */ - protected $stored = false; + protected $provisioning = false; public function __construct(User $user) { $this->user = $user; } - public function getPayDay(): int + public function getPayday(): int { - return $this->payDay; + return $this->payday; } - public function setPayDay(int $payDay): void + public function setPayday(int $payday): void { - if ($payDay < 1 || $payDay > 28) { - throw new \RuntimeException("Invalid payDay value: $payDay"); + if ($payday < 1 || $payday > 28) { + throw new \RuntimeException("Invalid payDay value: $payday"); } - $this->payDay = $payDay; + $this->payday = $payday; } - public function getMonthsRetrospective(): int + public function getMonths(): int { - return $this->monthsRetrospective; + return $this->months; } - public function setMonthsRetrospective(int $monthsRetrospective): void + public function setMonths(int $months): void { - $this->monthsRetrospective = $monthsRetrospective; + $this->months = $months; } - public function hasStored(): bool + public function hasProvisioning(): bool { - return $this->stored; + return $this->provisioning; } - public function setStored(bool $stored): void + public function setProvisioning(bool $provisioning): void { - $this->stored = $stored; + $this->provisioning = $provisioning; } public function getArrayCopy(): array @@ -90,35 +90,22 @@ public function getArrayCopy(): array return get_object_vars($this); } - /** - * Populate from an array. - * - * @param array $data - * @return Setting - */ - public function exchangeArray(array $data): self + public function exchangeArray(array $data): void { - if (isset($data['payDay'])) { - $this->setPayDay((int) $data['payDay']); + if (isset($data['payday'])) { + $this->setPayday((int) $data['payday']); } - if (isset($data['monthsRetrospective'])) { - $this->setMonthsRetrospective((int) $data['monthsRetrospective']); + if (isset($data['months'])) { + $this->setMonths((int) $data['months']); } - if (isset($data['stored'])) { - $this->setStored((bool) $data['stored']); + if (isset($data['provisioning'])) { + $this->setProvisioning((bool) $data['provisioning']); } - return $this; } - /** - * Set input filter - * @param \Laminas\InputFilter\InputFilterInterface $inputFilter - * @return $this - */ - public function setInputFilter(InputFilterInterface $inputFilter): self + public function setInputFilter(InputFilterInterface $inputFilter) { - $this->inputFilter = $inputFilter; - return $this; + throw new \Exception('Not used'); } public function getInputFilter(): InputFilterInterface @@ -126,18 +113,18 @@ public function getInputFilter(): InputFilterInterface if (!$this->inputFilter) { $this->inputFilter = new InputFilter(); $this->inputFilter->add([ - 'filters' => [['name' => ToInt::class]], - 'name' => 'payDay', + 'filters' => [['name' => ToInt::class]], + 'name' => 'payday', 'required' => true, ]); $this->inputFilter->add([ - 'filters' => [['name' => ToInt::class]], - 'name' => 'monthsRetrospective', + 'filters' => [['name' => ToInt::class]], + 'name' => 'months', 'required' => true, ]); $this->inputFilter->add([ - 'filters' => [['name' => ToInt::class]], - 'name' => 'stored', + 'filters' => [['name' => ToInt::class]], + 'name' => 'provisioning', 'required' => true, ]); } diff --git a/module/Auth/src/Auth/Service/UserData.php b/module/Auth/src/Auth/Service/UserData.php index 084668d8..8031f757 100644 --- a/module/Auth/src/Auth/Service/UserData.php +++ b/module/Auth/src/Auth/Service/UserData.php @@ -49,9 +49,9 @@ public function getSurname(): string public function setSettings(Setting $settings): self { $this->data->settings = [ - 'payDay' => $settings->getPayDay(), - 'monthsRetrospective' => $settings->getMonthsRetrospective(), - 'stored' => $settings->hasStored(), + 'payDay' => $settings->getPayday(), + 'monthsRetrospective' => $settings->getMonths(), + 'stored' => $settings->hasProvisioning(), ]; return $this; } diff --git a/module/MoneyLog/src/MoneyLog/Controller/DashboardController.php b/module/MoneyLog/src/MoneyLog/Controller/DashboardController.php index c361a09c..8f1814c8 100644 --- a/module/MoneyLog/src/MoneyLog/Controller/DashboardController.php +++ b/module/MoneyLog/src/MoneyLog/Controller/DashboardController.php @@ -4,10 +4,10 @@ namespace MoneyLog\Controller; -use Application\Entity\Provision; use Application\Entity\Account; use Application\Entity\Category; use Application\Entity\Movement; +use Application\Entity\Provision; use Application\Entity\Setting; use Doctrine\ORM\EntityManagerInterface; use Laminas\Mvc\Controller\AbstractActionController; @@ -48,7 +48,7 @@ public function indexAction(): ViewModel /** @var Setting $setting */ $setting = $this->em->find(Setting::class, $this->user->id); - $since = new \DateTime('-' . $setting->getMonthsRetrospective() . ' MONTH'); + $since = new \DateTime('-' . $setting->getMonths() . ' MONTH'); $avgPerCategory = $categoryRepository->getAverages($this->user->id, $since); usort($avgPerCategory, static function ($a, $b) { @@ -61,8 +61,8 @@ public function indexAction(): ViewModel $donutSpends = []; $donutAccounts = []; $currentDay = date('j'); - $monthBudget = $stored > 0 && $setting->hasStored() ? 0 - $stored : 0; - $payDay = $setting->getPayDay(); + $monthBudget = $stored > 0 && $setting->hasProvisioning() ? 0 - $stored : 0; + $payDay = $setting->getPayday(); foreach ($avgPerCategory as $category) { if ($category['average'] < 0) { @@ -77,7 +77,7 @@ public function indexAction(): ViewModel if ($payDay) { if ($currentDay < $payDay) { - $remainingDays = $setting->getPayDay() - $currentDay; + $remainingDays = $setting->getPayday() - $currentDay; $begin = date("Y-m-$payDay", (int) strtotime('last month')); } else { $remainingDays = date('t') - $currentDay + $payDay; diff --git a/module/MoneyLog/src/MoneyLog/Controller/SettingsController.php b/module/MoneyLog/src/MoneyLog/Controller/SettingsController.php index 8c452f46..c7b7f282 100644 --- a/module/MoneyLog/src/MoneyLog/Controller/SettingsController.php +++ b/module/MoneyLog/src/MoneyLog/Controller/SettingsController.php @@ -8,9 +8,9 @@ use Doctrine\ORM\OptimisticLockException; use Doctrine\ORM\ORMException; use Doctrine\ORM\TransactionRequiredException; -use Laminas\View\Model\ViewModel; -use MoneyLog\Form\SettingsForm; use Laminas\Mvc\Controller\AbstractActionController; +use Laminas\View\Model\ViewModel; +use MoneyLog\Form\SettingForm; class SettingsController extends AbstractActionController { @@ -47,7 +47,7 @@ public function indexAction(): ViewModel $setting = $this->em->find(Setting::class, $this->user->id); $message = ''; - $form = new SettingsForm(); + $form = new SettingForm(); $form->bind($setting); $request = $this->getRequest(); diff --git a/module/MoneyLog/src/MoneyLog/Form/SettingForm.php b/module/MoneyLog/src/MoneyLog/Form/SettingForm.php new file mode 100644 index 00000000..e7219508 --- /dev/null +++ b/module/MoneyLog/src/MoneyLog/Form/SettingForm.php @@ -0,0 +1,46 @@ +add([ + 'attributes' => ['max' => 28, 'min' => 0, 'step' => 1, 'value' => 27], + 'filters' => [['name' => StringTrim::class]], + 'name' => 'payday', + 'options' => ['label' => 'Giorno di paga'], + 'required' => true, + 'type' => 'Number', + ]); + $this->add([ + 'attributes' => ['max' => 48, 'min' => 2, 'step' => 1, 'value' => 12], + 'filters' => [['name' => StringTrim::class]], + 'name' => 'months', + 'options' => ['label' => 'Mesi di retrospettiva'], + 'required' => true, + 'type' => 'Number', + ]); + $this->add([ + 'filters' => [['name' => StringTrim::class]], + 'name' => 'provisioning', + 'options' => [ + 'checked_value' => 1, + 'label' => 'Abilita accantonamento', + 'unchecked_value' => 0, + 'use_hidden_element' => true, + ], + 'required' => true, + 'type' => 'Checkbox', + ]); + } +} diff --git a/module/MoneyLog/src/MoneyLog/Form/SettingsForm.php b/module/MoneyLog/src/MoneyLog/Form/SettingsForm.php deleted file mode 100644 index 4ee46068..00000000 --- a/module/MoneyLog/src/MoneyLog/Form/SettingsForm.php +++ /dev/null @@ -1,43 +0,0 @@ -add([ - 'attributes' => ['max' => 28, 'min' => 0, 'step' => 1, 'value' => 27], - 'filters' => [['name' => 'Laminas\Filter\StringTrim']], - 'name' => 'payDay', - 'options' => ['label' => 'Giorno di paga'], - 'required' => true, - 'type' => 'Number', - ]); - $this->add([ - 'attributes' => ['max' => 48, 'min' => 2, 'step' => 1, 'value' => 12], - 'filters' => [['name' => 'Laminas\Filter\StringTrim']], - 'name' => 'monthsRetrospective', - 'options' => ['label' => 'Mesi di retrospettiva'], - 'required' => true, - 'type' => 'Number', - ]); - $this->add([ - 'filters' => [['name' => 'Laminas\Filter\StringTrim']], - 'name' => 'stored', - 'options' => [ - 'checked_value' => 1, - 'label' => 'Abilita accantonamento', - 'unchecked_value' => 0, - 'use_hidden_element' => true, - ], - 'required' => true, - 'type' => 'Checkbox', - ]); - } -} diff --git a/module/MoneyLog/view/money-log/settings/index.phtml b/module/MoneyLog/view/money-log/settings/index.phtml index 18dda58a..d66f826e 100644 --- a/module/MoneyLog/view/money-log/settings/index.phtml +++ b/module/MoneyLog/view/money-log/settings/index.phtml @@ -1,7 +1,7 @@ pageHeader('Impostazioni'); @@ -16,9 +16,9 @@ echo $this->pageHeader('Impostazioni'); prepare(); ?> form()->openTag($form); ?> - sbaFormRow($form->get('payDay'), 'Se impostato, viene visualizzato nel cruscotto il calcolo dei giorni mancanti al prossimo stipendio e il budget medio giornaliero fino al prossimo stipendio.'); ?> - sbaFormRow($form->get('monthsRetrospective'), 'Numero di mesi utilizzatto per la statistica della media delle spese.'); ?> - sbaFormRow($form->get('stored'), 'L\'accantonamento è una quota del budget che serve a coprire le spese categorizzate'); ?> + sbaFormRow($form->get('payday'), 'Se impostato, viene visualizzato nel cruscotto il calcolo dei giorni mancanti al prossimo stipendio e il budget medio giornaliero fino al prossimo stipendio.'); ?> + sbaFormRow($form->get('months'), 'Numero di mesi utilizzatto per la statistica della media delle spese.'); ?> + sbaFormRow($form->get('provisioning'), 'L\'accantonamento è una quota del budget che serve a coprire le spese categorizzate'); ?>
From 58120a44624a0a8917b7ef74dc314849c1691861 Mon Sep 17 00:00:00 2001 From: Fabio Ventura Date: Sun, 23 May 2021 20:56:40 +0200 Subject: [PATCH 05/13] #147 add Setting tests --- .../Application/test/Entity/SettingTest.php | 65 +++++++++++++++++++ phpstan.neon.dist | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 module/Application/test/Entity/SettingTest.php diff --git a/module/Application/test/Entity/SettingTest.php b/module/Application/test/Entity/SettingTest.php new file mode 100644 index 00000000..6c4c3b22 --- /dev/null +++ b/module/Application/test/Entity/SettingTest.php @@ -0,0 +1,65 @@ +setMonths($months); + self::assertSame($months, $setting->getMonths()); + + $payday = 2; + $setting->setPayday($payday); + self::assertSame($payday, $setting->getPayday()); + + $provisioning = true; + $setting->setProvisioning($provisioning); + self::assertSame($provisioning, $setting->hasProvisioning()); + + self::assertInstanceOf(InputFilter::class, $setting->getInputFilter()); + + self::expectException(\Exception::class); + $setting->setInputFilter(new InputFilter()); + } + + public function setPaydayException(): void + { + $user = new User(); + $setting = new Setting($user); + + self::expectException(\Exception::class); + $setting->setPayday(29); + } + + public function testArrayExchangeAndCopy(): void + { + $user = new User(); + $setting = new Setting($user); + + $months = 54; + $payday = 12; + $provisioning = true; + + $setting->exchangeArray([ + 'months' => $months, + 'payday' => $payday, + 'provisioning' => $provisioning, + ]); + + $copy = $setting->getArrayCopy(); + + self::assertSame($months, $copy['months']); + self::assertSame($payday, $copy['payday']); + self::assertSame($provisioning, $copy['provisioning']); + } +} diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 94456238..7118c6dd 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -36,7 +36,7 @@ parameters: - '/PHPDoc tag @var for variable \$form has no value type specified in iterable type MoneyLog\\Form\\AccantonatoForm\./' - '/PHPDoc tag @var for variable \$form has no value type specified in iterable type MoneyLog\\Form\\CategoryForm\./' - '/PHPDoc tag @var for variable \$form has no value type specified in iterable type MoneyLog\\Form\\MovementForm\./' - - '/PHPDoc tag @var for variable \$form has no value type specified in iterable type MoneyLog\\Form\\SettingsForm\./' + - '/PHPDoc tag @var for variable \$form has no value type specified in iterable type MoneyLog\\Form\\SettingForm\./' - '/PHPDoc tag @var for variable \$formData has no value type specified in iterable type array\./' - '/Parameter #1 \(Laminas\\View\\Helper\\Partial\|string\) of echo cannot be converted to string\./' - '/Property Auth\\Service\\UserData::\$data type has no value type specified in iterable type Laminas\\Session\\Container\./' From bf6f738f73b2cbac096b99c026e4436e8995fe5e Mon Sep 17 00:00:00 2001 From: Fabio Ventura Date: Sun, 23 May 2021 21:52:02 +0200 Subject: [PATCH 06/13] #147 add user tests --- .../src/Application/Entity/User.php | 86 +++++++---------- module/Application/test/Entity/UserTest.php | 93 +++++++++++++++++++ 2 files changed, 125 insertions(+), 54 deletions(-) create mode 100644 module/Application/test/Entity/UserTest.php diff --git a/module/Application/src/Application/Entity/User.php b/module/Application/src/Application/Entity/User.php index b5ad82f7..08d5f7d1 100644 --- a/module/Application/src/Application/Entity/User.php +++ b/module/Application/src/Application/Entity/User.php @@ -5,8 +5,8 @@ namespace Application\Entity; use Doctrine\ORM\Mapping as ORM; -use Laminas\InputFilter\InputFilterAwareInterface; use Laminas\InputFilter\InputFilter; +use Laminas\InputFilter\InputFilterAwareInterface; use Laminas\InputFilter\InputFilterInterface; /** @@ -102,47 +102,37 @@ public function getArrayCopy(): array return get_object_vars($this); } - /** - * Populate from an array. - * - * @param array $data - */ public function exchangeArray(array $data = []): void { - $this->id = $data['id'] ?? null; - $this->name = $data['name'] ?? null; - $this->surname = $data['surname'] ?? null; - - if (array_key_exists('email', $data)) { - $this->email = $data['email']; + if (isset($data['name'])) { + $this->setName($data['name']); + } + if (isset($data['surname'])) { + $this->setSurname($data['surname']); + } + if (isset($data['email'])) { + $this->setEmail($data['email']); } - if (array_key_exists('password', $data)) { - $this->password = $data['password']; + if (isset($data['password'])) { + $this->setPassword($data['password']); } - if (array_key_exists('salt', $data)) { - $this->salt = $data['salt']; + if (isset($data['salt'])) { + $this->setSalt($data['salt']); } - if (array_key_exists('status', $data)) { - $this->status = $data['status']; + if (isset($data['status'])) { + $this->setStatus((int) $data['status']); } - if (array_key_exists('role', $data)) { - $this->role = $data['role']; + if (isset($data['role'])) { + $this->setRole($data['role']); } - if (array_key_exists('registrationToken', $data)) { + if (isset($data['registrationToken'])) { $this->registrationToken = $data['registrationToken']; } } - /** - * ATTENZIONE: filtri e form devono avere esattamente gli stessi campi - * - * @param InputFilterInterface $inputFilter - * @return $this - */ - public function setInputFilter(InputFilterInterface $inputFilter): self + public function setInputFilter(InputFilterInterface $inputFilter) { - $this->inputFilter = $inputFilter; - return $this; + throw new \Exception('Not implemented'); } public function getInputFilter(): InputFilterInterface @@ -190,21 +180,14 @@ public function getId(): int return $this->id; } - public function setId(int $id): self - { - $this->id = $id; - return $this; - } - public function getEmail(): string { return $this->email; } - public function setEmail(string $email): self + public function setEmail(string $email): void { $this->email = $email; - return $this; } public function getName(): string @@ -212,10 +195,9 @@ public function getName(): string return $this->name; } - public function setName(string $name): self + public function setName(string $name): void { $this->name = $name; - return $this; } public function getSurname(): string @@ -223,10 +205,9 @@ public function getSurname(): string return $this->surname; } - public function setSurname(string $surname): self + public function setSurname(string $surname): void { $this->surname = $surname; - return $this; } public function getRole(): string @@ -234,16 +215,14 @@ public function getRole(): string return $this->role; } - public function setRole(string $role): self + public function setRole(string $role): void { $this->role = $role; - return $this; } - public function setLastLogin(\DateTime $date): self + public function setLastLogin(\DateTime $date): void { $this->lastLogin = $date; - return $this; } public function getLastLogin(): \DateTime @@ -256,10 +235,9 @@ public function getPassword(): string return $this->password; } - public function setPassword(string $password): self + public function setPassword(string $password): void { $this->password = $password; - return $this; } public function getSalt(): string @@ -267,10 +245,9 @@ public function getSalt(): string return $this->salt; } - public function setSalt(string $salt): self + public function setSalt(string $salt): void { $this->salt = $salt; - return $this; } public function getStatus(): int @@ -278,10 +255,12 @@ public function getStatus(): int return $this->status; } - public function setStatus(int $status): self + public function setStatus(int $status): void { + if (!in_array($status, [self::STATUS_NOT_CONFIRMED, self::STATUS_CONFIRMED])) { + throw new \Exception("Invalid status: $status"); + } $this->status = $status; - return $this; } public function getSetting(): Setting @@ -289,10 +268,9 @@ public function getSetting(): Setting return $this->setting; } - public function setSetting(Setting $setting): self + public function setSetting(Setting $setting): void { $this->setting = $setting; - return $this; } public function getRegistrationToken(): string diff --git a/module/Application/test/Entity/UserTest.php b/module/Application/test/Entity/UserTest.php new file mode 100644 index 00000000..f642ed98 --- /dev/null +++ b/module/Application/test/Entity/UserTest.php @@ -0,0 +1,93 @@ +setStatus($status); + self::assertSame($status, $user->getStatus()); + + $password = 'password'; + $user->setPassword($password); + self::assertSame($password, $user->getPassword()); + + $email = 'email'; + $user->setEmail($email); + self::assertSame($email, $user->getEmail()); + + $lastLogin = new \DateTime(); + $user->setLastLogin($lastLogin); + self::assertSame($lastLogin, $user->getLastLogin()); + + $name = 'name'; + $user->setName($name); + self::assertSame($name, $user->getName()); + + $role = 'role'; + $user->setRole($role); + self::assertSame($role, $user->getRole()); + + $salt = 'salt'; + $user->setSalt($salt); + self::assertSame($salt, $user->getSalt()); + + $setting = new Setting($user); + $user->setSetting($setting); + self::assertSame($setting, $user->getSetting()); + + $surname = 'surname'; + $user->setSurname($surname); + self::assertSame($surname, $user->getSurname()); + + self::assertInstanceOf(InputFilter::class, $user->getInputFilter()); + + self::expectException(\Exception::class); + $user->setInputFilter(new InputFilter()); + } + + public function testArrayExchangeAndCopy(): void + { + $user = new User(); + + $email = 'email'; + $name = 'name'; + $password = 'password'; + $registrationToken = 'registrationToken'; + $role = 'role'; + $salt = 'salt'; + $status = User::STATUS_NOT_CONFIRMED; + $surname = 'surname'; + + $user->exchangeArray([ + 'email' => $email, + 'name' => $name, + 'password' => $password, + 'registrationToken' => $registrationToken, + 'role' => $role, + 'salt' => $salt, + 'status' => $status, + 'surname' => $surname, + ]); + + $copy = $user->getArrayCopy(); + + self::assertSame($email, $copy['email']); + self::assertSame($name, $copy['name']); + self::assertSame($password, $copy['password']); + self::assertSame($registrationToken, $copy['registrationToken']); + self::assertSame($role, $copy['role']); + self::assertSame($salt, $copy['salt']); + self::assertSame($status, $copy['status']); + self::assertSame($surname, $copy['surname']); + } +} From bc32b9a5ec5d4ada1342605f6c726be835a71f71 Mon Sep 17 00:00:00 2001 From: Fabio Ventura Date: Sun, 23 May 2021 21:53:16 +0200 Subject: [PATCH 07/13] #147 add user tests --- module/Auth/src/Auth/Controller/UserController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/Auth/src/Auth/Controller/UserController.php b/module/Auth/src/Auth/Controller/UserController.php index 8e48490c..38ba7da0 100644 --- a/module/Auth/src/Auth/Controller/UserController.php +++ b/module/Auth/src/Auth/Controller/UserController.php @@ -80,7 +80,8 @@ public function updateAction() if ($form->isValid()) { /** @var User $data */ $data = $form->getData(); - $user->setName($data->getName())->setSurname($data->getSurname()); + $user->setName($data->getName()); + $user->setSurname($data->getSurname()); $this->em->persist($user); $this->em->flush(); $message = 'I tuoi dati sono stati salvati correttamente'; From 67797355f53a58f5107440e184742d8f1f153ebb Mon Sep 17 00:00:00 2001 From: Fabio Ventura Date: Sun, 23 May 2021 22:08:37 +0200 Subject: [PATCH 08/13] modified test config --- phpunit.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 291c5955..1640da08 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,6 +11,7 @@ ./module/Application/src + ./module/Auth/src From 311fc02b78e573f0be0a8f10569d9bd52f69f78d Mon Sep 17 00:00:00 2001 From: Fabio Ventura Date: Sun, 23 May 2021 22:33:52 +0200 Subject: [PATCH 09/13] modfied arrayCopy functions --- .../src/Application/Entity/Account.php | 9 +++++++- .../src/Application/Entity/Category.php | 7 ++++++- .../src/Application/Entity/Movement.php | 9 +++++++- .../src/Application/Entity/Provision.php | 8 ++++++- .../src/Application/Entity/Setting.php | 7 ++++++- .../src/Application/Entity/User.php | 21 ++++++++++++------- module/Application/test/Entity/UserTest.php | 7 +++---- 7 files changed, 52 insertions(+), 16 deletions(-) diff --git a/module/Application/src/Application/Entity/Account.php b/module/Application/src/Application/Entity/Account.php index 7cad254e..7767055e 100644 --- a/module/Application/src/Application/Entity/Account.php +++ b/module/Application/src/Application/Entity/Account.php @@ -88,7 +88,14 @@ public function isClosed(): bool public function getArrayCopy(): array { - return get_object_vars($this); + return [ + 'id' => $this->id, + 'user' => $this->user, + 'name' => $this->name, + 'recap' => $this->recap, + 'closed' => $this->closed, + 'movements' => $this->movements, + ]; } public function exchangeArray(array $data = []): self diff --git a/module/Application/src/Application/Entity/Category.php b/module/Application/src/Application/Entity/Category.php index 1805f35a..cab1804e 100644 --- a/module/Application/src/Application/Entity/Category.php +++ b/module/Application/src/Application/Entity/Category.php @@ -89,7 +89,12 @@ public function setStatus(int $status): void public function getArrayCopy(): array { - return get_object_vars($this); + return [ + 'id' => $this->id, + 'user' => $this->user, + 'description' => $this->description, + 'status' => $this->status, + ]; } public function exchangeArray(array $data = []): void diff --git a/module/Application/src/Application/Entity/Movement.php b/module/Application/src/Application/Entity/Movement.php index 00692841..94de8e3a 100644 --- a/module/Application/src/Application/Entity/Movement.php +++ b/module/Application/src/Application/Entity/Movement.php @@ -119,7 +119,14 @@ public function setDescription(string $description): void public function getArrayCopy(): array { - return get_object_vars($this); + return [ + 'id' => $this->id, + 'account' => $this->amount, + 'category' => $this->category, + 'date' => $this->date, + 'amount' => $this->amount, + 'description' => $this->description, + ]; } public function exchangeArray(array $data): void diff --git a/module/Application/src/Application/Entity/Provision.php b/module/Application/src/Application/Entity/Provision.php index 2fbed4a8..6e8ed1d8 100644 --- a/module/Application/src/Application/Entity/Provision.php +++ b/module/Application/src/Application/Entity/Provision.php @@ -95,7 +95,13 @@ public function setDescription(string $description): void public function getArrayCopy(): array { - return get_object_vars($this); + return [ + 'id' => $this->id, + 'user' => $this->user, + 'date' => $this->date, + 'amount' => $this->amount, + 'description' => $this->description, + ]; } public function exchangeArray(array $data = []): void diff --git a/module/Application/src/Application/Entity/Setting.php b/module/Application/src/Application/Entity/Setting.php index 0182b62b..f65724dd 100644 --- a/module/Application/src/Application/Entity/Setting.php +++ b/module/Application/src/Application/Entity/Setting.php @@ -87,7 +87,12 @@ public function setProvisioning(bool $provisioning): void public function getArrayCopy(): array { - return get_object_vars($this); + return [ + 'user' => $this->user, + 'payday' => $this->payday, + 'months' => $this->months, + 'provisioning' => $this->provisioning, + ]; } public function exchangeArray(array $data): void diff --git a/module/Application/src/Application/Entity/User.php b/module/Application/src/Application/Entity/User.php index 08d5f7d1..061ceceb 100644 --- a/module/Application/src/Application/Entity/User.php +++ b/module/Application/src/Application/Entity/User.php @@ -92,14 +92,21 @@ class User implements InputFilterAwareInterface */ private $setting; - /** - * Convert the object to an array. - * - * @return array - */ public function getArrayCopy(): array { - return get_object_vars($this); + return [ + 'id' => $this->id, + 'email' => $this->email, + 'name' => $this->name, + 'surname' => $this->surname, + 'password' => $this->password, + 'salt' => $this->salt, + 'status' => $this->status, + 'role' => $this->role, + 'registrationToken' => $this->registrationToken, + 'lastLogin' => $this->lastLogin, + 'setting' => $this->setting, + ]; } public function exchangeArray(array $data = []): void @@ -132,7 +139,7 @@ public function exchangeArray(array $data = []): void public function setInputFilter(InputFilterInterface $inputFilter) { - throw new \Exception('Not implemented'); + $this->inputFilter = $inputFilter; } public function getInputFilter(): InputFilterInterface diff --git a/module/Application/test/Entity/UserTest.php b/module/Application/test/Entity/UserTest.php index f642ed98..29e1ef14 100644 --- a/module/Application/test/Entity/UserTest.php +++ b/module/Application/test/Entity/UserTest.php @@ -49,10 +49,9 @@ public function testGettersAndSetters(): void $user->setSurname($surname); self::assertSame($surname, $user->getSurname()); - self::assertInstanceOf(InputFilter::class, $user->getInputFilter()); - - self::expectException(\Exception::class); - $user->setInputFilter(new InputFilter()); + $inputFilter = new InputFilter(); + $user->setInputFilter($inputFilter); + self::assertSame($inputFilter, $user->getInputFilter()); } public function testArrayExchangeAndCopy(): void From a91c709168ffc2a8d967abc4725cf7bed5f30364 Mon Sep 17 00:00:00 2001 From: Fabio Ventura Date: Mon, 24 May 2021 08:12:40 +0200 Subject: [PATCH 10/13] Fix User Entity --- module/Application/src/Application/Entity/User.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/Application/src/Application/Entity/User.php b/module/Application/src/Application/Entity/User.php index 061ceceb..b9cdc5a1 100644 --- a/module/Application/src/Application/Entity/User.php +++ b/module/Application/src/Application/Entity/User.php @@ -137,9 +137,10 @@ public function exchangeArray(array $data = []): void } } - public function setInputFilter(InputFilterInterface $inputFilter) + public function setInputFilter(InputFilterInterface $inputFilter): self { $this->inputFilter = $inputFilter; + return $this; } public function getInputFilter(): InputFilterInterface From 4187c3e02ac713ac1eb89d2bf0af7748a9efb060 Mon Sep 17 00:00:00 2001 From: Fabio Ventura Date: Mon, 24 May 2021 14:30:59 +0200 Subject: [PATCH 11/13] removed Auth/Model/Auth.php --- .../src/Auth/Controller/UserController.php | 4 +- .../Auth/src/Auth/Form/Filter/LoginFilter.php | 25 ++++ module/Auth/src/Auth/Model/Auth.php | 123 ------------------ module/Auth/src/Auth/Service/AuthAdapter.php | 7 +- 4 files changed, 31 insertions(+), 128 deletions(-) create mode 100644 module/Auth/src/Auth/Form/Filter/LoginFilter.php delete mode 100644 module/Auth/src/Auth/Model/Auth.php diff --git a/module/Auth/src/Auth/Controller/UserController.php b/module/Auth/src/Auth/Controller/UserController.php index 38ba7da0..6e4e82f8 100644 --- a/module/Auth/src/Auth/Controller/UserController.php +++ b/module/Auth/src/Auth/Controller/UserController.php @@ -6,6 +6,7 @@ use Auth\Form\AuthForm; use Auth\Form\ChangePasswordForm; use Auth\Form\Filter\ChangePasswordFilter; +use Auth\Form\Filter\LoginFilter; use Auth\Form\Filter\UserFilter; use Auth\Form\UserForm; use Auth\Model\Auth; @@ -105,8 +106,7 @@ public function loginAction() $request = $this->getRequest(); if ($request->isPost()) { - $authFormFilters = new Auth(); - $form->setInputFilter($authFormFilters->getInputFilter()); + $form->setInputFilter(new LoginFilter()); $form->setData($request->getPost()); if ($form->isValid()) { diff --git a/module/Auth/src/Auth/Form/Filter/LoginFilter.php b/module/Auth/src/Auth/Form/Filter/LoginFilter.php new file mode 100644 index 00000000..358ebfaa --- /dev/null +++ b/module/Auth/src/Auth/Form/Filter/LoginFilter.php @@ -0,0 +1,25 @@ +add([ + 'name' => 'email', + 'required' => true, + 'filters' => [], + 'validators' => [['name' => 'StringLength', 'options' => ['encoding' => 'UTF-8', 'min' => 1]]], + ]); + + $this->add([ + 'name' => 'password', + 'required' => true, + 'filters' => [], + 'validators' => [['name' => 'StringLength', 'options' => ['encoding' => 'UTF-8', 'min' => 1]]], + ]); + } +} diff --git a/module/Auth/src/Auth/Model/Auth.php b/module/Auth/src/Auth/Model/Auth.php deleted file mode 100644 index ab8b6cf3..00000000 --- a/module/Auth/src/Auth/Model/Auth.php +++ /dev/null @@ -1,123 +0,0 @@ -id = $data['id'] ?? null; - $this->email = $data['email'] ?? null; - $this->name = $data['name'] ?? null; - $this->password = $data['password'] ?? null; - $this->salt = $data['salt'] ?? null; - $this->status = $data['status'] ?? null; - $this->role = $data['role'] ?? null; - $this->registrationToken = $data['registrationToken'] ?? null; - } - - public function getArrayCopy(): array - { - return get_object_vars($this); - } - - /** - * @throws \Exception - */ - public function setInputFilter(InputFilterInterface $inputFilter) - { - throw new \Exception("Not used"); - } - - public function getInputFilter() - { - if (!$this->inputFilter) { - $inputFilter = new InputFilter(); - $factory = new InputFactory(); - - $inputFilter->add($factory->createInput([ - 'name' => 'email', - 'required' => true, - 'filters' => [ - ['name' => 'StripTags'], - ['name' => 'StringTrim'], - ], - 'validators' => [ - [ - 'name' => 'StringLength', - 'options' => ['encoding' => 'UTF-8', 'max' => 100, 'min' => 1], - ], - ], - ])); - - $inputFilter->add($factory->createInput([ - 'name' => 'password', - 'required' => true, - 'filters' => [ - ['name' => 'StripTags'], - ['name' => 'StringTrim'], - ], - 'validators' => [ - [ - 'name' => 'StringLength', - 'options' => ['encoding' => 'UTF-8', 'max' => 100, 'min' => 1], - ], - ], - ])); - - $this->inputFilter = $inputFilter; - } - - return $this->inputFilter; - } -} diff --git a/module/Auth/src/Auth/Service/AuthAdapter.php b/module/Auth/src/Auth/Service/AuthAdapter.php index 31d55948..b26a1e3e 100644 --- a/module/Auth/src/Auth/Service/AuthAdapter.php +++ b/module/Auth/src/Auth/Service/AuthAdapter.php @@ -1,5 +1,7 @@ Date: Mon, 24 May 2021 19:54:02 +0200 Subject: [PATCH 12/13] removed Auth/Service/UserData.php --- .../src/Application/ViewHelper/UserData.php | 12 ++-- module/Application/view/layout/layout.phtml | 8 +-- module/Auth/config/module.config.php | 6 +- module/Auth/src/Auth/Service/AuthManager.php | 27 +++----- module/Auth/src/Auth/Service/UserData.php | 63 ------------------- module/MoneyLog/config/module.config.php | 3 +- .../Controller/SettingsController.php | 14 +---- phpstan.neon.dist | 4 -- 8 files changed, 23 insertions(+), 114 deletions(-) delete mode 100644 module/Auth/src/Auth/Service/UserData.php diff --git a/module/Application/src/Application/ViewHelper/UserData.php b/module/Application/src/Application/ViewHelper/UserData.php index f9a79ef3..9c10f53b 100644 --- a/module/Application/src/Application/ViewHelper/UserData.php +++ b/module/Application/src/Application/ViewHelper/UserData.php @@ -7,25 +7,25 @@ class UserData extends AbstractHelper { /** - * @var ?\Auth\Service\UserData + * @var ?\stdClass */ - private $data; + private $identity; public function __invoke(): self { - if (!$this->data) { - $this->data = new \Auth\Service\UserData(); + if (!$this->identity) { + $this->identity = $this->view->identity(); } return $this; } public function getFullName(): ?string { - return $this->data ? $this->data->getName() . ' ' . $this->data->getSurname() : null; + return $this->identity ? $this->identity->name . ' ' . $this->identity->surname : null; } public function hasStored(): ?bool { - return $this->data ? (bool) $this->data->getSettings()['stored'] : null; + return $this->identity ? (bool) $this->identity->setting->hasProvisioning() : null; } } diff --git a/module/Application/view/layout/layout.phtml b/module/Application/view/layout/layout.phtml index f9ca0e45..4c37ddde 100644 --- a/module/Application/view/layout/layout.phtml +++ b/module/Application/view/layout/layout.phtml @@ -2,7 +2,9 @@ /** * @var \Laminas\View\Renderer\PhpRenderer $this * @var string $content + * @var stdClass $identity */ +$identity = $this->identity(); ?> @@ -88,16 +90,12 @@ MoneyLog
- identity(); - ?> identity()): ?>