Skip to content

Commit f5c81c9

Browse files
committed
Upgrade phpstan to v0.12
1 parent 083ad62 commit f5c81c9

File tree

11 files changed

+89
-97
lines changed

11 files changed

+89
-97
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@
4444
"elasticsearch/elasticsearch": "^6.0",
4545
"friendsofsymfony/user-bundle": "^2.2@dev",
4646
"guzzlehttp/guzzle": "^6.0",
47-
"jangregor/phpstan-prophecy": "^0.4.2",
47+
"jangregor/phpstan-prophecy": "^0.6",
4848
"justinrainbow/json-schema": "^5.2.1",
4949
"nelmio/api-doc-bundle": "^2.13.4",
5050
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0",
5151
"phpdocumentor/type-resolver": "^0.3 || ^0.4",
5252
"phpspec/prophecy": "^1.8",
5353
"phpstan/extension-installer": "^1.0",
54-
"phpstan/phpstan-doctrine": "^0.11.5",
55-
"phpstan/phpstan-phpunit": "^0.11.2",
56-
"phpstan/phpstan-shim": "^0.11.10",
57-
"phpstan/phpstan-symfony": "^0.11.6",
54+
"phpstan/phpstan": "^0.12.4",
55+
"phpstan/phpstan-doctrine": "^0.12.7",
56+
"phpstan/phpstan-phpunit": "^0.12.4",
57+
"phpstan/phpstan-symfony": "^0.12.4",
5858
"phpunit/phpunit": "^7.5.2 || ^8.0",
5959
"psr/log": "^1.0",
6060
"ramsey/uuid": "^3.7",

phpstan.neon.dist

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,110 @@
11
parameters:
2-
level: 6
2+
level: 5
33
paths:
44
- src
55
- tests
66
- tests/Fixtures/app/console
77
inferPrivatePropertyTypeFromConstructor: true
88
symfony:
9-
container_xml_path: %rootDir%/../../../tests/Fixtures/app/var/cache/test/appAppKernelTestDebugContainer.xml
9+
container_xml_path: tests/Fixtures/app/var/cache/test/appAppKernelTestDebugContainer.xml
1010
constant_hassers: false
1111
autoload_files:
12-
- %rootDir%/../../../tests/Fixtures/app/AppKernel.php
12+
- tests/Fixtures/app/AppKernel.php
1313
excludes_analyse:
14-
- %rootDir%/../../../tests/Fixtures/app/var/cache
14+
- tests/Fixtures/app/var/cache
1515
# The Symfony Configuration API isn't good enough to be analysed
16-
- %rootDir%/../../../src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php
16+
- src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php
1717
# Imported code (temporary)
18-
- %rootDir%/../../../src/Bridge/Symfony/Bundle/Test/BrowserKitAssertionsTrait.php
19-
- %rootDir%/../../../tests/Bridge/Symfony/Bundle/Test/WebTestCaseTest.php
18+
- src/Bridge/Symfony/Bundle/Test/BrowserKitAssertionsTrait.php
19+
- tests/Bridge/Symfony/Bundle/Test/WebTestCaseTest.php
20+
earlyTerminatingMethodCalls:
21+
PHPUnit\Framework\Constraint\Constraint:
22+
- fail
2023
ignoreErrors:
2124
# Real problems, hard to fix
2225
- '#Parameter \#2 \$dqlPart of method Doctrine\\ORM\\QueryBuilder::add\(\) expects array\|object, string given\.#'
2326
-
2427
message: '#Return type \(int\) of method ApiPlatform\\Core\\Identifier\\Normalizer\\IntegerDenormalizer::denormalize\(\) should be compatible with return type \(array\|object\) of method Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface::denormalize\(\)#'
25-
path: %currentWorkingDirectory%/src/Identifier/Normalizer/IntegerDenormalizer.php
28+
path: src/Identifier/Normalizer/IntegerDenormalizer.php
2629

2730
# False positives
2831
-
2932
message: '#Variable \$iri might not be defined\.#'
30-
path: %currentWorkingDirectory%/src/JsonApi/Serializer/ItemNormalizer.php
33+
path: src/JsonApi/Serializer/ItemNormalizer.php
3134
-
3235
message: '#Variable \$positionPm might not be defined\.#'
33-
path: %currentWorkingDirectory%/src/Util/ClassInfoTrait.php
36+
path: src/Util/ClassInfoTrait.php
3437
-
35-
message: '#Cannot assign offset .+ to bool\.#'
36-
path: %currentWorkingDirectory%/src/GraphQl/Serializer/SerializerContextBuilder.php
38+
message: "#Cannot access offset 'node' on bool\\.#"
39+
path: src/GraphQl/Serializer/SerializerContextBuilder.php
3740
- '#Access to an undefined property Prophecy\\Prophecy\\ObjectProphecy<(\\?[a-zA-Z0-9_]+)+>::\$[a-zA-Z0-9_]+#'
3841
-
3942
message: '#Call to an undefined method Doctrine\\Persistence\\ObjectManager::getConnection\(\)#'
40-
path: %currentWorkingDirectory%/src/Bridge/Doctrine/Common/Util/IdentifierManagerTrait.php
43+
path: src/Bridge/Doctrine/Common/Util/IdentifierManagerTrait.php
4144
# https://github.com/willdurand/Negotiation/issues/89#issuecomment-513283286
4245
-
4346
message: '#Call to an undefined method Negotiation\\AcceptHeader::getType\(\)\.#'
44-
path: %currentWorkingDirectory%/src/EventListener/AddFormatListener.php
47+
path: src/EventListener/AddFormatListener.php
4548
# https://github.com/symfony/symfony/issues/31814#issuecomment-498749590
4649
-
4750
message: '#Call to an undefined method Symfony\\Component\\Security\\Core\\Role\\RoleHierarchyInterface::getReachableRoles\(\)\.#'
48-
path: %currentWorkingDirectory%/src/Security/ResourceAccessChecker.php
49-
- '#Parameter \#1 \$function of function call_user_func expects callable\(\): mixed, .+ given\.#'
50-
- '#Parameter \#1 \$exception of static method Symfony\\Component\\Debug\\Exception\\FlattenException::create\(\) expects Exception, Symfony\\Component\\Serializer\\Exception\\ExceptionInterface given\.#'
51-
- '#Parameter \#1 \$classes of class ApiPlatform\\Core\\Metadata\\Resource\\ResourceNameCollection constructor expects array<string>, array<int, int\|string> given\.#'
51+
path: src/Security/ResourceAccessChecker.php
5252
- '#Parameter \#1 \$vars of class GraphQL\\Language\\AST\\(IntValue|ObjectField|ObjectValue|BooleanValue|ListValue|StringValue)Node constructor expects array<bool\|float\|GraphQL\\Language\\AST\\Location\|GraphQL\\Language\\AST\\NameNode\|GraphQL\\Language\\AST\\NodeList\|GraphQL\\Language\\AST\\SelectionSetNode\|int\|string\|null>, array<string, .+> given\.#'
5353
- '#Parameter \#1 \$defaultContext of class Symfony\\Component\\Serializer\\Encoder\\Json(De|En)code constructor expects array, (int|true) given\.#'
5454
- '#Parameter \#(2|3) \$(resourceMetadataFactory|pagination) of class ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Extension\\PaginationExtension constructor expects (ApiPlatform\\Core\\Metadata\\Resource\\Factory\\ResourceMetadataFactoryInterface\|Symfony\\Component\\HttpFoundation\\RequestStack|ApiPlatform\\Core\\DataProvider\\Pagination\|ApiPlatform\\Core\\Metadata\\Resource\\Factory\\ResourceMetadataFactoryInterface), stdClass given\.#'
55-
- '#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\.#'
55+
# https://github.com/phpDocumentor/ReflectionDocBlock/pull/209
5656
-
57-
message: '#Parameter \#1 \$resource of method ApiPlatform\\Core\\Metadata\\Extractor\\XmlExtractor::getAttributes\(\) expects SimpleXMLElement, object given\.#'
58-
path: %currentWorkingDirectory%/src/Metadata/Extractor/XmlExtractor.php
57+
message: '#Parameter \#1 \$docblock of method phpDocumentor\\Reflection\\DocBlockFactoryInterface::create\(\) expects string, ReflectionClass<mixed> given\.#'
58+
path: src/Metadata/Resource/Factory/PhpDocResourceMetadataFactory.php
5959
-
60-
message: '#Parameter \#1 \$docblock of method phpDocumentor\\Reflection\\DocBlockFactoryInterface::create\(\) expects string, ReflectionClass given\.#'
61-
path: %currentWorkingDirectory%/src/Metadata/Resource/Factory/PhpDocResourceMetadataFactory.php
60+
message: '#Parameter \#[0-9] \$filterLocator of class .+ constructor expects ApiPlatform\\Core\\Api\\FilterCollection|Psr\\Container\\ContainerInterface, ArrayObject<mixed, mixed> given\.#'
61+
paths:
62+
- tests/Bridge/Doctrine/Orm/Extension/FilterExtensionTest.php
63+
- tests/Bridge/NelmioApiDoc/Extractor/AnnotationsProvider/ApiPlatformProviderTest.php
64+
- tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php
65+
- tests/Swagger/Serializer/DocumentationNormalizerV2Test.php
66+
- tests/Swagger/Serializer/DocumentationNormalizerV3Test.php
6267
-
6368
message: '#Parameter \#1 \$objectValue of method GraphQL\\Type\\Definition\\InterfaceType::resolveType\(\) expects object, array(<string, string>)? given.#'
64-
path: %currentWorkingDirectory%/tests/GraphQl/Type/TypeBuilderTest.php
65-
-
66-
message: '#Property ApiPlatform\\Core\\Test\\DoctrineMongoDbOdmFilterTestCase::\$repository \(Doctrine\\ODM\\MongoDB\\Repository\\DocumentRepository\) does not accept Doctrine\\Persistence\\ObjectRepository\.#'
67-
path: %currentWorkingDirectory%/src/Test/DoctrineMongoDbOdmFilterTestCase.php
68-
-
69-
message: '#Property ApiPlatform\\Core\\Test\\DoctrineOrmFilterTestCase::\$repository \(Doctrine\\ORM\\EntityRepository\) does not accept Doctrine\\Persistence\\ObjectRepository\.#'
70-
path: %currentWorkingDirectory%/src/Test/DoctrineOrmFilterTestCase.php
71-
- '#Method ApiPlatform\\Core\\Util\\RequestParser::parseRequestParams\(\) should return array but returns array\|false\.#'
69+
path: tests/GraphQl/Type/TypeBuilderTest.php
70+
# https://github.com/phpstan/phpstan-doctrine/issues/115
7271
-
73-
message: '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Util\\QueryBuilderHelper::mapJoinAliases() should return array<string, array<string>\|string> but returns array<int|string, mixed>\.#'
74-
path: %currentWorkingDirectory%/src/Bridge/Doctrine/Orm/Util/QueryBuilderHelper.php
75-
# https://github.com/phpstan/phpstan/issues/1482
72+
message: '#Property ApiPlatform\\Core\\Test\\DoctrineMongoDbOdmFilterTestCase::\$repository \(Doctrine\\ODM\\MongoDB\\Repository\\DocumentRepository\) does not accept Doctrine\\ORM\\EntityRepository<ApiPlatform\\Core\\Tests\\Fixtures\\TestBundle\\Document\\Dummy>\.#'
73+
path: src/Test/DoctrineMongoDbOdmFilterTestCase.php
7674
-
77-
message: "#Call to function method_exists\\(\\) with 'Symfony\\\\\\\\Component.+' and 'removeBindings' will always evaluate to false\\.#"
78-
path: %currentWorkingDirectory%/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php
75+
message: "#Call to method PHPUnit\\\\Framework\\\\Assert::assertSame\\(\\) with array\\('(collection_context|item_context|subresource_context)'\\) and array<Symfony\\\\Component\\\\VarDumper\\\\Cloner\\\\Data>\\|bool\\|float\\|int\\|string\\|null will always evaluate to false\\.#"
76+
path: tests/Bridge/Symfony/Bundle/DataCollector/RequestDataCollectorTest.php
77+
# https://github.com/phpstan/phpstan-phpunit/issues/62
7978
-
80-
message: "#Call to function method_exists\\(\\) with 'Symfony\\\\\\\\Component.+' and 'getReachableRoleNam.+' will always evaluate to false\\.#"
81-
path: %currentWorkingDirectory%/tests/Security/EventListener/DenyAccessListenerTest.php
82-
-
83-
message: "#Call to function method_exists\\(\\) with 'Symfony\\\\\\\\Component.+' and 'getRoleNames' will always evaluate to false\\.#"
84-
path: %currentWorkingDirectory%/tests/Security/EventListener/DenyAccessListenerTest.php
85-
- "#Call to method PHPUnit\\\\Framework\\\\Assert::assertSame\\(\\) with array\\('(collection_context|item_context|subresource_context)'\\) and array<Symfony\\\\Component\\\\VarDumper\\\\Cloner\\\\Data>\\|bool\\|float\\|int\\|string\\|null will always evaluate to false\\.#"
79+
message: '#Call to method PHPUnit\\Framework\\Assert::assertSame\(\) with 2 and int will always evaluate to false\.#'
80+
path: tests/Identifier/Normalizer/IntegerDenormalizerTest.php
8681
-
8782
message: '#Binary operation "\+" between (float\|int\|)?string and 0 results in an error\.#'
88-
path: %currentWorkingDirectory%/src/Bridge/Doctrine/Common/Filter/RangeFilterTrait.php
83+
path: src/Bridge/Doctrine/Common/Filter/RangeFilterTrait.php
8984
# https://github.com/phpstan/phpstan-symfony/issues/27
9085
-
9186
message: '#Service "api_platform\.json_schema\.schema_factory" is private\.#'
92-
path: %currentWorkingDirectory%/src/Bridge/Symfony/Bundle/Test/ApiTestAssertionsTrait.php
87+
path: src/Bridge/Symfony/Bundle/Test/ApiTestAssertionsTrait.php
88+
-
89+
message: '#Service "api_platform\.iri_converter" is private\.#'
90+
path: src/Bridge/Symfony/Bundle/Test/ApiTestCase.php
91+
# https://github.com/phpstan/phpstan-symfony/issues/76
92+
-
93+
message: '#Service "api_platform\.graphql\.fields_builder" is private\.#'
94+
path: src/GraphQl/Type/TypeBuilder.php
9395
-
94-
message: '#Service "api_platform.iri_converter" is private\.#'
95-
path: %currentWorkingDirectory%/src/Bridge/Symfony/Bundle/Test/ApiTestCase.php
96+
message: '#Service "test" is not registered in the container\.#'
97+
path: tests/GraphQl/Type/TypesContainerTest.php
98+
# https://github.com/phpstan/phpstan/issues/2999
99+
-
100+
message: '#ArrayObject<string, string> does not accept true\.#'
101+
path: src/JsonSchema/SchemaFactory.php
102+
-
103+
message: '#ArrayObject<string, string> does not accept array<string, mixed>\.#'
104+
path: src/JsonSchema/SchemaFactory.php
105+
-
106+
message: '#Cannot assign new offset to string\.#'
107+
path: src/JsonSchema/SchemaFactory.php
96108

97109
# Expected, due to optional interfaces
98110
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Extension\\QueryCollectionExtensionInterface::applyToCollection\(\) invoked with 5 parameters, 3-4 required\.#'
@@ -115,11 +127,4 @@ parameters:
115127
# Expected, due to backward compatibility
116128
-
117129
message: "#Call to function method_exists\\(\\) with ApiPlatform\\\\Core\\\\JsonApi\\\\Serializer\\\\ItemNormalizer and 'setCircularReferenc…' will always evaluate to false\\.#"
118-
path: %currentWorkingDirectory%/tests/JsonApi/Serializer/ItemNormalizerTest.php
119-
120-
# Expected, due to forward compatibility
121-
-
122-
message: "#Call to function method_exists\\(\\) with 'Symfony\\\\\\\\Component.+' and 'getThrowable' will always evaluate to false\\.#"
123-
paths:
124-
- %currentWorkingDirectory%/tests/Bridge/Symfony/Validator/EventListener/ValidationExceptionListenerTest.php
125-
- %currentWorkingDirectory%/tests/EventListener/ExceptionListenerTest.php
130+
path: tests/JsonApi/Serializer/ItemNormalizerTest.php

src/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ public function getTypes($class, $property, array $context = [])
102102
return $builtinType ? [new Type($builtinType, $nullable)] : null;
103103
}
104104
}
105+
106+
return null;
105107
}
106108

107109
/**

src/Bridge/Symfony/Bundle/Test/Constraint/ArraySubset.php

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Constraint;
1515

1616
use PHPUnit\Framework\Constraint\Constraint;
17-
use PHPUnit\Framework\ExpectationFailedException;
1817
use SebastianBergmann\Comparator\ComparisonFailure;
19-
use SebastianBergmann\RecursionContext\InvalidArgumentException;
2018

2119
/**
2220
* Constraint that asserts that the array it is evaluated for has a specified subset.
@@ -43,21 +41,7 @@ public function __construct(iterable $subset, bool $strict = false)
4341
}
4442

4543
/**
46-
* Evaluates the constraint for parameter $other.
47-
*
48-
* If $returnResult is set to false (the default), an exception is thrown
49-
* in case of a failure. null is returned otherwise.
50-
*
51-
* If $returnResult is true, the result of the evaluation is returned as
52-
* a boolean value instead: true in case of success, false in case of a
53-
* failure.
54-
*
55-
* @param iterable $other
56-
*
57-
* @throws ExpectationFailedException
58-
* @throws InvalidArgumentException
59-
*
60-
* @return iterable|bool|null
44+
* {@inheritdoc}
6145
*/
6246
public function evaluate($other, string $description = '', bool $returnResult = false)
6347
{
@@ -88,24 +72,15 @@ public function evaluate($other, string $description = '', bool $returnResult =
8872
}
8973

9074
/**
91-
* Returns a string representation of the constraint.
92-
*
93-
* @throws InvalidArgumentException
75+
* {@inheritdoc}
9476
*/
9577
public function toString(): string
9678
{
9779
return 'has the subset '.$this->exporter()->export($this->subset);
9880
}
9981

10082
/**
101-
* Returns the description of the failure.
102-
*
103-
* The beginning of failure messages is "Failed asserting that" in most
104-
* cases. This method should return the second part of that sentence.
105-
*
106-
* @param mixed $other evaluated value or object
107-
*
108-
* @throws InvalidArgumentException
83+
* {@inheritdoc}
10984
*/
11085
protected function failureDescription($other): string
11186
{
@@ -120,10 +95,7 @@ private function toArray(iterable $other): array
12095
if ($other instanceof \ArrayObject) {
12196
return $other->getArrayCopy();
12297
}
123-
if ($other instanceof \Traversable) {
124-
return iterator_to_array($other);
125-
}
126-
// Keep BC even if we know that array would not be the expected one
127-
return (array) $other;
98+
99+
return iterator_to_array($other);
128100
}
129101
}

src/DataProvider/OperationDataProviderTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ trait OperationDataProviderTrait
4545
/**
4646
* Retrieves data for a collection operation.
4747
*
48-
* @return iterable|null
48+
* @return iterable
4949
*/
5050
private function getCollectionData(array $attributes, array $context)
5151
{

src/EventListener/SerializeListener.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ public function onKernelView(ViewEvent $event): void
109109
/**
110110
* Tries to serialize data that are not API resources (e.g. the entrypoint or data returned by a custom controller).
111111
*
112-
* @param object $controllerResult
113-
*
114112
* @throws RuntimeException
115113
*/
116114
private function serializeRawData(ViewEvent $event, Request $request, $controllerResult): void

src/GraphQl/Action/EntrypointAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ private function parseData(?string $query, ?string $operation, array $variables,
141141
*/
142142
private function parseMultipartRequest(?string $query, ?string $operation, array $variables, array $bodyParameters, array $files): array
143143
{
144-
/** @var string $operations */
145-
/** @var string $map */
146144
if ((null === $operations = $bodyParameters['operations'] ?? null) || (null === $map = $bodyParameters['map'] ?? null)) {
147145
throw new BadRequestHttpException('GraphQL multipart request does not respect the specification.');
148146
}
149147

148+
/** @var string $operations */
150149
[$query, $operation, $variables] = $this->parseData($query, $operation, $variables, $operations);
151150

151+
/** @var string $map */
152152
if (!\is_array($decodedMap = json_decode($map, true))) {
153153
throw new BadRequestHttpException('GraphQL multipart request map is not valid JSON.');
154154
}

tests/Bridge/Symfony/Bundle/DataCollector/RequestDataCollectorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ private function getUsedCollectionDataProvider(): TraceableChainCollectionDataPr
237237
new class() implements CollectionDataProviderInterface {
238238
public function getCollection(string $resourceClass, string $operationName = null)
239239
{
240+
return [];
240241
}
241242
},
242243
]));
@@ -251,6 +252,7 @@ private function getUsedItemDataProvider(): TraceableChainItemDataProvider
251252
new class() implements ItemDataProviderInterface {
252253
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = [])
253254
{
255+
return null;
254256
}
255257
},
256258
]));
@@ -265,6 +267,7 @@ private function getUsedSubresourceDataProvider(): TraceableChainSubresourceData
265267
new class() implements SubresourceDataProviderInterface {
266268
public function getSubresource(string $resourceClass, array $identifiers, array $context, string $operationName = null)
267269
{
270+
return null;
268271
}
269272
},
270273
]));

tests/Bridge/Symfony/Bundle/DataProvider/TraceableChainCollectionDataCollectorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function dataProviderProvider(): iterable
6464
new class() implements CollectionDataProviderInterface {
6565
public function getCollection(string $resourceClass, string $operationName = null)
6666
{
67+
return [];
6768
}
6869
},
6970
['some_context'],
@@ -125,6 +126,7 @@ public function getCollection(string $resourceClass, string $operationName = nul
125126
new class() implements CollectionDataProviderInterface {
126127
public function getCollection(string $resourceClass, string $operationName = null)
127128
{
129+
return [];
128130
}
129131
},
130132
]),

0 commit comments

Comments
 (0)