Skip to content

Commit c326387

Browse files
committed
Merge branch '2.4' into merge-2.4
2 parents 6e9ccf7 + a0c9eff commit c326387

File tree

8 files changed

+72
-7
lines changed

8 files changed

+72
-7
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ parameters:
2424
# Real problems, hard to fix
2525
- '#Parameter \#2 \$dqlPart of method Doctrine\\ORM\\QueryBuilder::add\(\) expects array\|object, string given\.#'
2626
-
27-
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\(\)#'
27+
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\(\)#'
2828
path: %currentWorkingDirectory%/src/Identifier/Normalizer/IntegerDenormalizer.php
2929

3030
# False positives

src/Bridge/Doctrine/Orm/CollectionDataProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
2121
use ApiPlatform\Core\Exception\RuntimeException;
2222
use Doctrine\Common\Persistence\ManagerRegistry;
23-
use Doctrine\Common\Persistence\ObjectManager;
2423
use Doctrine\ORM\EntityManagerInterface;
2524

2625
/**
@@ -56,7 +55,7 @@ public function supports(string $resourceClass, string $operationName = null, ar
5655
*/
5756
public function getCollection(string $resourceClass, string $operationName = null, array $context = [])
5857
{
59-
/** @var ObjectManager $manager */
58+
/** @var EntityManagerInterface $manager */
6059
$manager = $this->managerRegistry->getManagerForClass($resourceClass);
6160

6261
$repository = $manager->getRepository($resourceClass);

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/Stage/DeserializeStage.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public function __invoke($objectToPopulate, string $resourceClass, string $opera
5454
$denormalizationContext[AbstractNormalizer::OBJECT_TO_POPULATE] = $objectToPopulate;
5555
}
5656

57-
return $this->denormalizer->denormalize($context['args']['input'], $resourceClass, ItemNormalizer::FORMAT, $denormalizationContext);
57+
$item = $this->denormalizer->denormalize($context['args']['input'], $resourceClass, ItemNormalizer::FORMAT, $denormalizationContext);
58+
59+
if (!\is_object($item)) {
60+
throw new \UnexpectedValueException('Expected item to be an object.');
61+
}
62+
63+
return $item;
5864
}
5965
}

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;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\BrowserKit;
15+
16+
use Symfony\Bundle\FrameworkBundle\Client as BaseClient;
17+
use Symfony\Component\BrowserKit\Request as DomRequest;
18+
use Symfony\Component\HttpFoundation\Request;
19+
20+
class Client extends BaseClient
21+
{
22+
/**
23+
* {@inheritdoc}
24+
*/
25+
protected function filterRequest(DomRequest $request): Request
26+
{
27+
$request = parent::filterRequest($request);
28+
29+
foreach ($request->headers->all() as $key => $value) {
30+
if ([null] === $value) {
31+
$request->headers->remove($key);
32+
}
33+
}
34+
35+
return $request;
36+
}
37+
}

tests/Fixtures/app/config/config_common.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ parameters:
8282
container.dumper.inline_class_loader: true
8383

8484
services:
85+
test.client:
86+
class: ApiPlatform\Core\Tests\Fixtures\TestBundle\BrowserKit\Client
87+
shared: false
88+
public: true
89+
arguments:
90+
- '@kernel'
91+
- '%test.client.parameters%'
92+
- '@test.client.history'
93+
- '@test.client.cookiejar'
94+
8595
ApiPlatform\Core\Tests\Fixtures\TestBundle\MessageHandler\:
8696
resource: '../../TestBundle/MessageHandler'
8797
autowire: true

0 commit comments

Comments
 (0)