Skip to content

Commit

Permalink
fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Aug 3, 2021
1 parent 14059e8 commit db8f3bf
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 28 deletions.
7 changes: 6 additions & 1 deletion phpstan.neon.dist
Expand Up @@ -41,9 +41,14 @@ parameters:
earlyTerminatingMethodCalls:
PHPUnit\Framework\Constraint\Constraint:
- fail
ApiPlatform\Metadata\Resource\ResourceMetadataCollection:
- handleNotFound
ignoreErrors:
# False positives
- '#Parameter \#1 \$callback of function call_user_func expects callable\(\): mixed, non-empty-string given\.#'
-
message: '#Unreachable statement - code above always terminates.#'
paths:
- tests/GraphQl/Resolver/Stage/SecurityPostDenormalizeStageTest.php
-
message: '#Strict comparison using !== between .+ and .+ will always evaluate to false\.#'
paths:
Expand Down
9 changes: 7 additions & 2 deletions src/Core/Bridge/Doctrine/MongoDbOdm/Filter/SearchFilter.php
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Core\Api\IdentifiersExtractorInterface;
use ApiPlatform\Core\Api\IriConverterInterface as LegacyIriConverterInterface;
use ApiPlatform\Core\Bridge\Doctrine\Common\Filter\SearchFilterInterface;
use ApiPlatform\Core\Bridge\Doctrine\Common\Filter\SearchFilterTrait;
use ApiPlatform\Core\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -43,16 +44,20 @@ final class SearchFilter extends AbstractFilter implements SearchFilterInterface

public const DOCTRINE_INTEGER_TYPE = [MongoDbType::INTEGER, MongoDbType::INT];

public function __construct(ManagerRegistry $managerRegistry, IriConverterInterface $iriConverter, IdentifiersExtractorInterface $identifiersExtractor, PropertyAccessorInterface $propertyAccessor = null, LoggerInterface $logger = null, array $properties = null, NameConverterInterface $nameConverter = null)
public function __construct(ManagerRegistry $managerRegistry, $iriConverter, IdentifiersExtractorInterface $identifiersExtractor, PropertyAccessorInterface $propertyAccessor = null, LoggerInterface $logger = null, array $properties = null, NameConverterInterface $nameConverter = null)
{
parent::__construct($managerRegistry, $logger, $properties, $nameConverter);

if ($iriConverter instanceof LegacyIriConverterInterface) {
trigger_deprecation('api-platform/core', '2.7', sprintf('Use an implementation of "%s" instead of "%s".', IriConverterInterface::class, LegacyIriConverterInterface::class));
}

$this->iriConverter = $iriConverter;
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
$this->identifiersExtractor = $identifiersExtractor;
}

protected function getIriConverter(): IriConverterInterface
protected function getIriConverter()
{
return $this->iriConverter;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Bridge/Symfony/Routing/ApiLoader.php
Expand Up @@ -66,8 +66,9 @@ public function __construct(KernelInterface $kernel, ResourceNameCollectionFacto
$paths = $kernel->locateResource('@ApiPlatformBundle/Resources/config/routing');
$this->fileLoader = new XmlFileLoader(new FileLocator($paths));
$this->resourceNameCollectionFactory = $resourceNameCollectionFactory;

if ($resourceMetadataFactory instanceof ResourceMetadataFactoryInterface) {
trigger_deprecation('api-platform/core', '2.7', sprintf('Use "%s" instead of "%s".', ResourceMetadataCollectionFactoryInterface::class, null === $resourceMetadataFactory ? 'null' : ResourceMetadataFactoryInterface::class));
trigger_deprecation('api-platform/core', '2.7', sprintf('Use "%s" instead of "%s".', ResourceMetadataCollectionFactoryInterface::class, ResourceMetadataFactoryInterface::class));
}
$this->resourceMetadataFactory = $resourceMetadataFactory;
$this->operationPathResolver = $operationPathResolver;
Expand Down
1 change: 0 additions & 1 deletion src/Core/Filter/Validator/ArrayItems.php
Expand Up @@ -62,7 +62,6 @@ private function getValue(string $name, array $filterDescription, array $queryPa

$collectionFormat = $filterDescription['swagger']['collectionFormat'] ?? 'csv';

/* @phpstan-ignore-next-line */
return explode(self::getSeparator($collectionFormat), $value) ?: [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Operation.php
Expand Up @@ -193,7 +193,7 @@ public function __construct(
?bool $stateless = null,
?string $sunset = null,
?string $acceptPatch = null,
?int $status = null,
$status = null,
string $host = '',
array $schemes = [],
string $condition = '',
Expand Down
2 changes: 0 additions & 2 deletions src/Metadata/Operations.php
Expand Up @@ -15,8 +15,6 @@

/**
* @internal
*
* @extends array<string, Operation>
*/
final class Operations implements \IteratorAggregate, \Countable
{
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/WithResourceTrait.php
Expand Up @@ -13,6 +13,8 @@

namespace ApiPlatform\Metadata;

use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;

trait WithResourceTrait
{
public function withResource(ApiResource $resource): self
Expand Down
2 changes: 1 addition & 1 deletion tests/Bridge/Doctrine/Orm/Filter/SearchFilterTest.php
Expand Up @@ -13,8 +13,8 @@

namespace ApiPlatform\Core\Tests\Bridge\Doctrine\Orm\Filter;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Core\Api\IdentifiersExtractorInterface;
use ApiPlatform\Core\Api\IriConverterInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator;
use ApiPlatform\Core\Exception\InvalidArgumentException;
Expand Down
1 change: 1 addition & 0 deletions tests/Bridge/Symfony/Routing/ApiLoaderTest.php
Expand Up @@ -26,6 +26,7 @@
use ApiPlatform\Core\PathResolver\OperationPathResolver;
use ApiPlatform\Core\Tests\Fixtures\DummyEntity;
use ApiPlatform\Core\Tests\Fixtures\RelatedDummyEntity;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
use ApiPlatform\Core\Tests\ProphecyTrait;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
Expand Down
6 changes: 3 additions & 3 deletions tests/Core/Metadata/AttributeTraitTest.php
Expand Up @@ -14,7 +14,7 @@
namespace ApiPlatform\Core\Tests\Core\Metadata;

use ApiPlatform\Core\Tests\ProphecyTrait;
use ApiPlatform\Metadata\Resource;
use ApiPlatform\Metadata\ApiResource;
use PHPUnit\Framework\TestCase;

class AttributeTraitTest extends TestCase
Expand All @@ -27,7 +27,7 @@ class AttributeTraitTest extends TestCase
public function testExtraProperties()
{
/** @var \stdClass */
$resource = new Resource();
$resource = new ApiResource();
$resource->foo = 'bar';
$this->assertEquals(['foo' => 'bar'], $resource->extraProperties);
$this->assertEquals($resource->foo, 'bar');
Expand All @@ -39,7 +39,7 @@ public function testExtraProperties()
public function testNamedArguments()
{
/** @var \stdClass */
$resource = new Resource(types: ['Resource'], foo: 'bar');
$resource = new ApiResource(types: ['Resource'], foo: 'bar'); // @phpstan-ignore-line
$this->assertEquals($resource->types, ['Resource']);
$this->assertEquals($resource->foo, 'bar');
$this->assertEquals(['foo' => 'bar'], $resource->extraProperties);
Expand Down
26 changes: 13 additions & 13 deletions tests/Core/State/ChainProviderTest.php
Expand Up @@ -28,20 +28,20 @@ class ChainProviderTest extends TestCase
public function testChainProvider()
{
$a = $this->prophesize(ProviderInterface::class);
$a->supports('class', [], [])->willReturn(false);
$a->provide('class', [], [])->shouldNotBeCalled();
$a->supports('class', [], 'operationName', [])->willReturn(false);
$a->provide('class', [], 'operationName', [])->shouldNotBeCalled();

$b = $this->prophesize(ProviderInterface::class);
$b->supports('class', [], [])->willReturn(true);
$b->provide('class', [], [])->willReturn('value');
$b->supports('class', [], 'operationName', [])->willReturn(true);
$b->provide('class', [], 'operationName', [])->willReturn('value');

$chainProvider = new ChainProvider([
$a->reveal(),
$b->reveal(),
]);

$this->assertEquals('value', $chainProvider->provide('class', [], []));
$this->assertTrue($chainProvider->supports('class', [], []));
$this->assertEquals('value', $chainProvider->provide('class', [], 'operationName', []));
$this->assertTrue($chainProvider->supports('class', [], 'operationName', []));
}

/**
Expand All @@ -50,17 +50,17 @@ public function testChainProvider()
public function testReturnValueWhenNoProvider()
{
$a = $this->prophesize(ProviderInterface::class);
$a->supports('class', ['id' => 1], [])->willReturn(false);
$a->supports('class', [], [])->willReturn(false);
$a->provide('class', ['id' => 1], [])->shouldNotBeCalled();
$a->provide('class', [], [])->shouldNotBeCalled();
$a->supports('class', ['id' => 1], 'operationName', [])->willReturn(false);
$a->supports('class', [], 'operationName', [])->willReturn(false);
$a->provide('class', ['id' => 1], 'operationName', [])->shouldNotBeCalled();
$a->provide('class', [], 'operationName', [])->shouldNotBeCalled();

$chainProvider = new ChainProvider([
$a->reveal(),
]);

$this->assertNull($chainProvider->provide('class', ['id' => 1], []));
$this->assertEquals([], $chainProvider->provide('class', [], []));
$this->assertFalse($chainProvider->supports('class', [], []));
$this->assertNull($chainProvider->provide('class', ['id' => 1], 'operationName', []));
$this->assertEquals([], $chainProvider->provide('class', [], 'operationName', []));
$this->assertFalse($chainProvider->supports('class', [], 'operationName', []));
}
}
2 changes: 0 additions & 2 deletions tests/Fixtures/app/bootstrap.php
Expand Up @@ -11,7 +11,6 @@

declare(strict_types=1);

use ApiPlatform\Core\Tests\DeprecationErrorHandler;
use Doctrine\Common\Annotations\AnnotationRegistry;

date_default_timezone_set('UTC');
Expand All @@ -30,6 +29,5 @@
require __DIR__.'/AppKernel.php';

AnnotationRegistry::registerLoader('class_exists');
DeprecationErrorHandler::register();

return $loader;
2 changes: 1 addition & 1 deletion tests/Hydra/Serializer/EntrypointNormalizerTest.php
Expand Up @@ -41,7 +41,7 @@ public function testSupportNormalization()
$collection = new ResourceNameCollection();
$entrypoint = new Entrypoint($collection);

$factoryProphecy = $this->prophesize(ResourceCollectionMetadataFactoryInterface::class);
$factoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class);
$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
$urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class);

Expand Down

0 comments on commit db8f3bf

Please sign in to comment.