Skip to content

Commit 3946a66

Browse files
committed
Fix PHPStan issues
1 parent 30d8213 commit 3946a66

File tree

7 files changed

+14
-11
lines changed

7 files changed

+14
-11
lines changed

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ parameters:
1616
- '#Call to an undefined method PHPUnit\\Framework\\MockObject\\MockObject::[a-zA-Z0-9_]+\(\)#'
1717
- '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy::[a-zA-Z0-9_]+\(\)#'
1818
- '#Method ApiPlatform\\Core\\Tests\\Bridge\\Doctrine\\Orm\\ItemDataProviderTest::getManagerRegistry\(\) should return Doctrine\\Common\\Persistence\\ManagerRegistry but returns object\.#'
19-
- '#Method ApiPlatform\\Core\\Tests\\Bridge\\Doctrine\\Util\\IdentifierManagerTraitTest::getObjectManager\(\) should return Doctrine\\Common\\Persistence\\ObjectManager but returns object\.#'
19+
- '#Method ApiPlatform\\Core\\Tests\\Bridge\\Doctrine\\Orm\\Util\\IdentifierManagerTraitTest::getObjectManager\(\) should return Doctrine\\Common\\Persistence\\ObjectManager but returns object\.#'
2020
# Temporary fix while the PHPStan extension for Prophecy isn't compatible with 0.10
2121
- '#Parameter .* expects .*, .*object.* given\.#'
2222
- '#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\.#'

src/DataProvider/OperationDataProviderTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ trait OperationDataProviderTrait
3838
private $subresourceDataProvider;
3939

4040
/**
41-
* @var IdentifierConverterInterface
41+
* @var IdentifierConverterInterface|null
4242
*/
4343
private $identifierConverter;
4444

@@ -92,7 +92,7 @@ private function extractIdentifiers(array $parameters, array $attributes)
9292

9393
$id = $parameters['id'];
9494

95-
if ($this->identifierConverter) {
95+
if (null !== $this->identifierConverter) {
9696
return $this->identifierConverter->convert((string) $id, $attributes['resource_class']);
9797
}
9898

@@ -108,7 +108,7 @@ private function extractIdentifiers(array $parameters, array $attributes)
108108

109109
$identifiers[$id] = $parameters[$id];
110110

111-
if ($this->identifierConverter) {
111+
if (null !== $this->identifierConverter) {
112112
$identifiers[$id] = $this->identifierConverter->convert((string) $identifiers[$id], $resourceClass);
113113
}
114114
}

src/JsonApi/Serializer/ItemNormalizer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ protected function normalizeRelation(PropertyMetadata $propertyMetadata, $relate
214214
}
215215
if (isset($context['api_included'])) {
216216
$context['api_sub_level'] = true;
217+
218+
if (!$this->serializer instanceof NormalizerInterface) {
219+
throw new InvalidArgumentException(sprintf('The injected serializer must be an instance of "%s".', NormalizerInterface::class));
220+
}
217221
$data = $this->serializer->normalize($relatedObject, $format, $context);
218222
unset($context['api_sub_level']);
219223

tests/Bridge/Doctrine/Orm/SubresourceDataProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public function testGetSubSubresourceItemLegacy()
425425

426426
$managerRegistryProphecy->getManagerForClass(RelatedDummy::class)->shouldBeCalled()->willReturn($rDummyManagerProphecy->reveal());
427427

428-
$result = new \StdClass();
428+
$result = new \stdClass();
429429
// Origin manager (ThirdLevel)
430430
$queryProphecy = $this->prophesize(AbstractQuery::class);
431431
$queryProphecy->getOneOrNullResult()->shouldBeCalled()->willReturn($result);

tests/Bridge/Doctrine/Orm/Util/IdentifierManagerTraitTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@ private function getMetadataFactories(string $resourceClass, array $identifiers)
146146

147147
/**
148148
* Gets a mocked object manager.
149-
*
150-
* @param string $resourceClass
151-
* @param array $identifierFields
152-
*
153-
* @return ObjectManager
154149
*/
155150
private function getObjectManager(string $resourceClass, array $identifierFields): ObjectManager
156151
{

tests/Bridge/Symfony/Routing/IriConverterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function testNotAbleToGenerateGetItemIriFromResourceClass()
207207

208208
public function testGetItemFromIriWithIdentifierConverter()
209209
{
210-
$item = new \StdClass();
210+
$item = new \stdClass();
211211
$itemDataProviderProphecy = $this->prophesize(ItemDataProviderInterface::class);
212212
$itemDataProviderProphecy->getItem(Dummy::class, ['id' => 3], 'get', ['fetch_data' => true, IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER => true])->shouldBeCalled()->willReturn($item);
213213
$identifierConverterProphecy = $this->prophesize(IdentifierConverterInterface::class);

tests/Fixtures/TestBundle/DataProvider/ContainNonResourceItemDataProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public function supports(string $resourceClass, string $operationName = null, ar
3333
*/
3434
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = [])
3535
{
36+
if (!is_scalar($id)) {
37+
throw new \InvalidArgumentException('The id must be a scalar.');
38+
}
39+
3640
// Retrieve the blog post item from somewhere
3741
$cnr = new ContainNonResource();
3842
$cnr->id = $id;

0 commit comments

Comments
 (0)