Skip to content

Commit 2333b2c

Browse files
committed
Enable "inferPrivatePropertyTypeFromConstructor" option in phpstan
1 parent 269b052 commit 2333b2c

File tree

45 files changed

+166
-93
lines changed

Some content is hidden

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

45 files changed

+166
-93
lines changed

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ jobs:
224224
working_directory: ~/api-platform/core
225225
steps:
226226
- checkout
227-
- install-mongodb-php-extension
228227
- disable-xdebug-php-extension
229228
- disable-php-memory-limit
230229
- update-composer

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ indent_size = 2
5050
[.gitmodules]
5151
indent_style = tab
5252

53-
[.php_cs]
53+
[.php_cs{,.dist}]
5454
indent_style = space
5555
indent_size = 4
5656

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"phpdocumentor/type-resolver": "^0.3 || ^0.4",
5050
"phpspec/prophecy": "^1.8",
5151
"phpstan/extension-installer": "^1.0",
52-
"phpstan/phpstan": "^0.11",
52+
"phpstan/phpstan": "^0.11.10",
5353
"phpstan/phpstan-doctrine": "^0.11",
5454
"phpstan/phpstan-phpunit": "^0.11",
5555
"phpstan/phpstan-symfony": "^0.11",

phpstan.neon.dist

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ parameters:
77
- src
88
- tests
99
- tests/Fixtures/app/console
10+
inferPrivatePropertyTypeFromConstructor: true
1011
symfony:
1112
container_xml_path: %rootDir%/../../../tests/Fixtures/app/var/cache/test/appAppKernelTestDebugContainer.xml
1213
constant_hassers: false
@@ -32,6 +33,14 @@ parameters:
3233
path: %currentWorkingDirectory%/src/GraphQl/Resolver/FieldsToAttributesTrait.php
3334
- '#Access to an undefined property Prophecy\\Prophecy\\ObjectProphecy<(\\?[a-zA-Z0-9_]+)+>::\$[a-zA-Z0-9_]+#'
3435
- '#Call to an undefined method Doctrine\\Common\\Persistence\\ObjectManager::getConnection\(\)#'
36+
# https://github.com/willdurand/Negotiation/issues/89#issuecomment-513283286
37+
-
38+
message: '#Call to an undefined method Negotiation\\AcceptHeader::getType\(\)\.#'
39+
path: %currentWorkingDirectory%/src/EventListener/AddFormatListener.php
40+
# https://github.com/symfony/symfony/issues/31814#issuecomment-498749590
41+
-
42+
message: '#Call to an undefined method Symfony\\Component\\Security\\Core\\Role\\RoleHierarchyInterface::getReachableRoles\(\)\.#'
43+
path: %currentWorkingDirectory%/src/Security/ResourceAccessChecker.php
3544
- '#Parameter \#1 \$function of function call_user_func expects callable\(\): mixed, .+ given\.#'
3645
- '#Parameter \#1 \$exception of static method Symfony\\Component\\Debug\\Exception\\FlattenException::create\(\) expects Exception, Symfony\\Component\\Serializer\\Exception\\ExceptionInterface given\.#'
3746
- '#Parameter \#1 \$classes of class ApiPlatform\\Core\\Metadata\\Resource\\ResourceNameCollection constructor expects array<string>, array<int, int\|string> given\.#'
@@ -52,14 +61,8 @@ parameters:
5261
message: '#Parameter \#1 \$collection of method ApiPlatform\\Core\\Tests\\GraphQl\\Resolver\\Factory\\CollectionResolverFactoryTest::createCollectionResolverFactory\(\) expects array\|Iterator, object given\.#'
5362
path: %currentWorkingDirectory%/tests/GraphQl/Resolver/Factory/CollectionResolverFactoryTest.php
5463
-
55-
message: '#Parameter \#1 \$resourceClass of method ApiPlatform\\Core\\Metadata\\Property\\Factory\\InheritedPropertyMetadataFactory::create\(\) expects string, object\|string given\.#'
56-
path: %currentWorkingDirectory%/src/Metadata/Property/Factory/InheritedPropertyMetadataFactory.php
57-
-
58-
message: '#Parameter \#1 \$childInherited of method ApiPlatform\\Core\\Metadata\\Property\\PropertyMetadata::withChildInherited\(\) expects string, object\|string given\.#'
59-
path: %currentWorkingDirectory%/src/Metadata/Property/Factory/InheritedPropertyMetadataFactory.php
60-
-
61-
message: '#Parameter \#1 \$resourceClass of method ApiPlatform\\Core\\Metadata\\Property\\Factory\\InheritedPropertyNameCollectionFactory::create\(\) expects string, object\|string given\.#'
62-
path: %currentWorkingDirectory%/src/Metadata/Property/Factory/InheritedPropertyNameCollectionFactory.php
64+
message: '#Parameter \#1 \$docblock of method phpDocumentor\\Reflection\\DocBlockFactoryInterface::create\(\) expects string, ReflectionClass given\.#'
65+
path: %currentWorkingDirectory%/src/Metadata/Resource/Factory/PhpDocResourceMetadataFactory.php
6366
-
6467
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>\.#'
6568
path: %currentWorkingDirectory%/src/Test/DoctrineMongoDbOdmFilterTestCase.php
@@ -85,14 +88,22 @@ parameters:
8588
message: '#Binary operation "\+" between (float\|int\|)?string and 0 results in an error\.#'
8689
path: %currentWorkingDirectory%/src/Bridge/Doctrine/Common/Filter/RangeFilterTrait.php
8790

88-
# Expected, due to deprecations
91+
# Expected, due to optional interfaces
92+
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Extension\\QueryCollectionExtensionInterface::applyToCollection\(\) invoked with 5 parameters, 3-4 required\.#'
8993
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Extension\\QueryResult(Item|Collection)ExtensionInterface::getResult\(\) invoked with 4 parameters, 1 required\.#'
9094
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Extension\\QueryResult(Item|Collection)ExtensionInterface::supportsResult\(\) invoked with 3 parameters, 1-2 required\.#'
95+
- '#Method ApiPlatform\\Core\\Bridge\\Symfony\\Routing\\RouteNameResolverInterface::getRouteName\(\) invoked with 3 parameters, 2 required\.#'
96+
- '#Method ApiPlatform\\Core\\DataPersister\\DataPersisterInterface::persist\(\) invoked with 2 parameters, 1 required\.#'
97+
- '#Method ApiPlatform\\Core\\DataPersister\\DataPersisterInterface::remove\(\) invoked with 2 parameters, 1 required\.#'
98+
- '#Method ApiPlatform\\Core\\DataPersister\\DataPersisterInterface::supports\(\) invoked with 2 parameters, 1 required\.#'
99+
- '#Method ApiPlatform\\Core\\DataProvider\\CollectionDataProviderInterface::getCollection\(\) invoked with 3 parameters, 1-2 required\.#'
100+
- '#Method Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface::denormalize\(\) invoked with (2|3|4) parameters, 1 required\.#'
101+
- '#Method Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface::normalize\(\) invoked with (2|3|4) parameters, 1 required\.#'
102+
- '#Method Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface::supportsNormalization\(\) invoked with 3 parameters, 1-2 required\.#'
103+
104+
# Expected, due to deprecations
91105
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\AbstractFilter::apply\(\) invoked with 5 parameters, 3-4 required\.#'
92106
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\AbstractFilter::filterProperty\(\) invoked with 7 parameters, 5-6 required\.#'
93107
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\FilterInterface::apply\(\) invoked with 5 parameters, 3-4 required\.#'
94108
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\OrderFilter::filterProperty\(\) invoked with 7 parameters, 5-6 required\.#'
95-
- '#Method ApiPlatform\\Core\\DataProvider\\CollectionDataProviderInterface::getCollection\(\) invoked with 3 parameters, 1-2 required\.#'
96-
- '#Method Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface::normalize\(\) invoked with 3 parameters, 1 required\.#'
97-
- '#Method Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface::normalize\(\) invoked with 4 parameters, 1 required\.#'
98-
- '#Class Symfony\\Component\\HttpKernel\\EventListener\\ExceptionListener constructor invoked with 5 parameters, 1-3 required\.#'
109+
- '#Method ApiPlatform\\Core\\PathResolver\\OperationPathResolverInterface::resolveOperationPath\(\) invoked with 4 parameters, 3 required\.#'

src/Api/FormatMatcher.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@
2020
*/
2121
final class FormatMatcher
2222
{
23+
/**
24+
* @var array<string, string[]>
25+
*/
2326
private $formats;
2427

28+
/**
29+
* @param array<string, string[]|string> $formats
30+
*/
2531
public function __construct(array $formats)
2632
{
2733
$normalizedFormats = [];

src/Bridge/Doctrine/EventListener/PublishMercureUpdatesListener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ final class PublishMercureUpdatesListener
4848
private $deletedEntities;
4949
private $formats;
5050

51+
/**
52+
* @param array<string, string[]|string> $formats
53+
*/
5154
public function __construct(ResourceClassResolverInterface $resourceClassResolver, IriConverterInterface $iriConverter, ResourceMetadataFactoryInterface $resourceMetadataFactory, SerializerInterface $serializer, array $formats, MessageBusInterface $messageBus = null, callable $publisher = null, ExpressionLanguage $expressionLanguage = null)
5255
{
5356
if (null === $messageBus && null === $publisher) {
@@ -166,6 +169,7 @@ private function publishUpdate($entity, array $targets): void
166169
// This may change in the feature, because it's not JSON Merge Patch compliant,
167170
// and I'm not a fond of this approach
168171
$iri = $entity->iri;
172+
/** @var string $data */
169173
$data = json_encode(['@id' => $entity->id]);
170174
} else {
171175
$resourceClass = $this->getObjectClass($entity);

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\Common\Collections\Collection;
1717
use Doctrine\Common\Persistence\Mapping\MappingException;
1818
use Doctrine\Common\Persistence\ObjectManager;
19+
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata as MongoDbClassMetadata;
1920
use Doctrine\ODM\MongoDB\Types\Type as MongoDbType;
2021
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
2122
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
@@ -63,17 +64,11 @@ public function getTypes($class, $property, array $context = [])
6364
return null;
6465
}
6566

66-
$reflectionMetadata = new \ReflectionClass($metadata);
67-
6867
if ($metadata->hasAssociation($property)) {
6968
$class = $metadata->getAssociationTargetClass($property);
7069

7170
if ($metadata->isSingleValuedAssociation($property)) {
72-
if ($reflectionMetadata->hasMethod('isNullable')) {
73-
$nullable = $metadata->isNullable($property);
74-
} else {
75-
$nullable = false;
76-
}
71+
$nullable = $metadata instanceof MongoDbClassMetadata && $metadata->isNullable($property);
7772

7873
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, $class)];
7974
}
@@ -94,7 +89,7 @@ public function getTypes($class, $property, array $context = [])
9489

9590
if ($metadata->hasField($property)) {
9691
$typeOfField = $metadata->getTypeOfField($property);
97-
$nullable = $reflectionMetadata->hasMethod('isNullable') && $metadata->isNullable($property);
92+
$nullable = $metadata instanceof MongoDbClassMetadata && $metadata->isNullable($property);
9893

9994
switch ($typeOfField) {
10095
case MongoDbType::DATE:

src/Bridge/Doctrine/Orm/CollectionDataProvider.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace ApiPlatform\Core\Bridge\Doctrine\Orm;
1515

16-
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\ContextAwareQueryCollectionExtensionInterface;
1716
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
1817
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryResultCollectionExtensionInterface;
1918
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator;
@@ -36,9 +35,9 @@ class CollectionDataProvider implements ContextAwareCollectionDataProviderInterf
3635
private $collectionExtensions;
3736

3837
/**
39-
* @param QueryCollectionExtensionInterface[]|ContextAwareQueryCollectionExtensionInterface[] $collectionExtensions
38+
* @param QueryCollectionExtensionInterface[] $collectionExtensions
4039
*/
41-
public function __construct(ManagerRegistry $managerRegistry, /* iterable */ $collectionExtensions = [])
40+
public function __construct(ManagerRegistry $managerRegistry, iterable $collectionExtensions = [])
4241
{
4342
$this->managerRegistry = $managerRegistry;
4443
$this->collectionExtensions = $collectionExtensions;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ final class PaginationExtension implements ContextAwareQueryResultCollectionExte
3838
{
3939
private $managerRegistry;
4040
private $requestStack;
41+
/**
42+
* @var ResourceMetadataFactoryInterface
43+
*/
4144
private $resourceMetadataFactory;
4245
private $enabled;
4346
private $clientEnabled;
@@ -50,6 +53,9 @@ final class PaginationExtension implements ContextAwareQueryResultCollectionExte
5053
private $partial;
5154
private $clientPartial;
5255
private $partialParameterName;
56+
/**
57+
* @var Pagination|null
58+
*/
5359
private $pagination;
5460

5561
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface QueryResultCollectionExtensionInterface extends QueryCollectionExtensi
2727
public function supportsResult(string $resourceClass, string $operationName = null): bool;
2828

2929
/**
30-
* @return array|\Traversable
30+
* @return iterable
3131
*/
3232
public function getResult(QueryBuilder $queryBuilder);
3333
}

0 commit comments

Comments
 (0)