Skip to content

Commit f4dfa2e

Browse files
authored
Merge pull request #3282 from alanpoulain/sf5
Fix phpstan running on Symfony 5.0
2 parents ab2f82c + ef1f7f4 commit f4dfa2e

File tree

4 files changed

+13
-27
lines changed

4 files changed

+13
-27
lines changed

phpstan.neon.dist

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,28 +107,14 @@ parameters:
107107
- '#Method ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Filter\\(AbstractFilter|FilterInterface)::apply\(\) invoked with 5 parameters, 3-4 required\.#'
108108
- '#Method ApiPlatform\\Core\\PathResolver\\OperationPathResolverInterface::resolveOperationPath\(\) invoked with 4 parameters, 3 required\.#'
109109

110-
# Expected, due to forward compatibility
111-
-
112-
message: '#Class Symfony\\Component\\ErrorHandler\\ErrorRenderer\\ErrorRendererInterface not found\.#'
113-
path: %currentWorkingDirectory%/tests/Fixtures/app/AppKernel.php
114-
- '#Class Symfony\\Component\\ErrorHandler\\Exception\\FlattenException not found\.#'
115-
-
116-
message: '#Class Symfony\\Component\\HttpKernel\\EventListener\\ErrorListener not found\.#'
117-
path: %currentWorkingDirectory%/src/EventListener/ExceptionListener.php
118-
-
119-
message: '#Instantiated class Symfony\\Component\\HttpKernel\\EventListener\\ErrorListener not found\.#'
120-
path: %currentWorkingDirectory%/src/EventListener/ExceptionListener.php
110+
# Expected, due to backward compatibility
121111
-
122-
message: '#Parameter \$exception of method ApiPlatform\\Core\\Action\\ExceptionAction::__invoke\(\) has invalid typehint type Symfony\\Component\\ErrorHandler\\Exception\\FlattenException\.#'
123-
path: %currentWorkingDirectory%/src/Action/ExceptionAction.php
124-
- '#Call to method get(Class|Headers|StatusCode)\(\) on an unknown class Symfony\\Component\\ErrorHandler\\Exception\\FlattenException\.#'
112+
message: "#Call to function method_exists\\(\\) with ApiPlatform\\\\Core\\\\JsonApi\\\\Serializer\\\\ItemNormalizer and 'setCircularReferenc…' will always evaluate to false\\.#"
113+
path: %currentWorkingDirectory%/tests/JsonApi/Serializer/ItemNormalizerTest.php
114+
115+
# Expected, due to forward compatibility
125116
-
126117
message: "#Call to function method_exists\\(\\) with 'Symfony\\\\\\\\Component.+' and 'getThrowable' will always evaluate to false\\.#"
127118
paths:
128119
- %currentWorkingDirectory%/tests/Bridge/Symfony/Validator/EventListener/ValidationExceptionListenerTest.php
129120
- %currentWorkingDirectory%/tests/EventListener/ExceptionListenerTest.php
130-
-
131-
message: '#Instanceof between bool\|float\|int|null and ArrayObject will always evaluate to false\.#'
132-
paths:
133-
- %currentWorkingDirectory%/src/JsonApi/Serializer/ItemNormalizer.php
134-
- %currentWorkingDirectory%/src/Serializer/AbstractItemNormalizer.php

src/Serializer/AbstractItemNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function __construct(PropertyNameCollectionFactoryInterface $propertyName
6868
return $this->iriConverter->getIriFromItem($object);
6969
};
7070
}
71-
if (!interface_exists(AdvancedNameConverterInterface::class)) {
71+
if (!interface_exists(AdvancedNameConverterInterface::class) && method_exists($this, 'setCircularReferenceHandler')) {
7272
$this->setCircularReferenceHandler($defaultContext['circular_reference_handler']);
7373
}
7474

tests/JsonApi/Serializer/ItemNormalizerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,17 @@ public function testNormalizeCircularReference()
191191
$normalizer->setSerializer($this->prophesize(SerializerInterface::class)->reveal());
192192

193193
$circularReferenceLimit = 2;
194-
if (interface_exists(AdvancedNameConverterInterface::class)) {
194+
if (!interface_exists(AdvancedNameConverterInterface::class) && method_exists($normalizer, 'setCircularReferenceLimit')) {
195+
$normalizer->setCircularReferenceLimit($circularReferenceLimit);
196+
195197
$context = [
196-
'circular_reference_limit' => $circularReferenceLimit,
197-
'circular_reference_limit_counters' => [spl_object_hash($circularReferenceEntity) => 2],
198+
'circular_reference_limit' => [spl_object_hash($circularReferenceEntity) => 2],
198199
'cache_error' => function () {},
199200
];
200201
} else {
201-
$normalizer->setCircularReferenceLimit($circularReferenceLimit);
202-
203202
$context = [
204-
'circular_reference_limit' => [spl_object_hash($circularReferenceEntity) => 2],
203+
'circular_reference_limit' => $circularReferenceLimit,
204+
'circular_reference_limit_counters' => [spl_object_hash($circularReferenceEntity) => 2],
205205
'cache_error' => function () {},
206206
];
207207
}

tests/Serializer/AbstractItemNormalizerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function testNormalize()
181181
]);
182182
$normalizer->setSerializer($serializerProphecy->reveal());
183183

184-
if (!interface_exists(AdvancedNameConverterInterface::class)) {
184+
if (!interface_exists(AdvancedNameConverterInterface::class) && method_exists($normalizer, 'setIgnoredAttributes')) {
185185
$normalizer->setIgnoredAttributes(['alias']);
186186
}
187187

0 commit comments

Comments
 (0)