Skip to content

Commit a24d18a

Browse files
authored
Merge pull request #421 from dotkernel/issue-415
Issue #415: Increased `PHPStan` level to `8`
2 parents 6e9b819 + 2001fca commit a24d18a

File tree

103 files changed

+1463
-217
lines changed

Some content is hidden

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

103 files changed

+1463
-217
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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:
77
- bin
88
- config

src/Admin/src/Command/AdminCreateCommand.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
use function implode;
2727
use function sprintf;
28+
use function trim;
2829

2930
use const PHP_EOL;
3031

@@ -75,6 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7576
$messages = [];
7677
foreach ($inputFilter->getMessages() as $field => $errors) {
7778
foreach ($errors as $error) {
79+
/** @var scalar $error */
7880
$messages[] = sprintf('%s: %s', $field, $error);
7981
}
8082
}
@@ -90,6 +92,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9092
}
9193

9294
/**
95+
* @return array{
96+
* identity: string,
97+
* password: string,
98+
* passwordConfirm: string,
99+
* firstName: string,
100+
* lastName: string,
101+
* status: 'active',
102+
* roles: array{uuid: non-empty-string}[],
103+
* }
93104
* @throws Exception
94105
*/
95106
private function getData(InputInterface $input): array
@@ -100,11 +111,11 @@ private function getData(InputInterface $input): array
100111
}
101112

102113
return [
103-
'identity' => $input->getOption('identity'),
104-
'password' => $input->getOption('password'),
105-
'passwordConfirm' => $input->getOption('password'),
106-
'firstName' => $input->getOption('firstName'),
107-
'lastName' => $input->getOption('lastName'),
114+
'identity' => trim($input->getOption('identity')),
115+
'password' => trim($input->getOption('password')),
116+
'passwordConfirm' => trim($input->getOption('password')),
117+
'firstName' => trim($input->getOption('firstName')),
118+
'lastName' => trim($input->getOption('lastName')),
108119
'status' => AdminStatusEnum::Active->value,
109120
'roles' => [
110121
['uuid' => $adminRole->getUuid()->toString()],

src/Admin/src/ConfigProvider.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,22 @@
2828
use Mezzio\Application;
2929
use Mezzio\Hal\Metadata\MetadataMap;
3030

31+
/**
32+
* @phpstan-import-type MetadataType from AppConfigProvider
33+
* @phpstan-type DependenciesType array{
34+
* delegators: array<class-string, class-string[]>,
35+
* factories: array<class-string, class-string>,
36+
* aliases: array<class-string, class-string>,
37+
* }
38+
*/
3139
class ConfigProvider
3240
{
41+
/**
42+
* @return array{
43+
* dependencies: DependenciesType,
44+
* "Mezzio\Hal\Metadata\MetadataMap": MetadataType[],
45+
* }
46+
*/
3347
public function __invoke(): array
3448
{
3549
return [
@@ -38,6 +52,9 @@ public function __invoke(): array
3852
];
3953
}
4054

55+
/**
56+
* @return DependenciesType
57+
*/
4158
private function getDependencies(): array
4259
{
4360
return [
@@ -74,6 +91,9 @@ private function getDependencies(): array
7491
];
7592
}
7693

94+
/**
95+
* @return MetadataType[]
96+
*/
7797
private function getHalConfig(): array
7898
{
7999
return [

src/Admin/src/Handler/Account/PatchAdminAccountResourceHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public function handle(ServerRequestInterface $request): ResponseInterface
4343
);
4444
}
4545

46+
/** @var non-empty-array<non-empty-string, mixed> $data */
47+
$data = (array) $this->inputFilter->getValues();
48+
4649
return $this->createResponse(
4750
$request,
48-
$this->adminService->saveAdmin(
49-
(array) $this->inputFilter->getValues(),
50-
$request->getAttribute(IdentityInterface::class)
51-
)
51+
$this->adminService->saveAdmin($data, $request->getAttribute(IdentityInterface::class))
5252
);
5353
}
5454
}

src/Admin/src/Handler/Admin/PatchAdminResourceHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public function handle(ServerRequestInterface $request): ResponseInterface
4545
);
4646
}
4747

48+
/** @var non-empty-array<non-empty-string, mixed> $data */
49+
$data = (array) $this->inputFilter->getValues();
50+
4851
return $this->createResponse(
4952
$request,
50-
$this->adminService->saveAdmin(
51-
(array) $this->inputFilter->getValues(),
52-
$request->getAttribute(Admin::class)
53-
)
53+
$this->adminService->saveAdmin($data, $request->getAttribute(Admin::class))
5454
);
5555
}
5656
}

src/Admin/src/Handler/Admin/PostAdminResourceHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public function handle(ServerRequestInterface $request): ResponseInterface
4242
);
4343
}
4444

45-
return $this->createdResponse(
46-
$request,
47-
$this->adminService->saveAdmin((array) $this->inputFilter->getValues())
48-
);
45+
/** @var non-empty-array<non-empty-string, mixed> $data */
46+
$data = (array) $this->inputFilter->getValues();
47+
48+
return $this->createdResponse($request, $this->adminService->saveAdmin($data));
4949
}
5050
}

src/Admin/src/Service/AdminRoleService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function findAdminRole(string $id): AdminRole
4343
}
4444

4545
/**
46-
* @param array<string, mixed> $params
46+
* @param array<non-empty-string, mixed> $params
4747
*/
4848
public function getAdminRoles(array $params): QueryBuilder
4949
{

src/Admin/src/Service/AdminRoleServiceInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function getAdminRoleRepository(): AdminRoleRepository;
1919
public function findAdminRole(string $id): AdminRole;
2020

2121
/**
22-
* @param array<string, mixed> $params
22+
* @param array<non-empty-string, mixed> $params
2323
*/
2424
public function getAdminRoles(array $params): QueryBuilder;
2525
}

src/Admin/src/Service/AdminService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function findAdmin(string $uuid): Admin
5858
}
5959

6060
/**
61-
* @param array<string, mixed> $params
61+
* @param array<non-empty-string, mixed> $params
6262
*/
6363
public function getAdmins(array $params): QueryBuilder
6464
{
@@ -82,6 +82,7 @@ public function getAdmins(array $params): QueryBuilder
8282
}
8383

8484
/**
85+
* @param non-empty-array<non-empty-string, mixed> $data
8586
* @throws BadRequestException
8687
* @throws ConflictException
8788
* @throws NotFoundException
@@ -118,7 +119,7 @@ public function saveAdmin(array $data, ?Admin $admin = null): Admin
118119
$admin->setStatus($status);
119120
}
120121

121-
$this->validateUniqueAdmin($admin->getIdentity(), $admin->getUuid());
122+
$this->validateUniqueAdmin((string) $admin->getIdentity(), $admin->getUuid());
122123

123124
if (array_key_exists('roles', $data) && count($data['roles']) > 0) {
124125
$admin->resetRoles();

0 commit comments

Comments
 (0)