Skip to content

Commit 9d4c06c

Browse files
committed
misc
1 parent a954fcd commit 9d4c06c

File tree

7 files changed

+39
-22
lines changed

7 files changed

+39
-22
lines changed

composer.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"tomasvotruba/class-leak": "^2.0",
1818
"rector/rector": "^2.0",
1919
"phpstan/extension-installer": "^1.4",
20-
"symplify/phpstan-extensions": "^12.0"
20+
"symplify/phpstan-extensions": "^12.0",
21+
"tomasvotruba/unused-public": "^2.0"
2122
},
2223
"autoload": {
2324
"psr-4": {
@@ -30,17 +31,8 @@
3031
},
3132
"classmap": [
3233
"stubs"
33-
],
34-
"files": [
3534
]
3635
},
37-
"extra": {
38-
"phpstan": {
39-
"includes": [
40-
"config/services/services.neon"
41-
]
42-
}
43-
},
4436
"config": {
4537
"platform-check": false,
4638
"allow-plugins": {
@@ -52,5 +44,12 @@
5244
"fix-cs": "vendor/bin/ecs check --fix --ansi",
5345
"phpstan": "vendor/bin/phpstan analyse --ansi",
5446
"rector": "vendor/bin/rector process --dry-run --ansi"
47+
},
48+
"extra": {
49+
"phpstan": {
50+
"includes": [
51+
"config/services/services.neon"
52+
]
53+
}
5554
}
5655
}

phpstan.neon

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ parameters:
2323
- */Fixture/*
2424

2525
# https://github.com/TomasVotruba/unused-public
26-
# unused_public:
27-
# methods: true
28-
# properties: true
29-
# constants: true
26+
unused_public:
27+
methods: true
28+
properties: true
29+
constants: true
3030

3131
# type_coverage:
3232
# return: 99
@@ -70,3 +70,6 @@ parameters:
7070

7171
# handle next
7272
- '#Method Symplify\\PHPStanRules\\Rules\\AbstractSymplifyRule\:\:processNode\(\) should return list<PHPStan\\Rules\\IdentifierRuleError> but returns array<PHPStan\\Rules\\RuleError\|string>#'
73+
74+
# used in tests
75+
- '#Public constant "Symplify\\PHPStanRules\\(.*?)Rule\:\:ERROR_MESSAGE" is never used#'

src/Enum/ClassName.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\PHPStanRules\Enum;
6+
7+
final class ClassName
8+
{
9+
/**
10+
* @var string
11+
*/
12+
public const ROUTE_ATTRIBUTE = 'Symfony\Component\Routing\Annotation\Route';
13+
}

src/Enum/RuleIdentifier.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,9 @@ final class RuleIdentifier
170170
* @var string
171171
*/
172172
public const REQUIRED_INTERFACE_CONTRACT_NAMESPACE = 'symplify.requiredInterfaceContractNamespace';
173+
174+
/**
175+
* @var string
176+
*/
177+
public const SYMFONY_REQUIRE_INVOKABLE_CONTROLLER = 'symfony.requireInvokableController';
173178
}

src/Rules/UppercaseConstantRule.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
/**
1515
* @implements Rule<ClassConst>
16+
*
1617
* @see \Symplify\PHPStanRules\Tests\Rules\UppercaseConstantRule\UppercaseConstantRuleTest
1718
*/
1819
final class UppercaseConstantRule implements Rule

src/Symfony/NodeAnalyzer/SymfonyControllerAnalyzer.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@
66

77
use PhpParser\Comment\Doc;
88
use PhpParser\Node\Stmt\ClassMethod;
9+
use Symplify\PHPStanRules\Enum\ClassName;
910
use Symplify\PHPStanRules\NodeAnalyzer\AttributeFinder;
1011

1112
final class SymfonyControllerAnalyzer
1213
{
13-
/**
14-
* @var string
15-
*/
16-
private const ROUTE_ATTRIBUTE = 'Symfony\Component\Routing\Annotation\Route';
17-
1814
public static function isControllerActionMethod(ClassMethod $classMethod): bool
1915
{
2016
$attributeFinder = new AttributeFinder();
@@ -23,7 +19,7 @@ public static function isControllerActionMethod(ClassMethod $classMethod): bool
2319
return false;
2420
}
2521

26-
if ($attributeFinder->hasAttribute($classMethod, self::ROUTE_ATTRIBUTE)) {
22+
if ($attributeFinder->hasAttribute($classMethod, ClassName::ROUTE_ATTRIBUTE)) {
2723
return true;
2824
}
2925

src/Symfony/Rules/RequireInvokableControllerRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Node\InClassNode;
1010
use PHPStan\Rules\Rule;
11-
use PHPStan\Rules\RuleError;
1211
use PHPStan\Rules\RuleErrorBuilder;
1312
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1413
use Symplify\PHPStanRules\Enum\MethodName;
14+
use Symplify\PHPStanRules\Enum\RuleIdentifier;
1515
use Symplify\PHPStanRules\Symfony\NodeAnalyzer\SymfonyControllerAnalyzer;
1616

1717
/**
@@ -34,7 +34,6 @@ public function getNodeType(): string
3434

3535
/**
3636
* @param InClassNode $node
37-
* @return RuleError[]
3837
*/
3938
public function processNode(Node $node, Scope $scope): array
4039
{
@@ -63,6 +62,7 @@ public function processNode(Node $node, Scope $scope): array
6362
}
6463

6564
$ruleErrors[] = RuleErrorBuilder::message(self::ERROR_MESSAGE)
65+
->identifier(RuleIdentifier::SYMFONY_REQUIRE_INVOKABLE_CONTROLLER)
6666
->line($classMethod->getLine())
6767
->build();
6868
}

0 commit comments

Comments
 (0)