Skip to content

Commit 7234882

Browse files
committed
fix issues related to the latest core changes. phpstan level 4,5 fixes
1 parent ba48083 commit 7234882

29 files changed

+129
-62
lines changed

.semver

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
:major: 6
2+
:major: 8
33
:minor: 0
4-
:patch: 1
4+
:patch: 0
55
:special: ''

composer.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"require": {
3030
"php": ">=7.2",
3131
"ext-json": "*",
32-
"cakephp/cakephp": "4.x-dev as 4.0.0",
33-
"cakedc/users": "9.next-dev",
32+
"cakephp/cakephp": "^4.0.0",
33+
"cakedc/users": "^9.0.0",
3434
"firebase/php-jwt": "^5.0"
3535
},
3636
"require-dev": {
@@ -72,8 +72,10 @@
7272
"stan": "phpstan analyse src/",
7373
"psalm": "php vendor/psalm/phar/psalm.phar --show-info=false src/ ",
7474
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan-shim:^0.11.18 psalm/phar:^3.5 && mv composer.backup composer.json",
75+
"stan-rebuild-baseline": "phpstan analyse --configuration phpstan.neon --error-format baselineNeon src/ > phpstan-baseline.neon",
76+
"psalm-rebuild-baseline": "php vendor/psalm/phar/psalm.phar --show-info=false --set-baseline=psalm-baseline.xml src/",
7577
"rector": "rector process src/",
76-
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:^0.4.11 && mv composer.backup composer.json",
78+
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:^0.4.11 && mv composer.backup composer.json",
7779
"coverage-test": "phpunit --stderr --coverage-clover=clover.xml"
7880
}
7981
}

phpcs.xml.dist

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="CakePHP Core">
3+
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />
4+
5+
<rule ref="CakePHP" />
6+
</ruleset>

phpstan-baseline.neon

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
3+
parameters:
4+
ignoreErrors:
5+
-
6+
message: "#^Call to an undefined method Cake\\\\ORM\\\\Table\\:\\:getRegisterValidators\\(\\)\\.$#"
7+
count: 1
8+
path: src\Service\Action\Auth\RegisterAction.php
9+
10+
-
11+
message: "#^Call to an undefined method Cake\\\\ORM\\\\Table\\:\\:register\\(\\)\\.$#"
12+
count: 2
13+
path: src\Service\Action\Auth\RegisterAction.php
14+
15+
-
16+
message: "#^Call to an undefined method Cake\\\\ORM\\\\Table\\:\\:validate\\(\\)\\.$#"
17+
count: 1
18+
path: src\Service\Action\Auth\ResetPasswordAction.php
19+
20+
-
21+
message: "#^Call to an undefined method Cake\\\\ORM\\\\Table\\:\\:validationPasswordConfirm\\(\\)\\.$#"
22+
count: 1
23+
path: src\Service\Action\Auth\ResetPasswordAction.php
24+
25+
-
26+
message: "#^Call to an undefined method Cake\\\\ORM\\\\Table\\:\\:changePassword\\(\\)\\.$#"
27+
count: 1
28+
path: src\Service\Action\Auth\ResetPasswordAction.php
29+
30+
-
31+
message: "#^Call to an undefined method Cake\\\\ORM\\\\Table\\:\\:resetToken\\(\\)\\.$#"
32+
count: 1
33+
path: src\Service\Action\Auth\ResetPasswordRequestAction.php
34+
35+
-
36+
message: "#^Call to an undefined method Cake\\\\ORM\\\\Table\\:\\:socialLogin\\(\\)\\.$#"
37+
count: 1
38+
path: src\Service\Action\Auth\SocialLoginAction.php
39+
40+
-
41+
message: "#^Call to an undefined method Cake\\\\ORM\\\\Table\\:\\:validate\\(\\)\\.$#"
42+
count: 1
43+
path: src\Service\Action\Auth\ValidateAccountAction.php
44+
45+
-
46+
message: "#^Call to an undefined method Cake\\\\ORM\\\\Table\\:\\:resetToken\\(\\)\\.$#"
47+
count: 1
48+
path: src\Service\Action\Auth\ValidateAccountRequestAction.php
49+
50+

phpstan.neon

+5-21
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
14
parameters:
25
level: 4
36
autoload_files:
47
- tests/bootstrap.php
58
ignoreErrors:
6-
-
7-
message: '#Call to an undefined method Cake\\ORM\\Table.*#'
8-
path: 'src/Service/Action/Auth/RegisterAction.php'
9-
-
10-
message: '#Call to an undefined method Cake\\ORM\\Table.*#'
11-
path: 'src/Service/Action/Auth/ResetPasswordAction.php'
12-
-
13-
message: '#Call to an undefined method Cake\\ORM\\Table.*#'
14-
path: 'src/Service/Action/Auth/ResetPasswordRequestAction.php'
15-
-
16-
message: '#Call to an undefined method Cake\\ORM\\Table.*#'
17-
path: 'src/Service/Action/Auth/SocialLoginAction.php'
18-
-
19-
message: '#Call to an undefined method Cake\\ORM\\Table.*#'
20-
path: 'src/Service/Action/Auth/ValidateAccountAction.php'
21-
-
22-
message: '#Call to an undefined method Cake\\ORM\\Table.*#'
23-
path: 'src/Service/Action/Auth/ValidateAccountRequestAction.php'
24-
-
25-
message: '#PHPDoc tag @throws with type PHPUnit.*#'
26-
path: 'src/TestSuite/IntegrationTestCase.php'
9+
10+
services:

src/Service/Action/Auth/LoginAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function validates(): bool
6464
$validator
6565
->requirePresence($this->_passwordField, 'create')
6666
->notBlank($this->_passwordField);
67-
$errors = $validator->errors($this->getData());
67+
$errors = $validator->validate($this->getData());
6868
if (!empty($errors)) {
6969
throw new ValidationException(__('Validation failed'), 0, null, $errors);
7070
}

src/Service/Action/Auth/RegisterAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function validates(): bool
5353
{
5454
$validator = $this->getUsersTable()->getRegisterValidators($this->_registerOptions());
5555

56-
$errors = $validator->errors($this->getData());
56+
$errors = $validator->validate($this->getData());
5757
if (!empty($errors)) {
5858
throw new ValidationException(__('Validation failed'), 0, null, $errors);
5959
}

src/Service/Action/Auth/ResetPasswordAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function validates(): bool
5656
$validator
5757
->requirePresence('token', 'create')
5858
->notBlank('token');
59-
$errors = $validator->errors($this->getData());
59+
$errors = $validator->validate($this->getData());
6060
if (!empty($errors)) {
6161
throw new ValidationException(__('Validation failed'), 0, null, $errors);
6262
}

src/Service/Action/Auth/ResetPasswordRequestAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function validates(): bool
5555
$validator
5656
->requirePresence('reference', 'create')
5757
->notBlank('reference');
58-
$errors = $validator->errors($this->getData());
58+
$errors = $validator->validate($this->getData());
5959
if (!empty($errors)) {
6060
throw new ValidationException(__('Validation failed'), 0, null, $errors);
6161
}

src/Service/Action/Auth/SocialLoginAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function validates(): bool
5959
->requirePresence('data', 'create');
6060
$validator
6161
->requirePresence('options', 'create');
62-
$errors = $validator->errors($this->getData());
62+
$errors = $validator->validate($this->getData());
6363
if (!empty($errors)) {
6464
throw new ValidationException(__('Validation failed'), 0, null, $errors);
6565
}

src/Service/Action/Auth/ValidateAccountAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function validates(): bool
5555
$validator
5656
->requirePresence('token', 'create')
5757
->notBlank('token');
58-
$errors = $validator->errors($this->getData());
58+
$errors = $validator->validate($this->getData());
5959
if (!empty($errors)) {
6060
throw new ValidationException(__('Validation failed'), 0, null, $errors);
6161
}

src/Service/Action/Auth/ValidateAccountRequestAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function validates(): bool
5555
$validator
5656
->requirePresence('reference', 'create')
5757
->notBlank('reference');
58-
$errors = $validator->errors($this->getData());
58+
$errors = $validator->validate($this->getData());
5959
if (!empty($errors)) {
6060
throw new ValidationException(__('Validation failed'), 0, null, $errors);
6161
}

src/Service/Action/Collection/CollectionAction.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function _validateMany(): bool
3737
$this->_validateDataIsArray($data);
3838
$index = 0;
3939
$errors = collection($data)->reduce(function ($errors, $data) use ($validator, &$index) {
40-
$error = $validator->errors($data);
40+
$error = $validator->validate($data);
4141
if ($error) {
4242
$errors[$index] = $error;
4343
}
@@ -57,11 +57,11 @@ protected function _validateMany(): bool
5757
/**
5858
* Save many entities
5959
*
60-
* @param array $entities entities
61-
* @return array of entities saved
60+
* @param \Cake\Datasource\EntityInterface[] $entities entities
61+
* @return \Cake\Datasource\EntityInterface[]|\Cake\Datasource\ResultSetInterface|array of entities saved
6262
* @throws \Exception
6363
*/
64-
protected function _saveMany(array $entities = []): array
64+
protected function _saveMany(iterable $entities)
6565
{
6666
if ($this->getTable()->saveMany($entities)) {
6767
return $entities;
@@ -77,10 +77,10 @@ protected function _saveMany(array $entities = []): array
7777
/**
7878
* Create entities from the posted data
7979
*
80-
* @param array $patchOptions options to use un patch
81-
* @return array entities
80+
* @param array $patchOptions options to use in patch
81+
* @return \Cake\Datasource\EntityInterface[] entities
8282
*/
83-
protected function _newEntities(array $patchOptions = []): array
83+
protected function _newEntities(array $patchOptions = [])
8484
{
8585
$data = $this->getData();
8686
$this->_validateDataIsArray($data);

src/Service/Action/CrudAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ protected function _getEntityQuery($primaryKey)
295295
/**
296296
* Build condition for get entity method.
297297
*
298-
* @param string|int $primaryKey Primary key
298+
* @param mixed $primaryKey Primary key
299299
* @return array
300300
*/
301301
protected function _buildViewCondition($primaryKey): array

src/Service/Action/CrudAddAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CrudAddAction extends CrudAction
3030
public function validates(): bool
3131
{
3232
$validator = $this->getTable()->getValidator();
33-
$errors = $validator->errors($this->getData());
33+
$errors = $validator->validate($this->getData());
3434
if (!empty($errors)) {
3535
throw new ValidationException(__('Validation failed'), 0, null, $errors);
3636
}

src/Service/Action/CrudEditAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CrudEditAction extends CrudAction
3030
public function validates(): bool
3131
{
3232
$validator = $this->getTable()->getValidator();
33-
$errors = $validator->errors($this->getData(), false);
33+
$errors = $validator->validate($this->getData(), false);
3434
if (!empty($errors)) {
3535
throw new ValidationException(__('Validation failed'), 0, null, $errors);
3636
}

src/Service/Action/DescribeAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function validates(): bool
3636
$validator
3737
->requirePresence('service', 'create')
3838
->notBlank('service');
39-
$errors = $validator->errors($this->getData());
39+
$errors = $validator->validate($this->getData());
4040
if (!empty($errors)) {
4141
throw new ValidationException(__('Validation failed'), 0, null, $errors);
4242
}

src/Service/Action/Extension/CrudAutocompleteListExtension.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,16 @@ public function implementedEvents(): array
4141
/**
4242
* On find entities.
4343
*
44-
* @param \Cake\Event\Event $Event An Event instance.
44+
* @param \Cake\Event\Event $event An Event instance.
4545
* @return \Cake\ORM\Query
4646
*/
47-
public function findEntities(Event $Event): \Cake\ORM\Query
47+
public function findEntities(Event $event): \Cake\ORM\Query
4848
{
49-
return $this->_autocompleteList($Event->getSubject(), $Event->getData('query'));
49+
/** @var \CakeDC\Api\Service\Action\CrudAction $action */
50+
$action = $event->getSubject();
51+
/** @var \Cake\ORM\Query $query */
52+
$query = $event->getData('query');
53+
return $this->_autocompleteList($action, $query);
5054
}
5155

5256
/**

src/Service/Action/Extension/CrudHateoasExtension.php

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function implementedEvents(): array
6666
*/
6767
public function afterAction(Event $event): void
6868
{
69+
/** @var \CakeDC\Api\Service\Action\Action $action */
6970
$action = $event->getSubject();
7071
$result = $action->getService()->getResult();
7172
$actionName = $action->getName();

src/Service/Action/Extension/CrudRelationsExtension.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ public function implementedEvents(): array
5252
*/
5353
public function findEntity(Event $event): \Cake\ORM\Query
5454
{
55-
return $this->_attachAssociations($event->getSubject(), $event->getData('query'));
55+
/** @var \CakeDC\Api\Service\Action\CrudAction $action */
56+
$action = $event->getSubject();
57+
/** @var \Cake\ORM\Query $query */
58+
$query = $event->getData('query');
59+
return $this->_attachAssociations($action, $query);
5660
}
5761

5862
/**
@@ -63,7 +67,11 @@ public function findEntity(Event $event): \Cake\ORM\Query
6367
*/
6468
public function findEntities(Event $event): \Cake\ORM\Query
6569
{
66-
return $this->_attachAssociations($event->getSubject(), $event->getData('query'));
70+
/** @var \CakeDC\Api\Service\Action\CrudAction $action */
71+
$action = $event->getSubject();
72+
/** @var \Cake\ORM\Query $query */
73+
$query = $event->getData('query');
74+
return $this->_attachAssociations($action, $query);
6775
}
6876

6977
/**

src/Service/Action/Extension/CursorPaginateExtension.php

+3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public function implementedEvents(): array
7676
*/
7777
public function findEntities(Event $event): \Cake\ORM\Query
7878
{
79+
/** @var \CakeDC\Api\Service\Action\Action $action */
7980
$action = $event->getSubject();
81+
/** @var \Cake\ORM\Query $query */
8082
$query = $event->getData('query');
8183
if ($event->getResult()) {
8284
$query = $event->getResult();
@@ -160,6 +162,7 @@ protected function _count(Action $action): ?int
160162
*/
161163
public function afterFind(EventInterface $event): ?Entity
162164
{
165+
/** @var \CakeDC\Api\Service\Action\Action $action */
163166
$action = $event->getSubject();
164167
$records = $event->getData('records');
165168
$result = $action->getService()->getResult();

src/Service/Action/Extension/NestedExtension.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public function implementedEvents(): array
4646
*/
4747
public function findEntities(Event $event): \Cake\ORM\Query
4848
{
49+
/** @var \CakeDC\Api\Service\Action\CrudAction $action */
4950
$action = $event->getSubject();
51+
/** @var \Cake\ORM\Query $query */
5052
$query = $event->getData('query');
5153
$foreignKey = $action->getParentId();
5254
$field = $action->getParentIdName();
@@ -68,7 +70,9 @@ public function findEntities(Event $event): \Cake\ORM\Query
6870
*/
6971
public function findEntity(Event $event): \Cake\ORM\Query
7072
{
73+
/** @var \CakeDC\Api\Service\Action\CrudAction $action */
7174
$action = $event->getSubject();
75+
/** @var \Cake\ORM\Query $query */
7276
$query = $event->getData('query');
7377
$foreignKey = $action->getParentId();
7478
$field = $action->getParentIdName();
@@ -90,8 +94,10 @@ public function findEntity(Event $event): \Cake\ORM\Query
9094
*/
9195
public function patchEntity(Event $event): \Cake\ORM\Entity
9296
{
97+
/** @var \CakeDC\Api\Service\Action\CrudAction $action */
9398
$action = $event->getSubject();
94-
$entity = $event->getData('entity');
99+
/** @var \Cake\ORM\Query $query */
100+
$query = $event->getData('query');
95101
if ($event->getResult()) {
96102
$entity = $event->getResult();
97103
}

src/Service/Auth/Authorize/SimpleRbacAuthorize.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ protected function _matchRule(array $permission, $user, string $role, ServerRequ
223223
*
224224
* @param array $permission permission configuration
225225
* @param string $key key to retrieve and check in permissions configuration
226-
* @param string $value value to check with (coming from the request) We'll check the DASHERIZED value too
226+
* @param string|null $value value to check with (coming from the request) We'll check the DASHERIZED value too
227227
* @param bool $allowEmpty true if we allow
228228
* @return bool
229229
*/

src/Service/Renderer/FlysystemRenderer.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use League\Flysystem\File;
2323
use League\Flysystem\FileNotFoundException;
2424
use League\Flysystem\Filesystem;
25+
use League\Flysystem\Handler;
2526
use Zend\Diactoros\Stream;
2627

2728
/**
@@ -65,9 +66,9 @@ public function response(?Result $result = null): bool
6566
*
6667
* @param \League\Flysystem\Filesystem $filesystem custom filesystem
6768
* @param string $path of file at filesystem
68-
* @return \League\Flysystem\File
69+
* @return \League\Flysystem\Handler
6970
*/
70-
protected function getFile(Filesystem $filesystem, string $path): File
71+
protected function getFile(Filesystem $filesystem, string $path): Handler
7172
{
7273
return $filesystem->get($path);
7374
}

src/Service/Service.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ public function dispatchProcessAction($request): Result
568568
/**
569569
* Dispatch service call through callbacks and action.
570570
*
571-
* @return \CakeDC\Api\Service\Action\Result
571+
* @return \CakeDC\Api\Service\Action\Result|null
572572
573573
*/
574574
protected function _dispatch()

0 commit comments

Comments
 (0)