diff --git a/Controller/ManageController.php b/Controller/ManageController.php index a70a629..73644ac 100644 --- a/Controller/ManageController.php +++ b/Controller/ManageController.php @@ -74,7 +74,7 @@ public function create(Request $request): Response { $type = $request->query->get('type'); - if (!\in_array($type, [SharedProjectTimesheet::TYPE_CUSTOMER, SharedProjectTimesheet::TYPE_PROJECT])) { + if (!\in_array($type, [SharedProjectTimesheet::TYPE_CUSTOMER, SharedProjectTimesheet::TYPE_PROJECT], true)) { throw new InvalidArgumentException('Invalid value for type'); } @@ -134,7 +134,7 @@ public function update(SharedProjectTimesheet $sharedProject, string $shareKey, $this->flashUpdateException($e); } } elseif (!$form->isSubmitted()) { - if (!empty($sharedProject->getPassword())) { + if ($sharedProject->hasPassword()) { $form->get('password')->setData(ManageService::PASSWORD_DO_NOT_CHANGE_VALUE); } } diff --git a/Entity/SharedProjectTimesheet.php b/Entity/SharedProjectTimesheet.php index 9bf904e..667e8f3 100644 --- a/Entity/SharedProjectTimesheet.php +++ b/Entity/SharedProjectTimesheet.php @@ -111,6 +111,11 @@ public function getPassword(): ?string return $this->password; } + public function hasPassword(): bool + { + return $this->password !== null && $this->password !== ''; + } + public function setPassword(?string $password): void { $this->password = $password; @@ -123,7 +128,7 @@ public function isEntryUserVisible(): bool public function setEntryUserVisible(bool $entryUserVisible): void { - $this->entryUserVisible = (bool) $entryUserVisible; + $this->entryUserVisible = $entryUserVisible; } public function isEntryRateVisible(): bool @@ -133,7 +138,7 @@ public function isEntryRateVisible(): bool public function setEntryRateVisible(bool $entryRateVisible): void { - $this->entryRateVisible = (bool) $entryRateVisible; + $this->entryRateVisible = $entryRateVisible; } public function hasRecordMerging(): bool diff --git a/Form/SharedProjectFormType.php b/Form/SharedProjectFormType.php index 3919d29..f69c461 100644 --- a/Form/SharedProjectFormType.php +++ b/Form/SharedProjectFormType.php @@ -118,7 +118,8 @@ public function configureOptions(OptionsResolver $resolver): void public function finishView(FormView $view, FormInterface $form, array $options): void { - if (!empty($form->get('password')->getData())) { + $data = $form->get('password')->getData(); + if (is_string($data) && trim($data) !== '') { $view['password']->vars['value'] = ManageService::PASSWORD_DO_NOT_CHANGE_VALUE; } } diff --git a/Model/TimeRecord.php b/Model/TimeRecord.php index 05b18ff..3c2aed4 100644 --- a/Model/TimeRecord.php +++ b/Model/TimeRecord.php @@ -44,7 +44,7 @@ private function __construct( public static function fromTimesheet(Timesheet $timesheet, string $mergeMode = RecordMergeMode::MODE_MERGE): TimeRecord { - if (!\in_array($mergeMode, self::VALID_MERGE_MODES)) { + if (!\in_array($mergeMode, self::VALID_MERGE_MODES, true)) { throw new \InvalidArgumentException("Invalid merge mode given: $mergeMode"); } diff --git a/Repository/SharedProjectTimesheetRepository.php b/Repository/SharedProjectTimesheetRepository.php index bff9059..da5f33a 100644 --- a/Repository/SharedProjectTimesheetRepository.php +++ b/Repository/SharedProjectTimesheetRepository.php @@ -73,7 +73,7 @@ public function getProjects(SharedProjectTimesheet $sharedProject): array } /** @var ProjectRepository $projectRepository */ - $projectRepository = $this->_em->getRepository(Project::class); + $projectRepository = $this->_em->getRepository(Project::class); // @phpstan-ignore-line $query = new ProjectQuery(); $query->setCustomers([$sharedProject->getCustomer()]); diff --git a/Service/ManageService.php b/Service/ManageService.php index 0e85641..a1a6b24 100644 --- a/Service/ManageService.php +++ b/Service/ManageService.php @@ -51,10 +51,10 @@ public function update(SharedProjectTimesheet $sharedProjectTimesheet, ?string $ } // Handle password - $currentHashedPassword = !empty($sharedProjectTimesheet->getPassword()) ? $sharedProjectTimesheet->getPassword() : null; + $currentHashedPassword = $sharedProjectTimesheet->hasPassword() ? $sharedProjectTimesheet->getPassword() : null; if ($newPassword !== self::PASSWORD_DO_NOT_CHANGE_VALUE) { - if (!empty($newPassword)) { + if (is_string($newPassword) && $newPassword !== '') { $encodedPassword = $this->passwordHasherFactory->getPasswordHasher('customer_portal')->hash($newPassword); $sharedProjectTimesheet->setPassword($encodedPassword); } else { diff --git a/Service/ViewService.php b/Service/ViewService.php index 3ba39aa..dd830f6 100644 --- a/Service/ViewService.php +++ b/Service/ViewService.php @@ -50,7 +50,7 @@ public function hasAccess(SharedProjectTimesheet $sharedProject, ?string $givenP if (!$this->request->getSession()->has($sessionPasswordKey)) { // Check given password - if (empty($givenPassword) || !$this->passwordHasherFactory->getPasswordHasher('customer_portal')->verify($hashedPassword, $givenPassword)) { + if ($givenPassword === null || $givenPassword === '' || !$this->passwordHasherFactory->getPasswordHasher('customer_portal')->verify($hashedPassword, $givenPassword)) { return false; } diff --git a/phpstan.neon b/phpstan.neon index 402a049..f91aff3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,9 +1,10 @@ includes: - - %rootDir%/../phpstan-symfony/extension.neon - - %rootDir%/../phpstan-symfony/rules.neon - - %rootDir%/../phpstan-doctrine/extension.neon - - %rootDir%/../phpstan-doctrine/rules.neon - - %rootDir%/../phpstan/conf/bleedingEdge.neon + - %rootDir%/../phpstan-symfony/extension.neon + - %rootDir%/../phpstan-symfony/rules.neon + - %rootDir%/../phpstan-doctrine/extension.neon + - %rootDir%/../phpstan-doctrine/rules.neon + - %rootDir%/../phpstan-strict-rules/rules.neon + - %rootDir%/../phpstan/conf/bleedingEdge.neon parameters: level: 7