Skip to content

Commit

Permalink
phpstan strict rules
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst committed Sep 17, 2024
1 parent a12b0e6 commit 335484e
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Controller/ManageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -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);
}
}
Expand Down
9 changes: 7 additions & 2 deletions Entity/SharedProjectTimesheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Form/SharedProjectFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Model/TimeRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
2 changes: 1 addition & 1 deletion Repository/SharedProjectTimesheetRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
Expand Down
4 changes: 2 additions & 2 deletions Service/ManageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Service/ViewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 6 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 335484e

Please sign in to comment.