Skip to content

Commit e89a5b6

Browse files
authored
Merge pull request #362 from dotkernel/issue-361
Issue #361: Increase `PHPStan` level to `8`
2 parents be86a69 + c5be927 commit e89a5b6

File tree

92 files changed

+924
-1042
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+924
-1042
lines changed

bin/composer-post-install-script.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
1111

12+
/**
13+
* @param array{source: string, destination: string, environment: array<string>} $file
14+
*/
1215
function copyFile(array $file): void
1316
{
1417
if (! in_array(getEnvironment(), $file['environment'])) {
@@ -33,8 +36,11 @@ function getEnvironment(): string
3336
return getenv('COMPOSER_DEV_MODE') === '1' ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION;
3437
}
3538

36-
// when adding files to the below array the `source` and `destination` paths must be relative to the project root folder
37-
// the `environment` key will indicate on what environments the file will be copied,
39+
/**
40+
* When adding files to the below array:
41+
* - `source` and `destination` paths must be relative to the project root folder
42+
* - `environment` key will indicate on what environments the file will be copied
43+
*/
3844
$files = [
3945
[
4046
'source' => 'config/autoload/local.php.dist',

phpstan.neon

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ includes:
22
- vendor/phpstan/phpstan-doctrine/extension.neon
33
- vendor/phpstan/phpstan-phpunit/extension.neon
44
parameters:
5-
level: 5
5+
level: 8
66
paths:
7+
- bin
8+
- config
9+
- public
710
- src
811
- test
912
treatPhpDocTypesAsCertain: false
10-
ignoreErrors:
11-
-
12-
message: '#Parameter \#1 \$expected of method PHPUnit\\Framework\\Assert::assertSame\(\) contains unresolvable type.#'
13-
path: test/Unit/App/Plugin/FormsPluginTest.php

src/Admin/src/Adapter/AuthenticationAdapter.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class AuthenticationAdapter implements AdapterInterface
3030
private string $identity;
3131
private string $credential;
3232

33+
/**
34+
* @param array<non-empty-string, mixed> $config
35+
*/
3336
#[Inject(
3437
EntityManagerInterface::class,
3538
'config.doctrine.authentication',
@@ -93,7 +96,7 @@ public function authenticate(): Result
9396
/** Check if the get credential method exists in the provided identity class */
9497
$getCredential = $this->validateMethod($identityClass, $this->config['orm_default']['credential_property']);
9598

96-
/** If passwords don't match, return failure response */
99+
/** If passwords don't match, return a failure response */
97100
if (false === password_verify($this->getCredential(), $identityClass->$getCredential())) {
98101
return new Result(
99102
Result::FAILURE_CREDENTIAL_INVALID,
@@ -105,7 +108,7 @@ public function authenticate(): Result
105108
/** Check for extra validation options */
106109
if (! empty($this->config['orm_default']['options'])) {
107110
foreach ($this->config['orm_default']['options'] as $property => $option) {
108-
/** Check if value for the current option is provided */
111+
/** Check if the value for the current option is provided */
109112
if (! array_key_exists('value', $option)) {
110113
throw new Exception(sprintf(
111114
self::OPTION_VALUE_NOT_PROVIDED,
@@ -114,7 +117,7 @@ public function authenticate(): Result
114117
));
115118
}
116119

117-
/** Check if message for the current option is provided */
120+
/** Check if a message for the current option is provided */
118121
if (! array_key_exists('message', $option)) {
119122
throw new Exception(sprintf(
120123
self::OPTION_VALUE_NOT_PROVIDED,
@@ -135,14 +138,20 @@ public function authenticate(): Result
135138
}
136139
}
137140

141+
/** @var non-empty-string[] $roles */
142+
$roles = array_map(
143+
fn (RoleInterface $role): string => (string) $role->getName()->value,
144+
$identityClass->getRoles()
145+
);
146+
138147
$adminIdentity = new AdminIdentity(
139148
$identityClass->getUuid()->toString(),
140-
$identityClass->getIdentity(),
149+
(string) $identityClass->getIdentity(),
141150
$identityClass->getStatus(),
142-
array_map(fn (RoleInterface $role): string => $role->getName()->value, $identityClass->getRoles()),
151+
$roles,
143152
[
144-
'firstName' => $identityClass->getFirstName(),
145-
'lastName' => $identityClass->getLastName(),
153+
'firstName' => (string) $identityClass->getFirstName(),
154+
'lastName' => (string) $identityClass->getLastName(),
146155
]
147156
);
148157

src/Admin/src/ConfigProvider.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,25 @@
3636
use Laminas\Form\ElementFactory;
3737
use Mezzio\Application;
3838

39+
/**
40+
* @phpstan-type ConfigType array{
41+
* dependencies: DependenciesType,
42+
* templates: TemplatesType,
43+
* }
44+
* @phpstan-type DependenciesType array{
45+
* delegators: non-empty-array<class-string, array<class-string>>,
46+
* factories: non-empty-array<class-string, class-string>,
47+
* aliases: non-empty-array<class-string, class-string>,
48+
* }
49+
* @phpstan-type TemplatesType array{
50+
* paths: non-empty-array<non-empty-string, non-empty-string[]>,
51+
* }
52+
*/
3953
class ConfigProvider
4054
{
55+
/**
56+
* @return ConfigType
57+
*/
4158
public function __invoke(): array
4259
{
4360
return [
@@ -46,6 +63,9 @@ public function __invoke(): array
4663
];
4764
}
4865

66+
/**
67+
* @return DependenciesType
68+
*/
4969
public function getDependencies(): array
5070
{
5171
return [
@@ -86,6 +106,9 @@ public function getDependencies(): array
86106
];
87107
}
88108

109+
/**
110+
* @return TemplatesType
111+
*/
89112
public function getTemplates(): array
90113
{
91114
return [

src/Admin/src/Form/AccountForm.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@
99
use Laminas\Form\Element\Csrf;
1010
use Laminas\Form\Element\Submit;
1111
use Laminas\Form\Element\Text;
12-
use Laminas\InputFilter\InputFilterInterface;
1312
use Laminas\Session\Container;
1413

14+
/**
15+
* @phpstan-import-type EditAccountDataType from EditAccountInputFilter
16+
* @extends AbstractForm<EditAccountDataType>
17+
*/
1518
class AccountForm extends AbstractForm
1619
{
20+
/**
21+
* @param array<non-empty-string, mixed> $options
22+
*/
1723
public function __construct(?string $name = null, array $options = [])
1824
{
1925
parent::__construct($name, $options);
@@ -58,9 +64,4 @@ public function init(): void
5864
->setAttribute('class', 'btn btn-primary btn-color btn-sm')
5965
);
6066
}
61-
62-
public function getInputFilter(): InputFilterInterface
63-
{
64-
return $this->inputFilter;
65-
}
6667
}

src/Admin/src/Form/ChangePasswordForm.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212
use Laminas\InputFilter\InputFilterInterface;
1313
use Laminas\Session\Container;
1414

15+
/**
16+
* @phpstan-import-type ChangePasswordDataType from ChangePasswordInputFilter
17+
* @extends AbstractForm<ChangePasswordDataType>
18+
*/
1519
class ChangePasswordForm extends AbstractForm
1620
{
21+
/**
22+
* @param array<non-empty-string, mixed> $options
23+
*/
1724
public function __construct(?string $name = null, array $options = [])
1825
{
1926
parent::__construct($name, $options);

src/Admin/src/Form/CreateAdminForm.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@
1313
use Laminas\Form\Element\Select;
1414
use Laminas\Form\Element\Submit;
1515
use Laminas\Form\Element\Text;
16-
use Laminas\InputFilter\InputFilterInterface;
1716
use Laminas\Session\Container;
1817

18+
/**
19+
* @phpstan-import-type CreateAdminDataType from CreateAdminInputFilter
20+
* @phpstan-import-type SelectDataType from AbstractForm
21+
* @extends AbstractForm<CreateAdminDataType>
22+
*/
1923
class CreateAdminForm extends AbstractForm
2024
{
25+
/**
26+
* @param array<non-empty-string, mixed> $options
27+
*/
2128
public function __construct(?string $name = null, array $options = [])
2229
{
2330
parent::__construct($name, $options);
@@ -32,6 +39,9 @@ public function __construct(?string $name = null, array $options = [])
3239
$this->inputFilter->init();
3340
}
3441

42+
/**
43+
* @phpstan-param SelectDataType[] $roles
44+
*/
3545
public function setRoles(array $roles): self
3646
{
3747
return $this->add(
@@ -86,9 +96,4 @@ public function init(): void
8696
->setAttribute('class', 'btn btn-sm btn-primary')
8797
);
8898
}
89-
90-
public function getInputFilter(): InputFilterInterface
91-
{
92-
return $this->inputFilter;
93-
}
9499
}

src/Admin/src/Form/DeleteAdminForm.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@
99
use Laminas\Form\Element\Checkbox;
1010
use Laminas\Form\Element\Csrf;
1111
use Laminas\Form\Element\Submit;
12-
use Laminas\InputFilter\InputFilterInterface;
1312
use Laminas\Session\Container;
1413

14+
/**
15+
* @phpstan-import-type DeleteAdminDataType from DeleteAdminInputFilter
16+
* @extends AbstractForm<DeleteAdminDataType>
17+
*/
1518
class DeleteAdminForm extends AbstractForm
1619
{
20+
/**
21+
* @param array<non-empty-string, mixed> $options
22+
*/
1723
public function __construct(?string $name = null, array $options = [])
1824
{
1925
parent::__construct($name, $options);
@@ -53,9 +59,4 @@ public function init(): void
5359
->setAttribute('class', 'btn btn-sm btn-danger')
5460
);
5561
}
56-
57-
public function getInputFilter(): InputFilterInterface
58-
{
59-
return $this->inputFilter;
60-
}
6162
}

src/Admin/src/Form/EditAdminForm.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
1313
use Laminas\Form\Element\Select;
1414
use Laminas\Form\Element\Submit;
1515
use Laminas\Form\Element\Text;
16-
use Laminas\InputFilter\InputFilterInterface;
1716
use Laminas\Session\Container;
1817

18+
/**
19+
* @phpstan-import-type EditAdminDataType from EditAdminInputFilter
20+
* @phpstan-import-type SelectDataType from AbstractForm
21+
* @extends AbstractForm<EditAdminDataType>
22+
*/
1923
class EditAdminForm extends AbstractForm
2024
{
21-
protected InputFilterInterface $inputFilter;
22-
25+
/**
26+
* @param array<non-empty-string, mixed> $options
27+
*/
2328
public function __construct(?string $name = null, array $options = [])
2429
{
2530
parent::__construct($name, $options);
@@ -34,6 +39,9 @@ public function __construct(?string $name = null, array $options = [])
3439
$this->inputFilter->init();
3540
}
3641

42+
/**
43+
* @phpstan-param SelectDataType[] $roles
44+
*/
3745
public function setRoles(array $roles): self
3846
{
3947
return $this->add(
@@ -81,9 +89,4 @@ public function init(): void
8189
->setAttribute('class', 'btn btn-sm btn-primary')
8290
);
8391
}
84-
85-
public function getInputFilter(): InputFilterInterface
86-
{
87-
return $this->inputFilter;
88-
}
8992
}

src/Admin/src/Form/LoginForm.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
use Laminas\Form\Element\Password;
1111
use Laminas\Form\Element\Submit;
1212
use Laminas\Form\Element\Text;
13-
use Laminas\InputFilter\InputFilterInterface;
1413
use Laminas\Session\Container;
1514

15+
/**
16+
* @phpstan-import-type LoginDataType from LoginInputFilter
17+
* @extends AbstractForm<LoginDataType>
18+
*/
1619
class LoginForm extends AbstractForm
1720
{
21+
/**
22+
* @param array<non-empty-string, mixed> $options
23+
*/
1824
public function __construct(?string $name = null, array $options = [])
1925
{
2026
parent::__construct($name, $options);
@@ -57,9 +63,4 @@ public function init(): void
5763
->setAttribute('class', 'btn btn-primary')
5864
);
5965
}
60-
61-
public function getInputFilter(): InputFilterInterface
62-
{
63-
return $this->inputFilter;
64-
}
6566
}

0 commit comments

Comments
 (0)