Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cs fixer #490

Merged
merged 1 commit into from
Apr 6, 2024
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
48 changes: 48 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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
# composer require --no-update jackalope/jackalope-doctrine-dbal jackalope/jackalope-jackrabbit phpstan/phpstan
- name: Install phpstan
run: |

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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ phpunit.xml
composer.lock
vendor
tests/Fixtures/App/var/
.phpunit.result.cache
.phpunit.result.cache
.php-cs-fixer.cache
19 changes: 19 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

$finder = PhpCsFixer\Finder::create()
->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)
;
31 changes: 0 additions & 31 deletions .styleci.yml

This file was deleted.

6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"doctrine/phpcr-bundle": "^3.0",
"doctrine/phpcr-odm": "^2.0",
"jackalope/jackalope-doctrine-dbal": "^2.0",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-symfony": "^1.3",
"phpunit/phpunit": "^9.5.28",
"matthiasnoback/symfony-dependency-injection-test": "^4.1.0 || ^5.1.0",
"matthiasnoback/symfony-config-test": "^4.1.0 || ^5.1.0",
"symfony/phpunit-bridge": "^7.0.3",
Expand All @@ -47,6 +52,7 @@
"conflict": {
"doctrine/common": "<3.1.1",
"doctrine/persistence": "<1.3.0",
"doctrine/phpcr-odm": "<2.0",
"symfony/doctrine-bridge": "<6.4.0",
"symfony/security-core": "<6.4.0"
},
Expand Down
15 changes: 15 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
includes:
- vendor/phpstan/phpstan-doctrine/extension.neon
- vendor/phpstan/phpstan-doctrine/rules.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-symfony/rules.neon
parameters:
level: 2
paths:
- src/
- tests/
excludePaths:
- tests/Fixtures/App/var/
- tests/Fixtures/App/config/
- tests/Fixtures/fixtures/config/
3 changes: 0 additions & 3 deletions src/DependencyInjection/CmfRoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
*/
final class CmfRoutingExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$config = $this->processConfiguration(new Configuration(), $configs);
Expand Down
2 changes: 0 additions & 2 deletions src/Doctrine/Orm/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions src/Doctrine/Orm/RedirectRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -65,9 +62,6 @@ public function getParameters(): array
return \is_array($params) ? $params : [];
}

/**
* {@inheritdoc}
*/
public function getPath(): string
{
$pattern = parent::getPath();
Expand All @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions src/Doctrine/Orm/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ public function getPosition(): int
return $this->position;
}

/**
* {@inheritdoc}
*/
public function getRouteKey(): string
{
return $this->getName();
Expand Down
17 changes: 4 additions & 13 deletions src/Doctrine/Orm/RouteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public function __construct(ManagerRegistry $managerRegistry, CandidatesInterfac
$this->candidatesStrategy = $candidatesStrategy;
}

/**
* {@inheritdoc}
*/
public function getRouteCollectionForRequest(Request $request): RouteCollection
{
$collection = new RouteCollection();
Expand All @@ -52,18 +49,15 @@ public function getRouteCollectionForRequest(Request $request): RouteCollection
if (0 === \count($candidates)) {
return $collection;
}
$routes = $this->getRouteRepository()->findByStaticPrefix($candidates, ['position' => 'ASC']);
/** @var $route Route */
$routes = $this->getRouteRepository()->findByStaticPrefix($candidates, ['position' => 'ASC']); /* @phpstan-ignore-line */
/** @var Route $route */
foreach ($routes as $route) {
$collection->add($route->getName(), $route);
}

return $collection;
}

/**
* {@inheritdoc}
*/
public function getRouteByName($name): SymfonyRoute
{
if (!$this->candidatesStrategy->isCandidate($name)) {
Expand All @@ -78,9 +72,6 @@ public function getRouteByName($name): SymfonyRoute
return $route;
}

/**
* {@inheritdoc}
*/
public function getRoutesByNames($names = null): array
{
if (null === $names) {
Expand All @@ -90,7 +81,7 @@ public function getRoutesByNames($names = null): array

try {
return $this->getRouteRepository()->findBy([], null, $this->routeCollectionLimit ?: null);
} catch (TableNotFoundException $e) {
} catch (TableNotFoundException) {
return [];
}
}
Expand All @@ -100,7 +91,7 @@ public function getRoutesByNames($names = null): array
// TODO: if we do findByName with multivalue, we need to filter with isCandidate afterwards
try {
$routes[] = $this->getRouteByName($name);
} catch (RouteNotFoundException $e) {
} catch (RouteNotFoundException) {
// not found
}
}
Expand Down
20 changes: 14 additions & 6 deletions src/Doctrine/Phpcr/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr;

use Doctrine\ODM\PHPCR\DocumentManagerInterface;
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\DoctrineProvider;
use Symfony\Cmf\Component\Routing\ContentRepositoryInterface;

Expand All @@ -25,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)) {
Expand All @@ -48,4 +43,17 @@ public function getContentId($content): ?string
return null;
}
}

/**
* Make sure the manager is a PHPCR-ODM manager.
*/
protected function getObjectManager(): DocumentManagerInterface
{
$dm = parent::getObjectManager();
if (!$dm instanceof DocumentManagerInterface) {
throw new \LogicException(sprintf('Expected %s, got %s', DocumentManagerInterface::class, get_class($dm)));
}

return $dm;
}
}
7 changes: 1 addition & 6 deletions src/Doctrine/Phpcr/PrefixCandidates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -74,8 +74,6 @@ public function isCandidate($name): bool
}

/**
* {@inheritdoc}
*
* @param QueryBuilder $queryBuilder
*/
public function restrictQuery($queryBuilder): void
Expand All @@ -91,9 +89,6 @@ public function restrictQuery($queryBuilder): void
}
}

/**
* {@inheritdoc}
*/
public function getCandidates(Request $request): array
{
$candidates = [];
Expand Down
Loading
Loading