Skip to content

Commit 6b785a0

Browse files
committed
Upgrade PHPStan to 0.10 and fix new violations
1 parent e6b18f3 commit 6b785a0

32 files changed

+104
-190
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ jobs:
110110
- *update-project-dependencies
111111
- run:
112112
name: Install PHPStan
113-
command: composer global require phpstan/phpstan:^0.8
113+
command: composer global require phpstan/phpstan:^0.10
114114
- *save-composer-cache-by-revision
115115
- *save-composer-cache-by-branch
116116
- run:

phpstan.neon

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,35 @@ parameters:
33
- tests/Fixtures/app/AppKernel.php
44
excludes_analyse:
55
- tests/Fixtures/app/cache
6+
# The Symfony Configuration API isn't good enough to be analysed
7+
- src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php
68
ignoreErrors:
7-
- '#Call to an undefined method Symfony\\Component\\Routing\\Exception\\ExceptionInterface::getCode\(\)#'
8-
- '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy::[a-zA-Z0-9_]+\(\)#'
9-
- '#Access to an undefined property Prophecy\\Prophecy\\ObjectProphecy::\$[a-zA-Z0-9_]+#'
10-
- '#Call to an undefined method PHPUnit\\Framework\\MockObject\\MockObject::[a-zA-Z0-9_]+\(\)#'
11-
- '#Call to an undefined method Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata::getAssociationMappings\(\)#'
9+
# Real problems, hard to fix
10+
- '#Parameter \#2 \$dqlPart of method Doctrine\\ORM\\QueryBuilder::add\(\) expects array\|object, string given\.#'
1211

1312
# False positives
13+
- '#Access to an undefined property Prophecy\\Prophecy\\ObjectProphecy::\$[a-zA-Z0-9_]+#'
14+
- '#Access to an undefined property object::\$isIdentifierComposite.#'
1415
- '#Call to an undefined method Doctrine\\Common\\Persistence\\ObjectManager::getConnection\(\)#'
15-
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Extension\\QueryResult(Item|Collection)ExtensionInterface::supportsResult\(\) invoked with 3 parameters, 1-2 required\.#'
16+
- '#Call to an undefined method PHPUnit\\Framework\\MockObject\\MockObject::[a-zA-Z0-9_]+\(\)#'
17+
- '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy::[a-zA-Z0-9_]+\(\)#'
18+
- '#Method ApiPlatform\\Core\\Tests\\Bridge\\Doctrine\\Orm\\ItemDataProviderTest::getManagerRegistry\(\) should return Doctrine\\Common\\Persistence\\ManagerRegistry but returns object\.#'
19+
- '#Method ApiPlatform\\Core\\Tests\\Bridge\\Doctrine\\Util\\IdentifierManagerTraitTest::getObjectManager\(\) should return Doctrine\\Common\\Persistence\\ObjectManager but returns object\.#'
20+
# Temporary fix while the PHPStan extension for Prophecy isn't compatible with 0.10
21+
- '#Parameter .* expects .*, .*object.* given\.#'
22+
- '#Parameter \#[0-9] \$filterLocator of class ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Extension\\FilterExtension constructor expects ApiPlatform\\Core\\Api\\FilterCollection|Psr\\Container\\ContainerInterface(\|null)?, ArrayObject given\.#'
23+
- '#Property ApiPlatform\\Core\\Test\\DoctrineOrmFilterTestCase::\$managerRegistry \(Doctrine\\Common\\Persistence\\ManagerRegistry\) does not accept object\.#'
24+
- '#Property ApiPlatform\\Core\\Test\\DoctrineOrmFilterTestCase::\$repository \(Doctrine\\ORM\\EntityRepository\) does not accept Doctrine\\Common\\Persistence\\ObjectRepository\.#'
25+
# https://github.com/doctrine/doctrine2/pull/7298/files
26+
- '#Strict comparison using === between null and int will always evaluate to false\.#'
27+
- '#Strict comparison using !== between null and null will always evaluate to false\.#'
28+
29+
# Expected, due to deprecations
1630
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Extension\\QueryResult(Item|Collection)ExtensionInterface::getResult\(\) invoked with 4 parameters, 1 required\.#'
31+
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Extension\\QueryResult(Item|Collection)ExtensionInterface::supportsResult\(\) invoked with 3 parameters, 1-2 required\.#'
32+
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\AbstractFilter::apply\(\) invoked with 5 parameters, 3-4 required\.#'
1733
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\AbstractFilter::filterProperty\(\) invoked with 7 parameters, 5-6 required\.#'
34+
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\FilterInterface::apply\(\) invoked with 5 parameters, 3-4 required\.#'
1835
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\OrderFilter::filterProperty\(\) invoked with 7 parameters, 5-6 required\.#'
36+
- '#Method ApiPlatform\\Core\\DataProvider\\CollectionDataProviderInterface::getCollection\(\) invoked with 3 parameters, 1-2 required.#'
37+
- '#PHPDoc tag @param references unknown parameter \$operationName#'

src/Annotation/ApiFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ final class ApiFilter
5353

5454
public function __construct($options = [])
5555
{
56-
if (!isset($options['value'])) {
56+
if (!\is_string($options['value'] ?? null)) {
5757
throw new InvalidArgumentException('This annotation needs a value representing the filter class.');
5858
}
5959

60-
if (!is_subclass_of($options['value'], FilterInterface::class)) {
60+
if (!is_a($options['value'], FilterInterface::class, true)) {
6161
throw new InvalidArgumentException(sprintf('The filter class "%s" does not implement "%s".', $options['value'], FilterInterface::class));
6262
}
6363

src/Api/ResourceClassResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getResourceClass($value, string $resourceClass = null, bool $str
5151
$typeToFind = $type = $resourceClass;
5252
}
5353

54-
if (($strict && isset($type) && $resourceClass !== $type) || false === $isResourceClass = $this->isResourceClass($typeToFind)) {
54+
if (($strict && $resourceClass !== $type) || false === $isResourceClass = $this->isResourceClass($typeToFind)) {
5555
if (is_subclass_of($type, $resourceClass) && $this->isResourceClass($resourceClass)) {
5656
return $type;
5757
}

src/Bridge/Doctrine/Orm/Extension/FilterExtension.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,11 @@ public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGenerator
6161
}
6262

6363
foreach ($resourceFilters as $filterId) {
64-
if (!($filter = $this->getFilter($filterId)) instanceof FilterInterface) {
65-
continue;
64+
$filter = $this->getFilter($filterId);
65+
if ($filter instanceof FilterInterface) {
66+
$context['filters'] = $context['filters'] ?? [];
67+
$filter->apply($queryBuilder, $queryNameGenerator, $resourceClass, $operationName, $context);
6668
}
67-
68-
$context['filters'] = $context['filters'] ?? [];
69-
70-
$filter->apply($queryBuilder, $queryNameGenerator, $resourceClass, $operationName, $context);
7169
}
7270
}
7371
}

src/Bridge/Doctrine/Orm/Extension/OrderExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGenerator
6060
$order = 'ASC';
6161
}
6262

63-
if (false === ($pos = \strpos($field, '.'))
64-
|| isset($classMetaData->embeddedClasses[\substr($field, 0, $pos)])) {
63+
$pos = strpos($field, '.');
64+
if (false === $pos || isset($classMetaData->embeddedClasses[\substr($field, 0, $pos)])) {
6565
// Configure default filter with property
6666
$field = "{$rootAlias}.{$field}";
6767
} else {

src/Bridge/Doctrine/Orm/Filter/AbstractFilter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ protected function isPropertyNested(string $property/*, string $resourceClass*/)
164164
$resourceClass = null;
165165
}
166166

167-
if (false === $pos = strpos($property, '.')) {
167+
$pos = strpos($property, '.');
168+
if (false === $pos) {
168169
return false;
169170
}
170171

src/Bridge/Doctrine/Orm/Util/IdentifierManagerTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private function normalizeIdentifiers($id, ObjectManager $manager, string $resou
4949
$identifiersMap = [];
5050

5151
// first transform identifiers to a proper key/value array
52-
foreach (explode(';', $id) as $identifier) {
52+
foreach (explode(';', (string) $id) as $identifier) {
5353
if (!$identifier) {
5454
continue;
5555
}

src/Bridge/Doctrine/Orm/Util/QueryChecker.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ public static function hasOrderByOnToManyJoin(QueryBuilder $queryBuilder, Manage
127127
$parts = QueryJoinParser::getOrderByParts($orderBy);
128128

129129
foreach ($parts as $part) {
130-
if (false !== ($pos = strpos($part, '.'))) {
131-
$alias = substr($part, 0, $pos);
132-
133-
$orderByAliases[$alias] = true;
130+
$pos = strpos($part, '.');
131+
if (false !== $pos) {
132+
$orderByAliases[substr($part, 0, $pos)] = true;
134133
}
135134
}
136135
}

src/Bridge/Symfony/Bundle/DependencyInjection/Compiler/AnnotationFilterPass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ final class AnnotationFilterPass implements CompilerPassInterface
3939
public function process(ContainerBuilder $container)
4040
{
4141
$resourceClassDirectories = $container->getParameter('api_platform.resource_class_directories');
42+
/**
43+
* @var Reader
44+
*/
4245
$reader = $container->get('annotation_reader');
4346

4447
foreach (ReflectionClassRecursiveIterator::getReflectionClassesFromDirectories($resourceClassDirectories) as $className => $reflectionClass) {

0 commit comments

Comments
 (0)