Skip to content

Commit cd84fff

Browse files
committed
improve symfony rules location
1 parent 3282547 commit cd84fff

File tree

53 files changed

+164
-98
lines changed

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

+164
-98
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ Use invokable controller with `__invoke()` method instead of named action method
876876

877877
```yaml
878878
rules:
879-
- Symplify\PHPStanRules\Symfony\Rules\RequireInvokableControllerRule
879+
- Symplify\PHPStanRules\Rules\Symfony\RequireInvokableControllerRule
880880
```
881881
882882
```php

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
"autoload": {
2727
"psr-4": {
2828
"Symplify\\PHPStanRules\\": "src"
29-
}
29+
},
30+
"files": [
31+
"src/functions/fast-functions.php"
32+
]
3033
},
3134
"autoload-dev": {
3235
"psr-4": {

config/symfony-rules.neon

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
rules:
2-
- Symplify\PHPStanRules\PHPStan\Rule\NoAbstractControllerConstructorRule
3-
- Symplify\PHPStanRules\PHPStan\Rule\NoRequiredOutsideClassRule
4-
- Symplify\PHPStanRules\PHPStan\Rule\SingleArgEventDispatchRule
2+
- Symplify\PHPStanRules\Rules\Symfony\NoAbstractControllerConstructorRule
3+
- Symplify\PHPStanRules\Rules\Symfony\NoRequiredOutsideClassRule
4+
- Symplify\PHPStanRules\Rules\Symfony\SingleArgEventDispatchRule
5+
- Symplify\PHPStanRules\Rules\Symfony\NoListenerWithoutContractRule
6+
- Symplify\PHPStanRules\Rules\Symfony\NoStringInGetSubscribedEventsRule
7+
- Symplify\PHPStanRules\Rules\Symfony\RequireInvokableControllerRule

phpstan.neon

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,26 @@ parameters:
2222
- */stubs/*
2323
- */Fixture/*
2424

25-
# https://github.com/TomasVotruba/unused-public
26-
unused_public:
27-
methods: true
28-
properties: true
29-
constants: true
30-
31-
type_coverage:
32-
return: 99
33-
param: 99
34-
property: 99
35-
3625
ignoreErrors:
3726
# needless generics
38-
- '#Class Symplify\\PHPStanRules\\(.*?)Rule implements generic interface PHPStan\\Rules\\Rule but does not specify its types\: TNodeType#'
27+
# - '#Class Symplify\\PHPStanRules\\(.*?)Rule implements generic interface PHPStan\\Rules\\Rule but does not specify its types\: TNodeType#'
3928

4029
- '#Method Symplify\\PHPStanRules\\Reflection\\ReflectionParser\:\:parseNativeClassReflection\(\) has parameter \$reflectionClass with generic class ReflectionClass but does not specify its types\: T#'
4130

4231
# overly detailed
4332
- '#Class Symplify\\PHPStanRules\\(.*?) extends generic class PHPStan\\Testing\\RuleTestCase but does not specify its types\: TRule#'
4433
- '#Method Symplify\\PHPStanRules\\(.*?)\:\:getRule\(\) return type with generic interface PHPStan\\Rules\\Rule does not specify its types\: TNodeType#'
34+
- '#Parameter \#2 \$expectedErrors of method PHPStan\\Testing\\RuleTestCase<PHPStan\\Rules\\Rule>\:\:analyse\(\) expects list<array\{0\: string, 1\: int, 2\?\: string\|null\}>, (.*?) given#'
4535

4636
# part of public contract
47-
- '#Method Symplify\\PHPStanRules\\Tests\\Rules\\PHPUnit\\(.*?)\\(.*?)Test\:\:testRule\(\) has parameter \$expectedErrorMessagesWithLines with no value type specified in iterable type array#'
37+
- '#Method Symplify\\PHPStanRules\\Tests\\Rules\\(.*?)\\(.*?)Test\:\:testRule\(\) has parameter \$(expectedError(.*?)|expectedErrors) with no value type specified in iterable type array#'
4838

4939
# overly detailed
5040
- '#Class Symplify\\PHPStanRules\\Collector\\(.*?) implements generic interface PHPStan\\Collectors\\Collector but does not specify its types\: TNodeType, TValue#'
5141

5242
# useful to have IDE know the types
5343
- identifier: phpstanApi.instanceofType
5444

55-
# overly detailed
56-
-
57-
message: '#Parameter \#2 \$expectedErrors of method PHPStan\\Testing\\RuleTestCase<(.*?)>::analyse\(\) expects list<array\{0: string, 1: int, 2\?: string\|null\}>, (.*?) given#'
58-
path: tests
59-
6045
# fast effective check
6146
-
6247
message: '#Function is_a\(\) is a runtime reflection concept that might not work in PHPStan because it uses fully static reflection engine#'

src/Enum/ClassName.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,19 @@ final class ClassName
5050
* @var string
5151
*/
5252
public const RECTOR_ATTRIBUTE_KEY = 'Rector\NodeTypeResolver\Node\AttributeKey';
53+
54+
/**
55+
* @var string
56+
*/
57+
public const FORM_EVENTS = 'Symfony\Component\Form\FormEvents';
58+
59+
/**
60+
* @var string
61+
*/
62+
public const SYMFONY_CONTROLLER = 'Symfony\Bundle\FrameworkBundle\Controller\Controller';
63+
64+
/**
65+
* @var string
66+
*/
67+
public const DOCTRINE_FIXTURE_INTERFACE = 'Doctrine\Common\DataFixtures\FixtureInterface';
5368
}

src/Enum/RuleIdentifier.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,14 @@ final class RuleIdentifier
160160
* @var string
161161
*/
162162
public const NO_VALUE_OBJECT_IN_SERVICE_CONSTRUCTOR = 'symplify.noValueObjectInServiceConstructor';
163+
164+
/**
165+
* @var string
166+
*/
167+
public const DOCTRINE_NO_REPOSITORY_CALL_IN_DATA_FIXTURES = 'doctrine.noRepositoryCallInDataFixtures';
168+
169+
/**
170+
* @var string
171+
*/
172+
public const PHPUNIT_NO_DOCUMENT_MOCKING = 'phpunit.noDocumentMocking';
163173
}

src/PHPStan/Rules/Doctrine/NoRepositoryCallInDataFixtureRule.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
use PhpParser\Node\Expr\MethodCall;
99
use PhpParser\Node\Identifier;
1010
use PHPStan\Analyser\Scope;
11+
use PHPStan\Rules\IdentifierRuleError;
1112
use PHPStan\Rules\Rule;
13+
use PHPStan\Rules\RuleErrorBuilder;
14+
use Symplify\PHPStanRules\Enum\ClassName;
15+
use Symplify\PHPStanRules\Enum\RuleIdentifier;
16+
use Symplify\PHPStanRules\Tests\Rules\Doctrine\NoRepositoryCallInDataFixtureRule\NoRepositoryCallInDataFixtureRuleTest;
1217

1318
/**
14-
* @see \Symplify\PHPStanRules\Tests\PHPStan\Rule\NoRepositoryCallInDataFixtureRule\NoRepositoryCallInDataFixtureRuleTest
19+
* @see NoRepositoryCallInDataFixtureRuleTest
1520
*
1621
* @implements Rule<MethodCall>
1722
*/
@@ -22,19 +27,14 @@ final class NoRepositoryCallInDataFixtureRule implements Rule
2227
*/
2328
public const ERROR_MESSAGE = 'Refactor read-data fixtures to write-only, make use of references';
2429

25-
/**
26-
* @var string
27-
*/
28-
private const FIXTURE_INTERFACE = 'Doctrine\Common\DataFixtures\FixtureInterface';
29-
3030
public function getNodeType(): string
3131
{
3232
return MethodCall::class;
3333
}
3434

3535
/**
3636
* @param MethodCall $node
37-
* @return string[]
37+
* @return IdentifierRuleError[]
3838
*/
3939
public function processNode(Node $node, Scope $scope): array
4040
{
@@ -55,7 +55,11 @@ public function processNode(Node $node, Scope $scope): array
5555
return [];
5656
}
5757

58-
return [self::ERROR_MESSAGE];
58+
$ruleError = RuleErrorBuilder::message(self::ERROR_MESSAGE)
59+
->identifier(RuleIdentifier::DOCTRINE_NO_REPOSITORY_CALL_IN_DATA_FIXTURES)
60+
->build();
61+
62+
return [$ruleError];
5963
}
6064

6165
private function isDataFixtureClass(Scope $scope): bool
@@ -65,6 +69,6 @@ private function isDataFixtureClass(Scope $scope): bool
6569
}
6670

6771
$classReflection = $scope->getClassReflection();
68-
return $classReflection->isSubclassOf(self::FIXTURE_INTERFACE);
72+
return $classReflection->isSubclassOf(ClassName::DOCTRINE_FIXTURE_INTERFACE);
6973
}
7074
}

src/Rules/Complexity/NoConstructorOverrideRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Symplify\PHPStanRules\PHPStan\Rule;
5+
namespace Symplify\PHPStanRules\Rules\Complexity;
66

77
use PhpParser\Node;
88
use PhpParser\Node\Expr\StaticCall;

src/Rules/Doctrine/NoDocumentMockingRule.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use PhpParser\Node\Identifier;
1010
use PHPStan\Analyser\Scope;
1111
use PHPStan\Rules\Rule;
12+
use PHPStan\Rules\RuleErrorBuilder;
13+
use Symplify\PHPStanRules\Enum\RuleIdentifier;
1214

1315
/**
1416
* @implements Rule<MethodCall>
@@ -27,7 +29,6 @@ public function getNodeType(): string
2729

2830
/**
2931
* @param MethodCall $node
30-
* @return string[]
3132
*/
3233
public function processNode(Node $node, Scope $scope): array
3334
{
@@ -51,7 +52,11 @@ public function processNode(Node $node, Scope $scope): array
5152
continue;
5253
}
5354

54-
return [self::ERROR_MESSAGE];
55+
$ruleError = RuleErrorBuilder::message(self::ERROR_MESSAGE)
56+
->identifier(RuleIdentifier::PHPUNIT_NO_DOCUMENT_MOCKING)
57+
->build();
58+
59+
return [$ruleError];
5560
}
5661

5762
return [];

src/Rules/NoSingleInterfaceImplementerRule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
/**
2020
* @see \Symplify\PHPStanRules\Tests\Rules\NoSingleInterfaceImplementerRule\NoSingleInterfaceImplementerRuleTest
21+
*
22+
* @implements Rule<CollectedDataNode>
2123
*/
2224
final readonly class NoSingleInterfaceImplementerRule implements Rule
2325
{

0 commit comments

Comments
 (0)