Skip to content

Commit 315f48a

Browse files
committed
setup phpstan and use php-cs-fixer
* work around ConstraintValidatorTestCase
1 parent 389449f commit 315f48a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+376
-736
lines changed

Diff for: .github/workflows/static.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Static analysis
2+
3+
on:
4+
push:
5+
branches:
6+
- '[0-9]+.x'
7+
- '[0-9]+.[0-9]+'
8+
- '[0-9]+.[0-9]+.x'
9+
pull_request:
10+
11+
jobs:
12+
phpstan:
13+
name: PHPStan
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: '8.3'
21+
extensions: "curl,dom,json,xml,dom"
22+
coverage: none
23+
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
# have to install phpstan ourselves here, the phpstan-ga fails at composer install with weird errors
28+
# composer require --no-update jackalope/jackalope-doctrine-dbal jackalope/jackalope-jackrabbit phpstan/phpstan
29+
- name: Install phpstan
30+
run: |
31+
32+
composer update
33+
34+
- name: PHPStan
35+
run: vendor/bin/phpstan analyze --no-progress
36+
37+
php-cs-fixer:
38+
name: PHP-CS-Fixer
39+
runs-on: ubuntu-latest
40+
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: PHP-CS-Fixer
46+
uses: docker://oskarstark/php-cs-fixer-ga
47+
with:
48+
args: --dry-run --diff

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ phpunit.xml
22
composer.lock
33
vendor
44
tests/Fixtures/App/var/
5-
.phpunit.result.cache
5+
.phpunit.result.cache
6+
.php-cs-fixer.cache

Diff for: .php-cs-fixer.dist.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__.'/src')
5+
->in(__DIR__.'/tests')
6+
->exclude('tests/Fixtures/App/var/')
7+
->name('*.php')
8+
;
9+
10+
$config = new PhpCsFixer\Config();
11+
12+
return $config
13+
->setRiskyAllowed(true)
14+
->setRules([
15+
'@Symfony' => true,
16+
'single_line_throw' => false,
17+
])
18+
->setFinder($finder)
19+
;

Diff for: .styleci.yml

-31
This file was deleted.

Diff for: composer.json

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
"doctrine/phpcr-bundle": "^3.0",
2727
"doctrine/phpcr-odm": "^2.0",
2828
"jackalope/jackalope-doctrine-dbal": "^2.0",
29+
"phpstan/phpstan": "^1.10",
30+
"phpstan/phpstan-doctrine": "^1.3",
31+
"phpstan/phpstan-phpunit": "^1.3",
32+
"phpstan/phpstan-symfony": "^1.3",
33+
"phpunit/phpunit": "^9.5.28",
2934
"matthiasnoback/symfony-dependency-injection-test": "^4.1.0 || ^5.1.0",
3035
"matthiasnoback/symfony-config-test": "^4.1.0 || ^5.1.0",
3136
"symfony/phpunit-bridge": "^7.0.3",
@@ -47,6 +52,7 @@
4752
"conflict": {
4853
"doctrine/common": "<3.1.1",
4954
"doctrine/persistence": "<1.3.0",
55+
"doctrine/phpcr-odm": "<2.0",
5056
"symfony/doctrine-bridge": "<6.4.0",
5157
"symfony/security-core": "<6.4.0"
5258
},

Diff for: phpstan.neon.dist

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
includes:
2+
- vendor/phpstan/phpstan-doctrine/extension.neon
3+
- vendor/phpstan/phpstan-doctrine/rules.neon
4+
- vendor/phpstan/phpstan-phpunit/extension.neon
5+
- vendor/phpstan/phpstan-symfony/extension.neon
6+
- vendor/phpstan/phpstan-symfony/rules.neon
7+
parameters:
8+
level: 2
9+
paths:
10+
- src/
11+
- tests/
12+
excludePaths:
13+
- tests/Fixtures/App/var/
14+
- tests/Fixtures/App/config/
15+
- tests/Fixtures/fixtures/config/

Diff for: src/DependencyInjection/CmfRoutingExtension.php

-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
*/
2828
final class CmfRoutingExtension extends Extension
2929
{
30-
/**
31-
* {@inheritdoc}
32-
*/
3330
public function load(array $configs, ContainerBuilder $container): void
3431
{
3532
$config = $this->processConfiguration(new Configuration(), $configs);

Diff for: src/Doctrine/Orm/ContentRepository.php

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ protected function getModelAndId(string $identifier): array
3737
}
3838

3939
/**
40-
* {@inheritdoc}
41-
*
4240
* @param string $id The ID contains both model name and id, separated by a colon
4341
*/
4442
public function findById(mixed $id): ?object

Diff for: src/Doctrine/Orm/RedirectRoute.php

-9
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ public function setParameters(array $parameters): void
5252
$this->serialisedParameters = json_encode($parameters, \JSON_THROW_ON_ERROR);
5353
}
5454

55-
/**
56-
* {@inheritdoc}
57-
*/
5855
public function getParameters(): array
5956
{
6057
if (!isset($this->serialisedParameters)) {
@@ -65,9 +62,6 @@ public function getParameters(): array
6562
return \is_array($params) ? $params : [];
6663
}
6764

68-
/**
69-
* {@inheritdoc}
70-
*/
7165
public function getPath(): string
7266
{
7367
$pattern = parent::getPath();
@@ -78,9 +72,6 @@ public function getPath(): string
7872
return $pattern;
7973
}
8074

81-
/**
82-
* {@inheritdoc}
83-
*/
8475
protected function isBooleanOption(string $name): bool
8576
{
8677
return 'add_trailing_slash' === $name || parent::isBooleanOption($name);

Diff for: src/Doctrine/Orm/Route.php

-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ public function getPosition(): int
5858
return $this->position;
5959
}
6060

61-
/**
62-
* {@inheritdoc}
63-
*/
6461
public function getRouteKey(): string
6562
{
6663
return $this->getName();

Diff for: src/Doctrine/Orm/RouteProvider.php

+4-13
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ public function __construct(ManagerRegistry $managerRegistry, CandidatesInterfac
4141
$this->candidatesStrategy = $candidatesStrategy;
4242
}
4343

44-
/**
45-
* {@inheritdoc}
46-
*/
4744
public function getRouteCollectionForRequest(Request $request): RouteCollection
4845
{
4946
$collection = new RouteCollection();
@@ -52,18 +49,15 @@ public function getRouteCollectionForRequest(Request $request): RouteCollection
5249
if (0 === \count($candidates)) {
5350
return $collection;
5451
}
55-
$routes = $this->getRouteRepository()->findByStaticPrefix($candidates, ['position' => 'ASC']);
56-
/** @var $route Route */
52+
$routes = $this->getRouteRepository()->findByStaticPrefix($candidates, ['position' => 'ASC']); /* @phpstan-ignore-line */
53+
/** @var Route $route */
5754
foreach ($routes as $route) {
5855
$collection->add($route->getName(), $route);
5956
}
6057

6158
return $collection;
6259
}
6360

64-
/**
65-
* {@inheritdoc}
66-
*/
6761
public function getRouteByName($name): SymfonyRoute
6862
{
6963
if (!$this->candidatesStrategy->isCandidate($name)) {
@@ -78,9 +72,6 @@ public function getRouteByName($name): SymfonyRoute
7872
return $route;
7973
}
8074

81-
/**
82-
* {@inheritdoc}
83-
*/
8475
public function getRoutesByNames($names = null): array
8576
{
8677
if (null === $names) {
@@ -90,7 +81,7 @@ public function getRoutesByNames($names = null): array
9081

9182
try {
9283
return $this->getRouteRepository()->findBy([], null, $this->routeCollectionLimit ?: null);
93-
} catch (TableNotFoundException $e) {
84+
} catch (TableNotFoundException) {
9485
return [];
9586
}
9687
}
@@ -100,7 +91,7 @@ public function getRoutesByNames($names = null): array
10091
// TODO: if we do findByName with multivalue, we need to filter with isCandidate afterwards
10192
try {
10293
$routes[] = $this->getRouteByName($name);
103-
} catch (RouteNotFoundException $e) {
94+
} catch (RouteNotFoundException) {
10495
// not found
10596
}
10697
}

Diff for: src/Doctrine/Phpcr/ContentRepository.php

+14-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

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

14+
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
1415
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\DoctrineProvider;
1516
use Symfony\Cmf\Component\Routing\ContentRepositoryInterface;
1617

@@ -25,17 +26,11 @@
2526
*/
2627
class ContentRepository extends DoctrineProvider implements ContentRepositoryInterface
2728
{
28-
/**
29-
* {@inheritdoc}
30-
*/
3129
public function findById($id): ?object
3230
{
3331
return $this->getObjectManager()->find(null, $id);
3432
}
3533

36-
/**
37-
* {@inheritdoc}
38-
*/
3934
public function getContentId($content): ?string
4035
{
4136
if (!\is_object($content)) {
@@ -48,4 +43,17 @@ public function getContentId($content): ?string
4843
return null;
4944
}
5045
}
46+
47+
/**
48+
* Make sure the manager is a PHPCR-ODM manager.
49+
*/
50+
protected function getObjectManager(): DocumentManagerInterface
51+
{
52+
$dm = parent::getObjectManager();
53+
if (!$dm instanceof DocumentManagerInterface) {
54+
throw new \LogicException(sprintf('Expected %s, got %s', DocumentManagerInterface::class, get_class($dm)));
55+
}
56+
57+
return $dm;
58+
}
5159
}

Diff for: src/Doctrine/Phpcr/PrefixCandidates.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ final class PrefixCandidates extends Candidates
4747
* is using
4848
* @param int $limit Limit to candidates generated per prefix
4949
*/
50-
public function __construct(array $prefixes, array $locales = [], ManagerRegistry $doctrine = null, int $limit = 20)
50+
public function __construct(array $prefixes, array $locales = [], ?ManagerRegistry $doctrine = null, int $limit = 20)
5151
{
5252
parent::__construct($locales, $limit);
5353
$this->setPrefixes($prefixes);
@@ -74,8 +74,6 @@ public function isCandidate($name): bool
7474
}
7575

7676
/**
77-
* {@inheritdoc}
78-
*
7977
* @param QueryBuilder $queryBuilder
8078
*/
8179
public function restrictQuery($queryBuilder): void
@@ -91,9 +89,6 @@ public function restrictQuery($queryBuilder): void
9189
}
9290
}
9391

94-
/**
95-
* {@inheritdoc}
96-
*/
9792
public function getCandidates(Request $request): array
9893
{
9994
$candidates = [];

0 commit comments

Comments
 (0)