Skip to content

Commit

Permalink
Merge 1f794eb into 359baae
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneBullier committed Nov 17, 2021
2 parents 359baae + 1f794eb commit f30749e
Show file tree
Hide file tree
Showing 66 changed files with 138 additions and 186 deletions.
21 changes: 11 additions & 10 deletions composer.json
Expand Up @@ -17,20 +17,21 @@
"doctrine/inflector": "^1.0 || ^2.0",
"fig/link-util": "^1.0",
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"psr/container": "^1.0",
"psr/container": "^1.0 || ^2.0",
"symfony/http-foundation": "^4.4 || ^5.1",
"symfony/http-kernel": "^4.4 || ^5.1",
"symfony/property-access": "^3.4.19 || ^4.4 || ^5.1",
"symfony/property-info": "^3.4 || ^4.4 || ^5.2.1",
"symfony/serializer": "^4.4 || ^5.1",
"symfony/uid": "^5.3",
"symfony/web-link": "^4.4 || ^5.1",
"willdurand/negotiation": "^2.0.3 || ^3.0"
},
"require-dev": {
"behat/behat": "^3.1",
"behat/mink": "^1.7",
"doctrine/annotations": "^1.7",
"doctrine/cache": "^1.11",
"doctrine/cache": "^1.11 || ^2.1",
"doctrine/common": "^2.11 || ^3.0",
"doctrine/data-fixtures": "^1.2.2",
"doctrine/dbal": "^2.6",
Expand All @@ -43,16 +44,16 @@
"friends-of-behat/mink-extension": "^2.2",
"friends-of-behat/symfony-extension": "^2.1",
"guzzlehttp/guzzle": "^6.0 || ^7.0",
"jangregor/phpstan-prophecy": "^0.8",
"jangregor/phpstan-prophecy": "^1.0",
"justinrainbow/json-schema": "^5.2.1",
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0 || ^5.1",
"phpdocumentor/type-resolver": "^0.3 || ^0.4 || ^1.4",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.65",
"phpstan/phpstan-doctrine": "^0.12.7",
"phpstan/phpstan-phpunit": "^0.12.4",
"phpstan/phpstan-symfony": "^0.12.4",
"psr/log": "^1.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.1",
"phpstan/phpstan-doctrine": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-symfony": "^1.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"ramsey/uuid": "^3.7 || ^4.0",
"ramsey/uuid-doctrine": "^1.4",
"soyuka/contexts": "^3.3.1",
Expand All @@ -76,7 +77,7 @@
"symfony/intl": "^4.4 || ^5.3",
"symfony/mercure-bundle": "*",
"symfony/messenger": "^4.4 || ^5.1",
"symfony/phpunit-bridge": "^5.1.7",
"symfony/phpunit-bridge": "^5.4@dev",
"symfony/routing": "^3.4 || ^4.4 || ^5.1",
"symfony/security-bundle": "^3.4 || ^4.4 || ^5.1",
"symfony/security-core": "^4.4 || ^5.1",
Expand Down
17 changes: 16 additions & 1 deletion phpstan.neon.dist
Expand Up @@ -8,12 +8,14 @@ parameters:
symfony:
container_xml_path: tests/Fixtures/app/var/cache/test/AppKernelTestDebugContainer.xml
constant_hassers: false
doctrine:
objectManagerLoader: tests/Fixtures/app/object-manager.php
bootstrapFiles:
- vendor/bin/.phpunit/phpunit/vendor/autoload.php
# We're aliasing classes for phpunit in this file, it needs to be added here see phpstan/#2194
- src/Bridge/Symfony/Bundle/Test/Constraint/ArraySubset.php
- tests/Fixtures/app/AppKernel.php
excludes_analyse:
excludePaths:
# Symfony cache
- tests/Fixtures/app/var/cache
# Deprecated integrations (will be removed in API Platform 3)
Expand Down Expand Up @@ -41,6 +43,19 @@ parameters:
- fail
ignoreErrors:
# False positives
-
message: '#is never read, only written.#'
paths:
- tests/Fixtures/TestBundle/Document/
- tests/Fixtures/TestBundle/Entity/
- tests/Behat/
- src/Identifier/
- src/Bridge/Doctrine/MongoDbOdm/
-
message: '#is never written, only read.#'
paths:
- tests/Fixtures/TestBundle/Document/
- tests/Fixtures/TestBundle/Entity/
-
message: '#Strict comparison using !== between .+ and .+ will always evaluate to false\.#'
paths:
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/ApiFilter.php
Expand Up @@ -66,7 +66,7 @@ public function __construct(
) {
if (\is_array($filterClass)) { /** @phpstan-ignore-line Doctrine annotations */
$options = $filterClass;
$this->filterClass = $options['value'] ?? null;
$this->filterClass = $options['value'] ?? null; /** @phpstan-ignore-line Doctrine annotations */
unset($options['value']);

foreach ($options as $key => $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/ApiResource.php
Expand Up @@ -234,6 +234,6 @@ public function __construct(
}
}

$this->hydrateAttributes($description ?? []);
$this->hydrateAttributes($description ?? []); // @phpstan-ignore-line
}
}
10 changes: 6 additions & 4 deletions src/Annotation/ApiSubresource.php
Expand Up @@ -37,10 +37,12 @@ final class ApiSubresource
*/
public function __construct($maxDepth = null)
{
if (!\is_array($maxDepth)) { // @phpstan-ignore-line
$this->maxDepth = $maxDepth;
} else {
$this->maxDepth = $maxDepth['maxDepth'] ?? null;
if (\is_array($maxDepth)) { // @phpstan-ignore-line
$this->maxDepth = $maxDepth['maxDepth'] ?? null; // @phpstan-ignore-line

return;
}

$this->maxDepth = $maxDepth;
}
}
7 changes: 2 additions & 5 deletions src/Bridge/Doctrine/MongoDbOdm/CollectionDataProvider.php
Expand Up @@ -61,11 +61,8 @@ public function getCollection(string $resourceClass, string $operationName = nul
/** @var DocumentManager $manager */
$manager = $this->managerRegistry->getManagerForClass($resourceClass);

/** @var DocumentRepository $repository */
$repository = $manager->getRepository($resourceClass);
if (!$repository instanceof DocumentRepository) {
throw new RuntimeException(sprintf('The repository for "%s" must be an instance of "%s".', $resourceClass, DocumentRepository::class));
}

$aggregationBuilder = $repository->createAggregationBuilder();
foreach ($this->collectionExtensions as $extension) {
$extension->applyToCollection($aggregationBuilder, $resourceClass, $operationName, $context);
Expand All @@ -79,6 +76,6 @@ public function getCollection(string $resourceClass, string $operationName = nul
$attribute = $resourceMetadata->getCollectionOperationAttribute($operationName, 'doctrine_mongodb', [], true);
$executeOptions = $attribute['execute_options'] ?? [];

return $aggregationBuilder->hydrate($resourceClass)->execute($executeOptions);
return $aggregationBuilder->hydrate($resourceClass)->getAggregation($executeOptions)->getIterator();
}
}
Expand Up @@ -68,11 +68,10 @@ public function applyToCollection(Builder $aggregationBuilder, string $resourceC
throw new RuntimeException(sprintf('The manager for "%s" must be an instance of "%s".', $resourceClass, DocumentManager::class));
}

/**
* @var DocumentRepository
*/
$repository = $manager->getRepository($resourceClass);
if (!$repository instanceof DocumentRepository) {
throw new RuntimeException(sprintf('The repository for "%s" must be an instance of "%s".', $resourceClass, DocumentRepository::class));
}

$resultsAggregationBuilder = $repository->createAggregationBuilder()->skip($offset);
if ($limit > 0) {
$resultsAggregationBuilder->limit($limit);
Expand Down
2 changes: 1 addition & 1 deletion tests/Behat/ElasticsearchContext.php
Expand Up @@ -120,7 +120,7 @@ private function loadFixtures(): void
$bulk = [];

foreach (json_decode($file->getContents(), true) as $document) {
if (null === $document['id'] ?? null) {
if (null === $document['id']) {
$bulk[] = ['index' => ['_index' => $index, '_type' => DocumentMetadata::DEFAULT_TYPE]];
} else {
$bulk[] = ['create' => ['_index' => $index, '_type' => DocumentMetadata::DEFAULT_TYPE, '_id' => (string) $document['id']]];
Expand Down
Expand Up @@ -81,65 +81,5 @@ class DoctrineDummy
*/
protected $binUuidRfc4122;

/**
* @Field(type="timestamp")
*/
private $timestamp;

/**
* @Field(type="date")
*/
private $date;

/**
* @Field(type="float")
*/
private $float;

/**
* @Field(type="bool")
*/
private $bool;

/**
* @Field(type="custom_foo")
*/
private $customFoo;

/**
* @Field(type="int")
*/
private $int;

/**
* @Field(type="string")
*/
private $string;

/**
* @Field(type="key")
*/
private $key;

/**
* @Field(type="hash")
*/
private $hash;

/**
* @Field(type="collection")
*/
private $collection;

/**
* @Field(type="object_id")
*/
private $objectId;

/**
* @Field(type="raw")
*/
private $raw;

public $notMapped;
}
4 changes: 2 additions & 2 deletions tests/Bridge/Elasticsearch/DataProvider/PaginatorTest.php
Expand Up @@ -126,7 +126,7 @@ public function testGetTotalItemsForElasticSearch7()
'relation' => 'eq',
];

$paginator = $this->getPaginator(static::LIMIT, static::OFFSET, $documents);
$paginator = $this->getPaginator(self::LIMIT, self::OFFSET, $documents);

self::assertSame(8., $paginator->getTotalItems());
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public function testGetIterator()
function (array $document): Foo {
return $this->denormalizeFoo($document['_source']);
},
static::DOCUMENTS['hits']['hits']
self::DOCUMENTS['hits']['hits']
),
iterator_to_array($this->paginator)
);
Expand Down
12 changes: 8 additions & 4 deletions tests/Bridge/Elasticsearch/Util/FieldDatatypeTraitTest.php
Expand Up @@ -40,7 +40,8 @@ public function testGetNestedFieldPathWithPropertyNotFound()
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willThrow(new PropertyNotFoundException())->shouldBeCalled();

$fieldDatatype = static::createFieldDatatypeInstance($propertyMetadataFactoryProphecy->reveal(), $this->prophesize(ResourceClassResolverInterface::class)->reveal());
$fieldDatatype = self::createFieldDatatypeInstance($propertyMetadataFactoryProphecy->reveal(), $this->prophesize
(ResourceClassResolverInterface::class)->reveal());

self::assertNull($fieldDatatype->getNestedFieldPath(Foo::class, 'foo.bar'));
}
Expand All @@ -50,7 +51,8 @@ public function testGetNestedFieldPathWithPropertyWithoutType()
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn(new PropertyMetadata())->shouldBeCalled();

$fieldDatatype = static::createFieldDatatypeInstance($propertyMetadataFactoryProphecy->reveal(), $this->prophesize(ResourceClassResolverInterface::class)->reveal());
$fieldDatatype = self::createFieldDatatypeInstance($propertyMetadataFactoryProphecy->reveal(),
$this->prophesize(ResourceClassResolverInterface::class)->reveal());

self::assertNull($fieldDatatype->getNestedFieldPath(Foo::class, 'foo.bar'));
}
Expand All @@ -60,7 +62,8 @@ public function testGetNestedFieldPathWithInvalidCollectionType()
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn(new PropertyMetadata(new Type(Type::BUILTIN_TYPE_STRING)))->shouldBeCalled();

$fieldDatatype = static::createFieldDatatypeInstance($propertyMetadataFactoryProphecy->reveal(), $this->prophesize(ResourceClassResolverInterface::class)->reveal());
$fieldDatatype = self::createFieldDatatypeInstance($propertyMetadataFactoryProphecy->reveal(),
$this->prophesize(ResourceClassResolverInterface::class)->reveal());

self::assertNull($fieldDatatype->getNestedFieldPath(Foo::class, 'foo.bar'));
}
Expand All @@ -85,7 +88,8 @@ private function getValidFieldDatatype()
$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
$resourceClassResolverProphecy->isResourceClass(Foo::class)->willReturn(true)->shouldBeCalled();

return static::createFieldDatatypeInstance($propertyMetadataFactoryProphecy->reveal(), $resourceClassResolverProphecy->reveal());
return self::createFieldDatatypeInstance($propertyMetadataFactoryProphecy->reveal(),
$resourceClassResolverProphecy->reveal());
}

private static function createFieldDatatypeInstance(PropertyMetadataFactoryInterface $propertyMetadataFactory, ResourceClassResolverInterface $resourceClassResolver)
Expand Down
Expand Up @@ -294,7 +294,7 @@ public function testEnableNelmioApiDoc()
$containerBuilderProphecy = $this->getBaseContainerBuilderProphecy();
$containerBuilderProphecy->getParameter('kernel.bundles')->willReturn([
'DoctrineBundle' => DoctrineBundle::class,
'NelmioApiDocBundle' => NelmioApiDocBundle::class, // @phpstan-ignore-line
'NelmioApiDocBundle' => NelmioApiDocBundle::class,
])->shouldBeCalled();
$containerBuilderProphecy->setDefinition('api_platform.nelmio_api_doc.annotations_provider', Argument::type(Definition::class))->shouldBeCalled();
$containerBuilderProphecy->setDefinition('api_platform.nelmio_api_doc.parser', Argument::type(Definition::class))->shouldBeCalled();
Expand Down Expand Up @@ -1113,7 +1113,7 @@ private function getBaseContainerBuilderProphecy(

private function getBaseContainerBuilderProphecyWithoutDefaultMetadataLoading(array $doctrineIntegrationsToLoad = ['orm'], $configuration = null)
{
$hasSwagger = null === $configuration || true === $configuration['api_platform']['enable_swagger'] ?? false;
$hasSwagger = null === $configuration || true === $configuration['api_platform']['enable_swagger'];
$hasHydra = null === $configuration || isset($configuration['api_platform']['formats']['jsonld']);

$containerBuilderProphecy = $this->getPartialContainerBuilderProphecy($configuration);
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/DummyObjectWithConstructor.php
Expand Up @@ -18,8 +18,8 @@
*/
class DummyObjectWithConstructor
{
private $foo;
private $bar;
private $foo; // @phpstan-ignore-line
private $bar; // @phpstan-ignore-line

public function __construct(string $foo, \stdClass $bar)
{
Expand Down
1 change: 0 additions & 1 deletion tests/Fixtures/DummyObjectWithOnlyPrivateProperty.php
Expand Up @@ -15,5 +15,4 @@

class DummyObjectWithOnlyPrivateProperty
{
private $foo;
}
1 change: 0 additions & 1 deletion tests/Fixtures/DummyObjectWithPublicAndPrivateProperty.php
Expand Up @@ -16,5 +16,4 @@
class DummyObjectWithPublicAndPrivateProperty
{
public $foo;
private $bar;
}
2 changes: 2 additions & 0 deletions tests/Fixtures/TestBundle/Entity/Answer.php
Expand Up @@ -51,6 +51,8 @@ class Answer
private $question;

/**
* @var Collection&iterable<Question>
*
* @ORM\OneToMany(targetEntity="Question", mappedBy="answer")
* @Serializer\Groups({"foobar"})
* @ApiSubresource
Expand Down
1 change: 0 additions & 1 deletion tests/Fixtures/TestBundle/Entity/Content.php
Expand Up @@ -41,7 +41,6 @@ class Content implements \JsonSerializable
private $id;

/**
* @var string|null
*
* @ORM\Column(type="string")
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/TestBundle/Entity/ConvertedBoolean.php
Expand Up @@ -26,7 +26,7 @@
class ConvertedBoolean
{
/**
* @var int
* @var int|null
*
* @ORM\Column(type="integer", nullable=true)
* @ORM\Id
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/TestBundle/Entity/ConvertedDate.php
Expand Up @@ -26,7 +26,7 @@
class ConvertedDate
{
/**
* @var int
* @var int|null
*
* @ORM\Column(type="integer", nullable=true)
* @ORM\Id
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/TestBundle/Entity/ConvertedInteger.php
Expand Up @@ -30,7 +30,7 @@
class ConvertedInteger
{
/**
* @var int
* @var int|null
*
* @ORM\Column(type="integer", nullable=true)
* @ORM\Id
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/TestBundle/Entity/ConvertedOwner.php
Expand Up @@ -26,7 +26,7 @@
class ConvertedOwner
{
/**
* @var int
* @var int|null
*
* @ORM\Column(type="integer", nullable=true)
* @ORM\Id
Expand All @@ -35,7 +35,7 @@ class ConvertedOwner
private $id;

/**
* @var ConvertedRelated
* @var ConvertedRelated|null
*
* @ORM\ManyToOne(targetEntity="ConvertedRelated")
*/
Expand Down

0 comments on commit f30749e

Please sign in to comment.