Skip to content

Commit c6d5fb5

Browse files
committed
Fix phpstan errors because of changes in Symfony
1 parent 4373de6 commit c6d5fb5

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ parameters:
2121
# Real problems, hard to fix
2222
- '#Parameter \#2 \$dqlPart of method Doctrine\\ORM\\QueryBuilder::add\(\) expects array\|object, string given\.#'
2323
-
24-
message: '#Return type \(int\) of method ApiPlatform\\Core\\Identifier\\Normalizer\\IntegerDenormalizer::denormalize\(\) should be compatible with return type \(object\) of method Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface::denormalize\(\)#'
24+
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\(\)#'
2525
path: %currentWorkingDirectory%/src/Identifier/Normalizer/IntegerDenormalizer.php
2626

2727
# False positives

src/Bridge/Elasticsearch/DataProvider/ItemDataProvider.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ public function getItem(string $resourceClass, $id, ?string $operationName = nul
101101
return null;
102102
}
103103

104-
return $this->denormalizer->denormalize($document, $resourceClass, ItemNormalizer::FORMAT, [AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => true]);
104+
$item = $this->denormalizer->denormalize($document, $resourceClass, ItemNormalizer::FORMAT, [AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => true]);
105+
if (!\is_object($item) && null !== $item) {
106+
throw new \UnexpectedValueException('Expected item to be an object or null.');
107+
}
108+
109+
return $item;
105110
}
106111
}

src/GraphQl/Resolver/Factory/ItemMutationResolverFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ public function __invoke(string $resourceClass = null, string $rootClass = null,
123123

124124
$context += $resourceMetadata->getGraphqlAttribute($operationName, 'denormalization_context', [], true);
125125
$item = $this->normalizer->denormalize($args['input'], $inputClass ?: $resourceClass, ItemNormalizer::FORMAT, $context);
126+
if (!\is_object($item)) {
127+
throw new \UnexpectedValueException('Expected item to be an object.');
128+
}
126129
$this->canAccess($this->resourceAccessChecker, $resourceMetadata, $resourceClass, $info, [
127130
'object' => $item,
128131
'previous_object' => $previousItem,

src/HttpCache/EventListener/AddHeadersListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function onKernelResponse(FilterResponseEvent $event): void
6363
}
6464

6565
if ($this->etag && !$response->getEtag()) {
66-
$response->setEtag(md5($response->getContent()));
66+
$response->setEtag(md5((string) $response->getContent()));
6767
}
6868

6969
if (null !== ($maxAge = $resourceCacheHeaders['max_age'] ?? $this->maxAge) && !$response->headers->hasCacheControlDirective('max-age')) {

src/Serializer/AbstractItemNormalizer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ public function denormalize($data, $class, $format = null, array $context = [])
183183
throw new LogicException('Cannot denormalize the input because the injected serializer is not a denormalizer');
184184
}
185185
$denormalizedInput = $this->serializer->denormalize($data, $inputClass, $format, $context);
186+
if (!\is_object($denormalizedInput)) {
187+
throw new \UnexpectedValueException('Expected denormalized input to be an object.');
188+
}
186189

187190
return $dataTransformer->transform($denormalizedInput, $resourceClass, $dataTransformerContext);
188191
}
@@ -437,7 +440,12 @@ protected function denormalizeRelation(string $attributeName, PropertyMetadata $
437440
}
438441

439442
try {
440-
return $this->serializer->denormalize($value, $className, $format, $context);
443+
$item = $this->serializer->denormalize($value, $className, $format, $context);
444+
if (!\is_object($item) && null !== $item) {
445+
throw new \UnexpectedValueException('Expected item to be an object or null.');
446+
}
447+
448+
return $item;
441449
} catch (InvalidValueException $e) {
442450
if (!$supportsPlainIdentifiers) {
443451
throw $e;

0 commit comments

Comments
 (0)