Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Doctrine\ODM\MongoDB\Aggregation\Builder;
use Doctrine\ODM\MongoDB\Aggregation\Stage\Sort;
use Doctrine\Persistence\ManagerRegistry;
use OutOfRangeException;

/**
* Applies selected ordering while querying resource collection.
Expand Down Expand Up @@ -110,7 +109,7 @@ private function hasSortStage(Builder $aggregationBuilder): bool
// If at least one stage is sort, then it has sorting
return true;
}
} catch (OutOfRangeException $outOfRangeException) {
} catch (\OutOfRangeException $outOfRangeException) {
// There is no more stages on the aggregation builder
$shouldStop = true;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Core/Upgrade/UpgradeApiSubresourceVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use ApiPlatform\Metadata\Link;
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
use ReflectionClass;

final class UpgradeApiSubresourceVisitor extends NodeVisitorAbstract
{
Expand Down Expand Up @@ -175,7 +174,7 @@ public function enterNode(Node $node)
];

if (null !== $this->referenceType) {
$urlGeneratorInterface = new ReflectionClass(UrlGeneratorInterface::class);
$urlGeneratorInterface = new \ReflectionClass(UrlGeneratorInterface::class);
$urlGeneratorConstants = array_flip($urlGeneratorInterface->getConstants());
$currentUrlGeneratorConstant = $urlGeneratorConstants[$this->referenceType];

Expand Down
3 changes: 1 addition & 2 deletions src/Doctrine/Odm/Extension/OrderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Doctrine\ODM\MongoDB\Aggregation\Builder;
use Doctrine\ODM\MongoDB\Aggregation\Stage\Sort;
use Doctrine\Persistence\ManagerRegistry;
use OutOfRangeException;

/**
* Applies selected ordering while querying resource collection.
Expand Down Expand Up @@ -101,7 +100,7 @@ private function hasSortStage(Builder $aggregationBuilder): bool
// If at least one stage is sort, then it has sorting
return true;
}
} catch (OutOfRangeException $outOfRangeException) {
} catch (\OutOfRangeException $outOfRangeException) {
// There is no more stages on the aggregation builder
$shouldStop = true;
}
Expand Down
17 changes: 8 additions & 9 deletions src/Metadata/Extractor/ResourceExtractorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace ApiPlatform\Metadata\Extractor;

use ApiPlatform\Exception\InvalidArgumentException;
use SimpleXMLElement;
use Symfony\Component\Config\Util\XmlUtils;

/**
Expand All @@ -25,14 +24,14 @@
trait ResourceExtractorTrait
{
/**
* @param array|SimpleXMLElement|null $resource
* @param mixed|null $default
* @param array|\SimpleXMLElement|null $resource
* @param mixed|null $default
*
* @return array|null
*/
private function buildArrayValue($resource, string $key, $default = null)
{
if (\is_object($resource) && $resource instanceof SimpleXMLElement) {
if (\is_object($resource) && $resource instanceof \SimpleXMLElement) {
if (!isset($resource->{$key.'s'}->{$key})) {
return $default;
}
Expand All @@ -54,8 +53,8 @@ private function buildArrayValue($resource, string $key, $default = null)
/**
* Transforms an attribute's value in a PHP value.
*
* @param array|SimpleXMLElement|null $resource
* @param mixed|null $default
* @param array|\SimpleXMLElement|null $resource
* @param mixed|null $default
*
* @return string|int|bool|array|null
*/
Expand All @@ -73,7 +72,7 @@ private function phpize($resource, string $key, string $type, $default = null)
case 'integer':
return (int) $resource[$key];
case 'bool':
if (\is_object($resource) && $resource instanceof SimpleXMLElement) {
if (\is_object($resource) && $resource instanceof \SimpleXMLElement) {
return (bool) XmlUtils::phpize($resource[$key]);
}

Expand All @@ -83,7 +82,7 @@ private function phpize($resource, string $key, string $type, $default = null)
throw new InvalidArgumentException(sprintf('The property "%s" must be a "%s", "%s" given.', $key, $type, \gettype($resource[$key])));
}

private function buildArgs(SimpleXMLElement $resource): ?array
private function buildArgs(\SimpleXMLElement $resource): ?array
{
if (!isset($resource->args->arg)) {
return null;
Expand All @@ -97,7 +96,7 @@ private function buildArgs(SimpleXMLElement $resource): ?array
return $data;
}

private function buildValues(SimpleXMLElement $resource): array
private function buildValues(\SimpleXMLElement $resource): array
{
$data = [];
foreach ($resource->value as $value) {
Expand Down
4 changes: 1 addition & 3 deletions src/Metadata/Operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace ApiPlatform\Metadata;

use RuntimeException;

final class Operations implements \IteratorAggregate, \Countable
{
private $operations;
Expand Down Expand Up @@ -71,7 +69,7 @@ public function remove(string $key): self
}
}

throw new RuntimeException(sprintf('Could not remove operation "%s".', $key));
throw new \RuntimeException(sprintf('Could not remove operation "%s".', $key));
}

public function has(string $key): bool
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Routing/SkolemIriConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use ApiPlatform\Api\UrlGeneratorInterface;
use ApiPlatform\Exception\ItemNotFoundException;
use ApiPlatform\Metadata\Operation;
use SplObjectStorage;
use Symfony\Component\Routing\RouterInterface;

/**
Expand All @@ -36,7 +35,7 @@ final class SkolemIriConverter implements IriConverterInterface
public function __construct(RouterInterface $router)
{
$this->router = $router;
$this->objectHashMap = new SplObjectStorage();
$this->objectHashMap = new \SplObjectStorage();
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Test/DoctrineMongoDbOdmTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

use function sys_get_temp_dir;

/**
* Source: https://github.com/doctrine/DoctrineMongoDBBundle/blob/0174003844bc566bb4cb3b7d10c5528d1924d719/Tests/TestCase.php
* Test got excluded from vendor in 4.x.
Expand Down
43 changes: 21 additions & 22 deletions tests/Action/ExceptionActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use ApiPlatform\Metadata\Operations;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
use DomainException;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
Expand Down Expand Up @@ -82,7 +81,7 @@ public function testLegacyActionWithOperationExceptionToStatus(
) {
$this->expectDeprecation('Since api-platform/core 2.7: Use "ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface" instead of "ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface".');

$exception = new DomainException();
$exception = new \DomainException();
$flattenException = FlattenException::create($exception);

$serializer = $this->prophesize(SerializerInterface::class);
Expand Down Expand Up @@ -135,7 +134,7 @@ public function testActionWithOperationExceptionToStatus(
?array $operationExceptionToStatus,
int $expectedStatusCode
) {
$exception = new DomainException();
$exception = new \DomainException();
$flattenException = FlattenException::create($exception);

$serializer = $this->prophesize(SerializerInterface::class);
Expand Down Expand Up @@ -196,86 +195,86 @@ public function provideOperationExceptionToStatusCases()
];

yield 'on global attributes' => [
[DomainException::class => 100],
[\DomainException::class => 100],
null,
null,
100,
];

yield 'on global attributes with empty resource and operation attributes' => [
[DomainException::class => 100],
[\DomainException::class => 100],
[],
[],
100,
];

yield 'on global attributes and resource attributes' => [
[DomainException::class => 100],
[DomainException::class => 200],
[\DomainException::class => 100],
[\DomainException::class => 200],
null,
200,
];

yield 'on global attributes and resource attributes with empty operation attributes' => [
[DomainException::class => 100],
[DomainException::class => 200],
[\DomainException::class => 100],
[\DomainException::class => 200],
[],
200,
];

yield 'on global attributes and operation attributes' => [
[DomainException::class => 100],
[\DomainException::class => 100],
null,
[DomainException::class => 300],
[\DomainException::class => 300],
300,
];

yield 'on global attributes and operation attributes with empty resource attributes' => [
[DomainException::class => 100],
[\DomainException::class => 100],
[],
[DomainException::class => 300],
[\DomainException::class => 300],
300,
];

yield 'on global, resource and operation attributes' => [
[DomainException::class => 100],
[DomainException::class => 200],
[DomainException::class => 300],
[\DomainException::class => 100],
[\DomainException::class => 200],
[\DomainException::class => 300],
300,
];

yield 'on resource attributes' => [
[],
[DomainException::class => 200],
[\DomainException::class => 200],
null,
200,
];

yield 'on resource attributes with empty operation attributes' => [
[],
[DomainException::class => 200],
[\DomainException::class => 200],
[],
200,
];

yield 'on resource and operation attributes' => [
[],
[DomainException::class => 200],
[DomainException::class => 300],
[\DomainException::class => 200],
[\DomainException::class => 300],
300,
];

yield 'on operation attributes' => [
[],
null,
[DomainException::class => 300],
[\DomainException::class => 300],
300,
];

yield 'on operation attributes with empty resource attributes' => [
[],
[],
[DomainException::class => 300],
[\DomainException::class => 300],
300,
];
}
Expand Down
3 changes: 1 addition & 2 deletions tests/Core/Metadata/Extractor/YamlExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use ApiPlatform\Core\Metadata\Extractor\YamlExtractor;
use ApiPlatform\Exception\InvalidArgumentException;
use Generator;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
Expand Down Expand Up @@ -56,7 +55,7 @@ public function testInvalidResources(string $path, string $exceptionRegex)
}
}

public function provideInvalidResources(): Generator
public function provideInvalidResources(): \Generator
{
yield [
__DIR__.'/../../../Fixtures/FileConfigurations/resourcesinvalid.yml',
Expand Down
11 changes: 5 additions & 6 deletions tests/Doctrine/Odm/Extension/OrderExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\Persistence\ManagerRegistry;
use OutOfRangeException;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -39,7 +38,7 @@ public function testApplyToCollectionWithValidOrder(): void
{
$aggregationBuilderProphecy = $this->prophesize(Builder::class);

$aggregationBuilderProphecy->getStage(0)->willThrow(new OutOfRangeException('message'));
$aggregationBuilderProphecy->getStage(0)->willThrow(new \OutOfRangeException('message'));
$aggregationBuilderProphecy->sort(['name' => 'asc'])->shouldBeCalled();

$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
Expand All @@ -60,7 +59,7 @@ public function testApplyToCollectionWithWrongOrder(): void
{
$aggregationBuilderProphecy = $this->prophesize(Builder::class);

$aggregationBuilderProphecy->getStage(0)->willThrow(new OutOfRangeException('message'));
$aggregationBuilderProphecy->getStage(0)->willThrow(new \OutOfRangeException('message'));
$aggregationBuilderProphecy->sort(['name' => 'asc'])->shouldNotBeCalled();

$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
Expand All @@ -81,7 +80,7 @@ public function testApplyToCollectionWithOrderOverridden(): void
{
$aggregationBuilderProphecy = $this->prophesize(Builder::class);

$aggregationBuilderProphecy->getStage(0)->willThrow(new OutOfRangeException('message'));
$aggregationBuilderProphecy->getStage(0)->willThrow(new \OutOfRangeException('message'));
$aggregationBuilderProphecy->sort(['foo' => 'DESC'])->shouldBeCalled();

$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
Expand All @@ -102,7 +101,7 @@ public function testApplyToCollectionWithOrderOverriddenWithNoDirection(): void
{
$aggregationBuilderProphecy = $this->prophesize(Builder::class);

$aggregationBuilderProphecy->getStage(0)->willThrow(new OutOfRangeException('message'));
$aggregationBuilderProphecy->getStage(0)->willThrow(new \OutOfRangeException('message'));
$aggregationBuilderProphecy->sort(['foo' => 'ASC'])->shouldBeCalled();
$aggregationBuilderProphecy->sort(['foo' => 'ASC', 'bar' => 'DESC'])->shouldBeCalled();

Expand Down Expand Up @@ -130,7 +129,7 @@ public function testApplyToCollectionWithOrderOverriddenWithAssociation(): void
$lookupProphecy->alias('author_lkup')->shouldBeCalled();
$aggregationBuilderProphecy->lookup(Dummy::class)->shouldBeCalled()->willReturn($lookupProphecy->reveal());
$aggregationBuilderProphecy->unwind('$author_lkup')->shouldBeCalled();
$aggregationBuilderProphecy->getStage(0)->willThrow(new OutOfRangeException('message'));
$aggregationBuilderProphecy->getStage(0)->willThrow(new \OutOfRangeException('message'));
$aggregationBuilderProphecy->sort(['author_lkup.name' => 'ASC'])->shouldBeCalled();

$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
Expand Down
Loading