Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,45 @@ jobs:
- name: Run PHP-CS-Fixer fix
run: php-cs-fixer fix --dry-run --diff --ansi --show-progress=none

rector:
name: Rector (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
php:
- '8.3'
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: intl, bcmath, curl, openssl, mbstring, mongodb
ini-values: memory_limit=-1
tools: composer
coverage: none
- name: Get composer cache directory
id: composercache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v5
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Update project dependencies
run: |
composer global require soyuka/pmu
composer global config allow-plugins.soyuka/pmu true --no-interaction
composer global link .
- name: Install Rector
run: composer require --dev rector/rector
- name: Run Rector
run: ./vendor/bin/rector process --dry-run --ansi --no-progress-bar

lint-container:
name: Lint Container
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"psr/log": "^1.0 || ^2.0 || ^3.0",
"ramsey/uuid": "^4.7",
"ramsey/uuid-doctrine": "^2.0",
"rector/rector": "^2.3",
"soyuka/contexts": "^3.3.10",
"soyuka/pmu": "^0.2.0",
"soyuka/stubs-mongodb": "^1.0",
Expand Down
5 changes: 4 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ parameters:
paths:
- tests/Fixtures/TestBundle/Document/
- src/Metadata/Tests/Fixtures/ApiResource/
- tests/Fixtures/TestBundle/Entity/FooEmbeddable.php
- '#Access to an undefined property Prophecy\\Prophecy\\ObjectProphecy<(\\?[a-zA-Z0-9_]+)+>::\$[a-zA-Z0-9_]+#'
# https://github.com/phpstan/phpstan-symfony/issues/76
-
message: '#Service "test" is not registered in the container\.#'
path: src/GraphQl/Tests/Type/TypesContainerTest.php

-
message: '#Constant.*is unused\.#'
path: src/HttpCache/SouinPurger.php
# Expected, due to backward compatibility
- '#Method GraphQL\\Type\\Definition\\WrappingType::getWrappedType\(\) invoked with 1 parameter, 0 required\.#'
- '#Access to an undefined property GraphQL\\Type\\Definition\\NamedType&GraphQL\\Type\\Definition\\Type::\$name\.#'
Expand Down
49 changes: 49 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodParameterRector;

return RectorConfig::configure()
->withPaths([
__DIR__.'/src',
__DIR__.'/tests',
])
->withSkip([
__DIR__.'/src/Core/Bridge/Symfony/Maker/Resources/skeleton',
__DIR__.'/src/Laravel/Console/Maker/Resources/skeleton',
__DIR__.'/src/Laravel/config',
__DIR__.'/tests/Fixtures/app/var',
__DIR__.'/docs/guides',
__DIR__.'/docs/var',
__DIR__.'/src/Doctrine/Orm/Tests/var',
__DIR__.'/src/Doctrine/Odm/Tests/var',
__DIR__.'/tests/Fixtures/app/config/reference.php',
__DIR__.'/src/Symfony/Bundle/DependencyInjection/Configuration.php',
__DIR__.'/tests/Fixer/SymfonyServiceClassConstantFixer.php',
RemoveUnusedPromotedPropertyRector::class => [
__DIR__.'/tests/Fixtures/TestBundle/Filter/SearchTextAndDateFilter.php',
__DIR__.'/tests/Fixtures/TestBundle/Filter/ODMSearchTextAndDateFilter.php',
],
RemoveUnusedPublicMethodParameterRector::class => [
__DIR__.'/src/GraphQl/Action/GraphiQlAction.php',
],
])
// uncomment to reach your current PHP version
// ->withPhpSets()
->withPreparedSets(
typeDeclarations: true,
deadCode: true,
)
->withCodeQualityLevel(0);
4 changes: 2 additions & 2 deletions src/Doctrine/Common/Filter/BackedEnumFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getDescription(string $resourceClass): array
foreach ($filterParameterNames as $filterParameterName) {
$isCollection = str_ends_with($filterParameterName, '[]');

$enumValues = array_map(static fn (\BackedEnum $case) => $case->value, $this->enumTypes[$property]::cases());
$enumValues = array_map(static fn (\BackedEnum $case): int|string => $case->value, $this->enumTypes[$property]::cases());

$schema = $isCollection
? ['type' => 'array', 'items' => ['type' => 'string', 'enum' => $enumValues]]
Expand Down Expand Up @@ -99,7 +99,7 @@ private function normalizeValue(mixed $value, string $property): mixed
$value = (int) $value;
}

$values = array_map(static fn (\BackedEnum $case) => $case->value, $this->enumTypes[$property]::cases());
$values = array_map(static fn (\BackedEnum $case): int|string => $case->value, $this->enumTypes[$property]::cases());

if (\in_array($value, $values, true)) {
return $value;
Expand Down
3 changes: 0 additions & 3 deletions src/Doctrine/Common/Messenger/DispatchTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ trait DispatchTrait
{
private ?MessageBusInterface $messageBus;

/**
* @param object|Envelope $message
*/
private function dispatch(object $message): Envelope
{
if (!$this->messageBus instanceof MessageBusInterface) {
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/Common/State/LinksHandlerLocatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private function findSimilarMethod(string $className, string $methodName): ?stri
{
$methods = get_class_methods($className);

$similarMethods = array_filter($methods, static function ($method) use ($methodName) {
$similarMethods = array_filter($methods, static function ($method) use ($methodName): bool {
return levenshtein($methodName, $method) <= 3;
});

Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/Common/State/PersistProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private function handleLazyObjectRelations(object $data, DoctrineObjectManager $
$identifiers = $metadata->getIdentifierValues($value);

// Do not get reference for partial objects or objects with null identifiers
if (!$identifiers || \count($identifiers) !== \count(array_filter($identifiers, static fn ($v) => null !== $v))) {
if (!$identifiers || \count($identifiers) !== \count(array_filter($identifiers, static fn ($v): bool => null !== $v))) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/Common/Tests/CollectionPaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class CollectionPaginatorTest extends TestCase
{
#[DataProvider('initializeProvider')]
public function testInitialize($results, $currentPage, $itemsPerPage, $totalItems, $lastPage, $currentItems): void
public function testInitialize(array $results, int $currentPage, int $itemsPerPage, int $totalItems, int $lastPage, int $currentItems): void
{
$results = new ArrayCollection($results);
$paginator = new CollectionPaginator($results, $currentPage, $itemsPerPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function getDummyDate()
return $this->dummyDate;
}

public function setDummyPrice($dummyPrice)
public function setDummyPrice($dummyPrice): static
{
$this->dummyPrice = $dummyPrice;

Expand Down Expand Up @@ -284,10 +284,7 @@ public function isDummyBoolean(): ?bool
return $this->dummyBoolean;
}

/**
* @param bool $dummyBoolean
*/
public function setDummyBoolean($dummyBoolean): void
public function setDummyBoolean(?bool $dummyBoolean): void
{
$this->dummyBoolean = $dummyBoolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ public static function staticMethod(): void
{
}

public function __construct()
{
}

public function getDummyName(): ?string
{
return $this->dummyName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ public function isDummyBoolean(): ?bool
return $this->dummyBoolean;
}

/**
* @param bool $dummyBoolean
*/
public function setDummyBoolean($dummyBoolean): void
public function setDummyBoolean(?bool $dummyBoolean): void
{
$this->dummyBoolean = $dummyBoolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ public function getDescription(): ?string
return $this->description;
}

/**
* @param string|null $description
*/
public function setDescription($description): void
public function setDescription(?string $description): void
{
$this->description = $description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ public function getLevel(): ?int
return $this->level;
}

/**
* @param int $level
*/
public function setLevel($level): void
public function setLevel(int $level): void
{
$this->level = $level;
}
Expand All @@ -74,10 +71,7 @@ public function isTest(): bool
return $this->test;
}

/**
* @param bool $test
*/
public function setTest($test): void
public function setTest(bool $test): void
{
$this->test = $test;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/Common/Tests/SelectablePaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class SelectablePaginatorTest extends TestCase
{
#[DataProvider('initializeProvider')]
public function testInitialize($results, $currentPage, $itemsPerPage, $totalItems, $lastPage, $currentItems): void
public function testInitialize(array $results, int $currentPage, int $itemsPerPage, int $totalItems, int $lastPage, int $currentItems): void
{
$results = new ArrayCollection($results);
$paginator = new SelectablePaginator($results, $currentPage, $itemsPerPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class SelectablePartialPaginatorTest extends TestCase
{
#[DataProvider('initializeProvider')]
public function testInitialize($results, $currentPage, $itemsPerPage, $currentItems): void
public function testInitialize(array $results, int $currentPage, int $itemsPerPage, int $currentItems): void
{
$results = new ArrayCollection($results);
$paginator = new SelectablePartialPaginator($results, $currentPage, $itemsPerPage);
Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/Odm/Extension/PaginationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function applyToCollection(Builder $aggregationBuilder, string $resourceC
return;
}

if (($context['graphql_operation_name'] ?? false) && !$this->pagination->isGraphQlEnabled($operation, $context)) {
if (($context['graphql_operation_name'] ?? false) && !$this->pagination->isGraphQlEnabled($operation)) {
return;
}

Expand Down Expand Up @@ -95,7 +95,7 @@ public function applyToCollection(Builder $aggregationBuilder, string $resourceC
public function supportsResult(string $resourceClass, ?Operation $operation = null, array $context = []): bool
{
if ($context['graphql_operation_name'] ?? false) {
return $this->pagination->isGraphQlEnabled($operation, $context);
return $this->pagination->isGraphQlEnabled($operation);
}

return $this->pagination->isEnabled($operation, $context);
Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/Odm/Tests/Fixtures/Document/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getId(): ?int
return $this->id;
}

public function setId($id): void
public function setId(?int $id): void
{
$this->id = $id;
}
Expand Down Expand Up @@ -167,7 +167,7 @@ public function getDummyDate()
return $this->dummyDate;
}

public function setDummyPrice($dummyPrice)
public function setDummyPrice($dummyPrice): static
{
$this->dummyPrice = $dummyPrice;

Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/Odm/Tests/Fixtures/Document/DummyFriend.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getId(): ?int
*
* @param int $id the value to set
*/
public function setId($id): void
public function setId(?int $id): void
{
$this->id = $id;
}
Expand Down
4 changes: 0 additions & 4 deletions src/Doctrine/Odm/Tests/Fixtures/Document/EmbeddableDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ public static function staticMethod(): void
{
}

public function __construct()
{
}

public function getDummyName(): ?string
{
return $this->dummyName;
Expand Down
5 changes: 1 addition & 4 deletions src/Doctrine/Odm/Tests/Fixtures/Document/RelatedDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ public function isDummyBoolean(): ?bool
return $this->dummyBoolean;
}

/**
* @param bool $dummyBoolean
*/
public function setDummyBoolean($dummyBoolean): void
public function setDummyBoolean(?bool $dummyBoolean): void
{
$this->dummyBoolean = $dummyBoolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ public function getDescription(): ?string
return $this->description;
}

/**
* @param string|null $description
*/
public function setDescription($description): void
public function setDescription(?string $description): void
{
$this->description = $description;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/Orm/Extension/PaginationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGenerator
public function supportsResult(string $resourceClass, ?Operation $operation = null, array $context = []): bool
{
if ($context['graphql_operation_name'] ?? false) {
return $this->pagination->isGraphQlEnabled($operation, $context);
return $this->pagination->isGraphQlEnabled($operation);
}

return $this->pagination->isEnabled($operation, $context);
Expand Down Expand Up @@ -98,7 +98,7 @@ public function getResult(QueryBuilder $queryBuilder, ?string $resourceClass = n
*/
private function getPagination(QueryBuilder $queryBuilder, ?Operation $operation, array $context): ?array
{
$enabled = isset($context['graphql_operation_name']) ? $this->pagination->isGraphQlEnabled($operation, $context) : $this->pagination->isEnabled($operation, $context);
$enabled = isset($context['graphql_operation_name']) ? $this->pagination->isGraphQlEnabled($operation) : $this->pagination->isEnabled($operation, $context);

if (!$enabled) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/Orm/Filter/AbstractUuidFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $q
throw new InvalidArgumentException(\sprintf('The filter parameter with key "%s" must specify a property. Nested properties are not automatically resolved. Please provide the property explicitly.', $parameter->getKey()));
}

$this->filterProperty($parameter->getProperty(), $parameter->getValue(), $queryBuilder, $queryNameGenerator, $resourceClass, $operation, $context);
$this->filterProperty($parameter->getProperty(), $parameter->getValue(), $queryBuilder, $queryNameGenerator, $resourceClass);
}

private function filterProperty(string $property, mixed $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
private function filterProperty(string $property, mixed $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass): void
{
$alias = $queryBuilder->getRootAliases()[0];
$field = $property;
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/Orm/Filter/BackedEnumFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function filterProperty(string $property, mixed $value, QueryBuilder $
$values = \is_array($value) ? $value : [$value];

$normalizedValues = array_filter(array_map(
fn ($v) => $this->normalizeValue($v, $property),
fn ($v): mixed => $this->normalizeValue($v, $property),
$values
));

Expand Down
Loading
Loading