Skip to content

Commit a5f76b5

Browse files
committed
Fix phpstan errors
1 parent df37bbc commit a5f76b5

File tree

8 files changed

+7
-39
lines changed

8 files changed

+7
-39
lines changed

composer.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,8 @@
6565
"scripts": {
6666
"cs-check": "phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
6767
"cs-fix": "phpcbf --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
68-
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:~1.8.0 psalm/phar:~4.26.0 && mv composer.backup composer.json",
68+
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:~2.1.17 && mv composer.backup composer.json",
6969
"phpstan": "phpstan analyse --memory-limit=3G src/",
70-
"psalm": "psalm.phar --show-info=false",
71-
"stan": [
72-
"@phpstan",
73-
"@psalm"
74-
],
7570
"test": "phpunit"
7671
},
7772
"config": {

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,3 @@ parameters:
99
message: "#^Access to an undefined property Cake\\\\Controller\\\\Controller\\:\\:\\$Crud\\.$#"
1010
count: 1
1111
path: src/Listener/PaginationListener.php
12-
13-
-
14-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\EntityInterface\\:\\:visibleProperties\\(\\)\\.$#"
15-
count: 1
16-
path: src/Schema/JsonApi/DynamicEntitySchema.php

phpstan.neon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ parameters:
55
level: 6
66
paths:
77
- src
8-
checkMissingIterableValueType: false
9-
checkGenericClassInNonGenericObjectType: false
108
universalObjectCratesClasses:
119
- Crud\Event\Subject
1210
bootstrapFiles:
1311
- vendor/cakephp/cakephp/src/Core/Exception/CakeException.php
12+
ignoreErrors:
13+
- identifier: missingType.iterableValue
14+
- identifier: missingType.generics

src/Action/RelationshipsAction.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ protected function _patch(): void
365365

366366
if (in_array($association->type(), [Association::MANY_TO_ONE, Association::ONE_TO_ONE], true)) {
367367
//Set the relationship to the corresponding entity
368-
/** @psalm-suppress TypeDoesNotContainNull */
369368
if (array_key_exists('id', $data)) {
370369
$entity->{$property} = $foreignTable->get($data['id']);
371370
} elseif ($data === null) {

src/Listener/JsonApiListener.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,14 +1019,7 @@ protected function _deduplicateResultSet(Subject $subject): ResultSetInterface
10191019
}
10201020
}
10211021

1022-
if ($subject->entities instanceof ResultSet) {
1023-
$resultSet = clone $subject->entities;
1024-
$resultSet->unserialize(serialize($entities));
1025-
} else {
1026-
$resultSet = new ResultSetDecorator($entities);
1027-
}
1028-
1029-
return $resultSet;
1022+
return new ResultSet($entities);
10301023
}
10311024

10321025
/**
@@ -1059,7 +1052,6 @@ protected function _getFindResult(Subject $subject): EntityInterface|ResultSetIn
10591052
protected function _getSingleEntity(Subject $subject): ?EntityInterface
10601053
{
10611054
if (!empty($subject->entities) && $subject->entities instanceof SelectQuery) {
1062-
/** @psalm-suppress InvalidReturnStatement */
10631055
return (clone $subject->entities)->first();
10641056
}
10651057

@@ -1267,7 +1259,6 @@ protected function _checkRequestData(): void
12671259
$validator->validateCreateDocument();
12681260
}
12691261

1270-
/** @psalm-suppress TypeDoesNotContainType */
12711262
if ($requestMethod === 'PATCH' || $requestMethod === 'DELETE') {
12721263
$validator->validateUpdateDocument();
12731264
}
@@ -1303,9 +1294,6 @@ protected function _checkRequestData(): void
13031294
protected function _getAssociationsList(?Table $table, array $associationTypes = []): array
13041295
{
13051296
$table = $table ?: $this->_controller()->fetchTable();
1306-
if (!$table instanceof Table) {
1307-
return [];
1308-
}
13091297

13101298
$associations = $table->associations();
13111299

src/Listener/PaginationListener.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ protected function _getJsonApiPaginationResponse(array $pagination): array
9595
$query['sort'] = $request->getQuery('sort');
9696
}
9797

98-
/** @psalm-suppress UndefinedMagicPropertyFetch */
9998
$fullBase = (bool)$this->_controller()->Crud->getConfig('listeners.jsonApi.absoluteLinks');
10099

101100
$baseUrl = $request->getAttributes()['params'];

src/Listener/SearchListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function injectSearch(EventInterface $event): void
5050
}
5151

5252
$repository = $this->_controller()->fetchTable();
53-
if ($repository instanceof Table && !$repository->behaviors()->has('Search')) {
53+
if (!$repository->behaviors()->has('Search')) {
5454
throw new RuntimeException(
5555
sprintf(
5656
'Missing Search.Search behavior on %s',

src/Schema/JsonApi/DynamicEntitySchema.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public function getType(): string
8888
*
8989
* @param \Cake\ORM\Entity $resource Entity
9090
* @return string
91-
* @psalm-suppress MoreSpecificImplementedParamType
9291
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
9392
*/
9493
public function getId($resource): ?string
@@ -129,10 +128,7 @@ protected function getRepository(?EntityInterface $entity = null): Table
129128
protected function entityToShallowArray(EntityInterface $entity): array
130129
{
131130
$result = [];
132-
/** @psalm-suppress UndefinedInterfaceMethod */
133-
$properties = method_exists($entity, 'getVisible')
134-
? $entity->getVisible()
135-
: $entity->visibleProperties();
131+
$properties = $entity->getVisible();
136132
foreach ($properties as $property) {
137133
if ($property[0] === '_') {
138134
continue;
@@ -161,7 +157,6 @@ protected function entityToShallowArray(EntityInterface $entity): array
161157
* @param \Cake\Datasource\EntityInterface $resource Entity
162158
* @param \Neomerx\JsonApi\Contracts\Schema\ContextInterface $context The Context
163159
* @return array
164-
* @psalm-suppress MoreSpecificImplementedParamType
165160
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
166161
*/
167162
public function getAttributes($resource, ContextInterface $context): iterable
@@ -206,7 +201,6 @@ public function getAttributes($resource, ContextInterface $context): iterable
206201
* @param \Cake\Datasource\EntityInterface $resource Entity object
207202
* @param \Neomerx\JsonApi\Contracts\Schema\ContextInterface $context The Context
208203
* @return array
209-
* @psalm-suppress MoreSpecificImplementedParamType
210204
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
211205
*/
212206
public function getRelationships($resource, ContextInterface $context): iterable
@@ -284,7 +278,6 @@ public function getRelationships($resource, ContextInterface $context): iterable
284278
*
285279
* @param \Cake\ORM\Entity|null $resource Entity, null only to be compatible with the Neomerx method
286280
* @return string
287-
* @psalm-suppress MoreSpecificImplementedParamType
288281
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
289282
*/
290283
public function getSelfSubUrl($resource = null): string
@@ -329,7 +322,6 @@ protected function getAssociationByProperty(string $name): ?Association
329322
* @param \Cake\Datasource\EntityInterface $resource Entity
330323
* @param string $name Relationship name in lowercase singular or plural
331324
* @return \Neomerx\JsonApi\Contracts\Schema\LinkInterface
332-
* @psalm-suppress MoreSpecificImplementedParamType
333325
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
334326
*/
335327
public function getRelationshipSelfLink($resource, string $name): LinkInterface
@@ -370,7 +362,6 @@ public function getRelationshipSelfLink($resource, string $name): LinkInterface
370362
* @param \Cake\Datasource\EntityInterface $resource Entity
371363
* @param string $name Relationship name in lowercase singular or plural
372364
* @return \Neomerx\JsonApi\Contracts\Schema\LinkInterface
373-
* @psalm-suppress MoreSpecificImplementedParamType
374365
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
375366
*/
376367
public function getRelationshipRelatedLink($resource, string $name): LinkInterface

0 commit comments

Comments
 (0)