From 96f8dc96446663fdcdb64b42312082dbc2961527 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 6 Apr 2024 17:54:55 +0200 Subject: [PATCH] cs fixer --- .github/workflows/static.yml | 47 +++++++++++++++++++ .gitignore | 3 +- .php-cs-fixer.dist.php | 19 ++++++++ .styleci.yml | 31 ------------ .../CmfRoutingExtension.php | 3 -- src/Doctrine/Orm/ContentRepository.php | 2 - src/Doctrine/Orm/RedirectRoute.php | 9 ---- src/Doctrine/Orm/Route.php | 3 -- src/Doctrine/Orm/RouteProvider.php | 11 +---- src/Doctrine/Phpcr/ContentRepository.php | 6 --- src/Doctrine/Phpcr/PrefixCandidates.php | 7 +-- src/Doctrine/Phpcr/RedirectRoute.php | 12 ----- src/Doctrine/Phpcr/Route.php | 6 --- src/Doctrine/Phpcr/RouteProvider.php | 4 +- src/Form/Type/RouteTypeType.php | 9 ---- src/Model/RedirectRoute.php | 26 +--------- src/Model/Route.php | 9 ---- src/Routing/DynamicRouter.php | 2 +- src/Routing/RedirectableRequestMatcher.php | 2 +- .../Doctrine/Phpcr/RedirectRouteTest.php | 3 +- .../Doctrine/Phpcr/RouteProviderTest.php | 2 +- tests/Functional/Doctrine/Phpcr/RouteTest.php | 2 +- .../Functional/Routing/DynamicRouterTest.php | 2 +- .../RouteDefaultsTwigValidatorTest.php | 1 - 24 files changed, 79 insertions(+), 142 deletions(-) create mode 100644 .github/workflows/static.yml create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .styleci.yml diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 00000000..1a66ca71 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,47 @@ +name: Static analysis + +on: + push: + branches: + - '[0-9]+.x' + - '[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.x' + pull_request: + +jobs: + phpstan: + name: PHPStan + runs-on: ubuntu-latest + + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + extensions: "curl,dom,json,xml,dom" + coverage: none + + - name: Checkout code + uses: actions/checkout@v4 + + # have to install phpstan ourselves here, the phpstan-ga fails at composer install with weird errors + - name: Install phpstan + run: | +# composer require --no-update jackalope/jackalope-doctrine-dbal jackalope/jackalope-jackrabbit phpstan/phpstan + composer update + + - name: PHPStan + run: vendor/bin/phpstan analyze --no-progress + + php-cs-fixer: + name: PHP-CS-Fixer + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: PHP-CS-Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --dry-run --diff diff --git a/.gitignore b/.gitignore index 6e7a8532..0b4c0b10 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ phpunit.xml composer.lock vendor tests/Fixtures/App/var/ -.phpunit.result.cache +.phpunit.result.cache +.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..a8e3ac3a --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,19 @@ +in(__DIR__.'/src') + ->in(__DIR__.'/tests') + ->exclude('tests/Fixtures/App/var/') + ->name('*.php') +; + +$config = new PhpCsFixer\Config(); + +return $config + ->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + 'single_line_throw' => false, + ]) + ->setFinder($finder) +; diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 793ac737..00000000 --- a/.styleci.yml +++ /dev/null @@ -1,31 +0,0 @@ -####################################################### -# DO NOT EDIT THIS FILE! # -# # -# It's auto-generated by symfony-cmf/dev-kit package. # -####################################################### - -############################################################################ -# This file is part of the Symfony CMF package. # -# # -# (c) Symfony CMF i # -# # -# For the full copyright and license information, please view the LICENSE # -# file that was distributed with this source code. # -############################################################################ - - -preset: symfony - -risky: true - -enabled: - - combine_consecutive_unsets - - no_php4_constructor - - no_useless_else - - ordered_use - - strict - - php_unit_construct - -disabled: - - single_line_class_definition - - single_line_throw diff --git a/src/DependencyInjection/CmfRoutingExtension.php b/src/DependencyInjection/CmfRoutingExtension.php index 5d015913..b03db9cb 100644 --- a/src/DependencyInjection/CmfRoutingExtension.php +++ b/src/DependencyInjection/CmfRoutingExtension.php @@ -27,9 +27,6 @@ */ final class CmfRoutingExtension extends Extension { - /** - * {@inheritdoc} - */ public function load(array $configs, ContainerBuilder $container): void { $config = $this->processConfiguration(new Configuration(), $configs); diff --git a/src/Doctrine/Orm/ContentRepository.php b/src/Doctrine/Orm/ContentRepository.php index ef629000..ba0b02c1 100644 --- a/src/Doctrine/Orm/ContentRepository.php +++ b/src/Doctrine/Orm/ContentRepository.php @@ -37,8 +37,6 @@ protected function getModelAndId(string $identifier): array } /** - * {@inheritdoc} - * * @param string $id The ID contains both model name and id, separated by a colon */ public function findById(mixed $id): ?object diff --git a/src/Doctrine/Orm/RedirectRoute.php b/src/Doctrine/Orm/RedirectRoute.php index 3bb5f210..7c5b07b4 100644 --- a/src/Doctrine/Orm/RedirectRoute.php +++ b/src/Doctrine/Orm/RedirectRoute.php @@ -52,9 +52,6 @@ public function setParameters(array $parameters): void $this->serialisedParameters = json_encode($parameters, \JSON_THROW_ON_ERROR); } - /** - * {@inheritdoc} - */ public function getParameters(): array { if (!isset($this->serialisedParameters)) { @@ -65,9 +62,6 @@ public function getParameters(): array return \is_array($params) ? $params : []; } - /** - * {@inheritdoc} - */ public function getPath(): string { $pattern = parent::getPath(); @@ -78,9 +72,6 @@ public function getPath(): string return $pattern; } - /** - * {@inheritdoc} - */ protected function isBooleanOption(string $name): bool { return 'add_trailing_slash' === $name || parent::isBooleanOption($name); diff --git a/src/Doctrine/Orm/Route.php b/src/Doctrine/Orm/Route.php index eb1a4e75..eb93dc73 100644 --- a/src/Doctrine/Orm/Route.php +++ b/src/Doctrine/Orm/Route.php @@ -58,9 +58,6 @@ public function getPosition(): int return $this->position; } - /** - * {@inheritdoc} - */ public function getRouteKey(): string { return $this->getName(); diff --git a/src/Doctrine/Orm/RouteProvider.php b/src/Doctrine/Orm/RouteProvider.php index 27d17fe9..76dec55c 100644 --- a/src/Doctrine/Orm/RouteProvider.php +++ b/src/Doctrine/Orm/RouteProvider.php @@ -41,9 +41,6 @@ public function __construct(ManagerRegistry $managerRegistry, CandidatesInterfac $this->candidatesStrategy = $candidatesStrategy; } - /** - * {@inheritdoc} - */ public function getRouteCollectionForRequest(Request $request): RouteCollection { $collection = new RouteCollection(); @@ -52,7 +49,7 @@ public function getRouteCollectionForRequest(Request $request): RouteCollection if (0 === \count($candidates)) { return $collection; } - $routes = $this->getRouteRepository()->findByStaticPrefix($candidates, ['position' => 'ASC']); /** @phpstan-ignore-line */ + $routes = $this->getRouteRepository()->findByStaticPrefix($candidates, ['position' => 'ASC']); /* @phpstan-ignore-line */ /** @var Route $route */ foreach ($routes as $route) { $collection->add($route->getName(), $route); @@ -61,9 +58,6 @@ public function getRouteCollectionForRequest(Request $request): RouteCollection return $collection; } - /** - * {@inheritdoc} - */ public function getRouteByName($name): SymfonyRoute { if (!$this->candidatesStrategy->isCandidate($name)) { @@ -78,9 +72,6 @@ public function getRouteByName($name): SymfonyRoute return $route; } - /** - * {@inheritdoc} - */ public function getRoutesByNames($names = null): array { if (null === $names) { diff --git a/src/Doctrine/Phpcr/ContentRepository.php b/src/Doctrine/Phpcr/ContentRepository.php index 96f238a5..02a712c4 100644 --- a/src/Doctrine/Phpcr/ContentRepository.php +++ b/src/Doctrine/Phpcr/ContentRepository.php @@ -26,17 +26,11 @@ */ class ContentRepository extends DoctrineProvider implements ContentRepositoryInterface { - /** - * {@inheritdoc} - */ public function findById($id): ?object { return $this->getObjectManager()->find(null, $id); } - /** - * {@inheritdoc} - */ public function getContentId($content): ?string { if (!\is_object($content)) { diff --git a/src/Doctrine/Phpcr/PrefixCandidates.php b/src/Doctrine/Phpcr/PrefixCandidates.php index 7b17f1bc..afd9303d 100644 --- a/src/Doctrine/Phpcr/PrefixCandidates.php +++ b/src/Doctrine/Phpcr/PrefixCandidates.php @@ -47,7 +47,7 @@ final class PrefixCandidates extends Candidates * is using * @param int $limit Limit to candidates generated per prefix */ - public function __construct(array $prefixes, array $locales = [], ManagerRegistry $doctrine = null, int $limit = 20) + public function __construct(array $prefixes, array $locales = [], ?ManagerRegistry $doctrine = null, int $limit = 20) { parent::__construct($locales, $limit); $this->setPrefixes($prefixes); @@ -74,8 +74,6 @@ public function isCandidate($name): bool } /** - * {@inheritdoc} - * * @param QueryBuilder $queryBuilder */ public function restrictQuery($queryBuilder): void @@ -91,9 +89,6 @@ public function restrictQuery($queryBuilder): void } } - /** - * {@inheritdoc} - */ public function getCandidates(Request $request): array { $candidates = []; diff --git a/src/Doctrine/Phpcr/RedirectRoute.php b/src/Doctrine/Phpcr/RedirectRoute.php index 64f08d15..f821ad66 100644 --- a/src/Doctrine/Phpcr/RedirectRoute.php +++ b/src/Doctrine/Phpcr/RedirectRoute.php @@ -69,9 +69,6 @@ public function setParentDocument($parent): static return $this; } - /** - * {@inheritdoc} - */ public function getParentDocument(): ?object { return $this->parent; @@ -160,9 +157,6 @@ public function getPrefix(): string return $this->idPrefix; } - /** - * {@inheritdoc} - */ public function setPrefix(string $prefix): static { $this->idPrefix = $prefix; @@ -206,9 +200,6 @@ public function generateStaticPrefix(string $id, string $idPrefix): string return $url; } - /** - * {@inheritdoc} - */ public function getPath(): string { $pattern = parent::getPath(); @@ -240,9 +231,6 @@ public function getRouteChildren(): array return $children; } - /** - * {@inheritdoc} - */ protected function isBooleanOption(string $name): bool { return 'add_trailing_slash' === $name || parent::isBooleanOption($name); diff --git a/src/Doctrine/Phpcr/Route.php b/src/Doctrine/Phpcr/Route.php index 5a50ffa1..746c8987 100644 --- a/src/Doctrine/Phpcr/Route.php +++ b/src/Doctrine/Phpcr/Route.php @@ -172,9 +172,6 @@ public function getPrefix(): ?string return $this->idPrefix; } - /** - * {@inheritdoc} - */ public function setPrefix(string $prefix): static { $this->idPrefix = $prefix; @@ -264,9 +261,6 @@ public function getChildren(): Collection return $this->children; } - /** - * {@inheritdoc} - */ protected function isBooleanOption(string $name): bool { return 'add_trailing_slash' === $name || parent::isBooleanOption($name); diff --git a/src/Doctrine/Phpcr/RouteProvider.php b/src/Doctrine/Phpcr/RouteProvider.php index cf21c4ed..e19099f7 100644 --- a/src/Doctrine/Phpcr/RouteProvider.php +++ b/src/Doctrine/Phpcr/RouteProvider.php @@ -45,7 +45,7 @@ public function __construct( ManagerRegistry $managerRegistry, CandidatesInterface $candidatesStrategy, ?string $className = null, - LoggerInterface $logger = null + ?LoggerInterface $logger = null ) { parent::__construct($managerRegistry, $className); $this->candidatesStrategy = $candidatesStrategy; @@ -102,8 +102,6 @@ public function getRouteCollectionForRequest(Request $request): RouteCollection } /** - * {@inheritdoc} - * * @param string $name The absolute path or uuid of the Route document */ public function getRouteByName(string $name): SymfonyRoute diff --git a/src/Form/Type/RouteTypeType.php b/src/Form/Type/RouteTypeType.php index 4ab01217..8cd09c8d 100644 --- a/src/Form/Type/RouteTypeType.php +++ b/src/Form/Type/RouteTypeType.php @@ -19,9 +19,6 @@ class RouteTypeType extends AbstractType { protected array $routeTypes = []; - /** - * {@inheritdoc} - */ public function configureOptions(OptionsResolver $resolver): void { $choices = []; @@ -43,17 +40,11 @@ public function addRouteType(string $type): void $this->routeTypes[$type] = $type; } - /** - * {@inheritdoc} - */ public function getParent(): string { return ChoiceType::class; } - /** - * {@inheritdoc} - */ public function getBlockPrefix(): string { return 'cmf_routing_route_type'; diff --git a/src/Model/RedirectRoute.php b/src/Model/RedirectRoute.php index 41b1ab27..b913162f 100644 --- a/src/Model/RedirectRoute.php +++ b/src/Model/RedirectRoute.php @@ -11,13 +11,9 @@ namespace Symfony\Cmf\Bundle\RoutingBundle\Model; -use LogicException; use Symfony\Cmf\Component\Routing\RedirectRouteInterface; use Symfony\Component\Routing\Route as SymfonyRoute; -/** - * {@inheritdoc} - */ class RedirectRoute extends Route implements RedirectRouteInterface { /** @@ -47,16 +43,13 @@ class RedirectRoute extends Route implements RedirectRouteInterface * as route content for the redirection controller to have the redirect route * object as content. * - * @throws LogicException + * @throws \LogicException */ public function setContent($document): static { - throw new LogicException('Do not set a content for the redirect route. It is its own content.'); + throw new \LogicException('Do not set a content for the redirect route. It is its own content.'); } - /** - * {@inheritdoc} - */ public function getContent(): static { return $this; @@ -71,9 +64,6 @@ public function setRouteTarget(?SymfonyRoute $document): void $this->routeTarget = $document; } - /** - * {@inheritdoc} - */ public function getRouteTarget(): ?SymfonyRoute { return $this->routeTarget; @@ -87,9 +77,6 @@ public function setRouteName(?string $routeName): void $this->routeName = $routeName; } - /** - * {@inheritdoc} - */ public function getRouteName(): ?string { return $this->routeName; @@ -104,9 +91,6 @@ public function setPermanent(bool $permanent): void $this->permanent = $permanent; } - /** - * {@inheritdoc} - */ public function isPermanent(): bool { return $this->permanent; @@ -123,9 +107,6 @@ public function setParameters(array $parameters): void $this->parameters = $parameters; } - /** - * {@inheritdoc} - */ public function getParameters(): array { return $this->parameters; @@ -139,9 +120,6 @@ public function setUri(?string $uri): void $this->uri = $uri; } - /** - * {@inheritdoc} - */ public function getUri(): ?string { return $this->uri; diff --git a/src/Model/Route.php b/src/Model/Route.php index cc7378f2..b5fcf8c6 100644 --- a/src/Model/Route.php +++ b/src/Model/Route.php @@ -76,9 +76,6 @@ public function __construct(array $options = []) } } - /** - * {@inheritdoc} - */ public function getRouteKey(): string { return (string) $this->getId(); @@ -117,9 +114,6 @@ public function setContent(object $object): static return $this; } - /** - * {@inheritdoc} - */ public function getContent(): ?object { return $this->content; @@ -185,9 +179,6 @@ protected function isBooleanOption(string $name): bool return \in_array($name, ['add_format_pattern', 'add_locale_pattern']); } - /** - * {@inheritdoc} - */ public function getPath(): string { $pattern = ''; diff --git a/src/Routing/DynamicRouter.php b/src/Routing/DynamicRouter.php index 350654bf..88f19693 100644 --- a/src/Routing/DynamicRouter.php +++ b/src/Routing/DynamicRouter.php @@ -79,7 +79,7 @@ public function matchRequest(Request $request): array * * @return array the updated defaults to return for this match */ - protected function cleanDefaults(array $defaults, Request $request = null): array + protected function cleanDefaults(array $defaults, ?Request $request = null): array { if (null === $request) { $request = $this->getRequest(); diff --git a/src/Routing/RedirectableRequestMatcher.php b/src/Routing/RedirectableRequestMatcher.php index 6136d027..d46acbc8 100644 --- a/src/Routing/RedirectableRequestMatcher.php +++ b/src/Routing/RedirectableRequestMatcher.php @@ -68,7 +68,7 @@ public function matchRequest(Request $request): array } } - private function redirect(string $path, string $route, string $scheme = null): array + private function redirect(string $path, string $route, ?string $scheme = null): array { return [ '_controller' => 'Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction', diff --git a/tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php b/tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php index 78892b97..c7247c0c 100644 --- a/tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php +++ b/tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php @@ -14,12 +14,11 @@ use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RedirectRoute; use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route; use Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\BaseTestCase; -use Symfony\Cmf\Component\Routing\RedirectRouteInterface; use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface; class RedirectRouteTest extends BaseTestCase { - const ROUTE_ROOT = '/test/redirectroute'; + public const ROUTE_ROOT = '/test/redirectroute'; public function setUp(): void { diff --git a/tests/Functional/Doctrine/Phpcr/RouteProviderTest.php b/tests/Functional/Doctrine/Phpcr/RouteProviderTest.php index 54931348..6c028463 100644 --- a/tests/Functional/Doctrine/Phpcr/RouteProviderTest.php +++ b/tests/Functional/Doctrine/Phpcr/RouteProviderTest.php @@ -21,7 +21,7 @@ class RouteProviderTest extends BaseTestCase { - const ROUTE_ROOT = '/test/routing'; + public const ROUTE_ROOT = '/test/routing'; /** @var RouteProvider */ private $repository; diff --git a/tests/Functional/Doctrine/Phpcr/RouteTest.php b/tests/Functional/Doctrine/Phpcr/RouteTest.php index db03ea08..8c98e191 100644 --- a/tests/Functional/Doctrine/Phpcr/RouteTest.php +++ b/tests/Functional/Doctrine/Phpcr/RouteTest.php @@ -16,7 +16,7 @@ class RouteTest extends BaseTestCase { - const ROUTE_ROOT = '/test/routing'; + public const ROUTE_ROOT = '/test/routing'; public function setUp(): void { diff --git a/tests/Functional/Routing/DynamicRouterTest.php b/tests/Functional/Routing/DynamicRouterTest.php index fd68b03b..14b17d8d 100644 --- a/tests/Functional/Routing/DynamicRouterTest.php +++ b/tests/Functional/Routing/DynamicRouterTest.php @@ -39,7 +39,7 @@ class DynamicRouterTest extends BaseTestCase protected $routeNamePrefix; - const ROUTE_ROOT = '/test/routing'; + public const ROUTE_ROOT = '/test/routing'; public function setUp(): void { diff --git a/tests/Unit/Validator/Constraints/RouteDefaultsTwigValidatorTest.php b/tests/Unit/Validator/Constraints/RouteDefaultsTwigValidatorTest.php index 4dd56316..aa3b50f4 100644 --- a/tests/Unit/Validator/Constraints/RouteDefaultsTwigValidatorTest.php +++ b/tests/Unit/Validator/Constraints/RouteDefaultsTwigValidatorTest.php @@ -12,7 +12,6 @@ namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Unit\Validator\Constraints; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; use Symfony\Cmf\Bundle\RoutingBundle\Validator\Constraints\RouteDefaults; use Symfony\Cmf\Bundle\RoutingBundle\Validator\Constraints\RouteDefaultsTwigValidator; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;