Skip to content

Commit 1400703

Browse files
authored
make use of naming helper (#211)
1 parent 3a3263a commit 1400703

10 files changed

+20
-47
lines changed

src/Rules/Doctrine/NoDocumentMockingRule.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\Rules\Rule;
1212
use PHPStan\Rules\RuleErrorBuilder;
1313
use Symplify\PHPStanRules\Enum\RuleIdentifier\PHPUnitRuleIdentifier;
14+
use Symplify\PHPStanRules\Helper\NamingHelper;
1415

1516
/**
1617
* @implements Rule<MethodCall>
@@ -36,12 +37,7 @@ public function processNode(Node $node, Scope $scope): array
3637
return [];
3738
}
3839

39-
if (! $node->name instanceof Identifier) {
40-
return [];
41-
}
42-
43-
$methodName = $node->name->toString();
44-
if ($methodName !== 'createMock') {
40+
if (! NamingHelper::isName($node->name, 'createMock')) {
4541
return [];
4642
}
4743

src/Rules/Doctrine/NoGetRepositoryOnServiceRepositoryEntityRule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symplify\PHPStanRules\Enum\DoctrineClass;
2020
use Symplify\PHPStanRules\Enum\RuleIdentifier\DoctrineRuleIdentifier;
2121
use Symplify\PHPStanRules\Enum\TestClassName;
22+
use Symplify\PHPStanRules\Helper\NamingHelper;
2223

2324
/**
2425
* @implements Rule<MethodCall>
@@ -51,7 +52,7 @@ public function getNodeType(): string
5152
*/
5253
public function processNode(Node $node, Scope $scope): array
5354
{
54-
if (! $node->name instanceof Identifier || $node->name->toString() !== 'getRepository') {
55+
if (! NamingHelper::isName($node->name, 'getRepository')) {
5556
return [];
5657
}
5758

src/Rules/Doctrine/NoGetRepositoryOutsideServiceRule.php

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

77
use PhpParser\Node;
88
use PhpParser\Node\Expr\MethodCall;
9-
use PhpParser\Node\Identifier;
109
use PHPStan\Analyser\Scope;
1110
use PHPStan\Rules\Rule;
1211
use PHPStan\Rules\RuleErrorBuilder;
1312
use Symplify\PHPStanRules\Enum\RuleIdentifier\DoctrineRuleIdentifier;
13+
use Symplify\PHPStanRules\Helper\NamingHelper;
1414

1515
/**
1616
* @see \Symplify\PHPStanRules\Tests\Rules\Doctrine\NoGetRepositoryOutsideServiceRule\NoGetRepositoryOutsideServiceRuleTest
@@ -34,11 +34,7 @@ public function getNodeType(): string
3434
*/
3535
public function processNode(Node $node, Scope $scope): array
3636
{
37-
if (! $node->name instanceof Identifier) {
38-
return [];
39-
}
40-
41-
if ($node->name->toString() !== 'getRepository') {
37+
if (! NamingHelper::isName($node->name, 'getRepository')) {
4238
return [];
4339
}
4440

src/Rules/Doctrine/RequireQueryBuilderOnRepositoryRule.php

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

77
use PhpParser\Node;
88
use PhpParser\Node\Expr\MethodCall;
9-
use PhpParser\Node\Identifier;
109
use PHPStan\Analyser\Scope;
1110
use PHPStan\Rules\Rule;
1211
use PHPStan\Rules\RuleErrorBuilder;
1312
use PHPStan\Type\ObjectType;
1413
use Symplify\PHPStanRules\Enum\DoctrineClass;
1514
use Symplify\PHPStanRules\Enum\RuleIdentifier\DoctrineRuleIdentifier;
15+
use Symplify\PHPStanRules\Helper\NamingHelper;
1616

1717
/**
1818
* @implements Rule<MethodCall>
@@ -34,11 +34,7 @@ public function getNodeType(): string
3434
*/
3535
public function processNode(Node $node, Scope $scope): array
3636
{
37-
if (! $node->name instanceof Identifier) {
38-
return [];
39-
}
40-
41-
if ($node->name->toString() !== 'createQueryBuilder') {
37+
if (! NamingHelper::isName($node->name, 'createQueryBuilder')) {
4238
return [];
4339
}
4440

src/Rules/NoValueObjectInServiceConstructorRule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\Rules\Rule;
1212
use PHPStan\Rules\RuleErrorBuilder;
1313
use Symplify\PHPStanRules\Enum\RuleIdentifier;
14+
use Symplify\PHPStanRules\Helper\NamingHelper;
1415

1516
/**
1617
* @implements Rule<ClassMethod>
@@ -27,7 +28,7 @@ public function getNodeType(): string
2728
*/
2829
public function processNode(Node $node, Scope $scope): array
2930
{
30-
if ($node->name->toString() !== '__construct') {
31+
if (! NamingHelper::isName($node->name, '__construct')) {
3132
return [];
3233
}
3334

src/Rules/PHPUnit/NoAssertFuncCallInTestsRule.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
use PhpParser\Node;
66
use PhpParser\Node\Expr\FuncCall;
7-
use PhpParser\Node\Name;
87
use PHPStan\Analyser\Scope;
98
use PHPStan\Rules\IdentifierRuleError;
109
use PHPStan\Rules\Rule;
1110
use PHPStan\Rules\RuleErrorBuilder;
1211
use Symplify\PHPStanRules\Enum\RuleIdentifier\PHPUnitRuleIdentifier;
12+
use Symplify\PHPStanRules\Helper\NamingHelper;
1313

1414
/**
1515
* @implements Rule<FuncCall>
@@ -38,11 +38,7 @@ public function getNodeType(): string
3838
*/
3939
public function processNode(Node $node, Scope $scope): array
4040
{
41-
if (! $node->name instanceof Name) {
42-
return [];
43-
}
44-
45-
if ($node->name->toString() !== 'assert') {
41+
if (! NamingHelper::isName($node->name, 'assert')) {
4642
return [];
4743
}
4844

src/Rules/Rector/NoInstanceOfStaticReflectionRule.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPStan\Type\Constant\ConstantStringType;
1616
use PHPStan\Type\Type;
1717
use Symplify\PHPStanRules\Enum\RuleIdentifier\RectorRuleIdentifier;
18+
use Symplify\PHPStanRules\Helper\NamingHelper;
1819
use Symplify\PHPStanRules\TypeAnalyzer\RectorAllowedAutoloadedTypeAnalyzer;
1920

2021
/**
@@ -65,11 +66,7 @@ private function resolveExprStaticType(FuncCall|Instanceof_ $node, Scope $scope)
6566
return $this->resolveInstanceOfType($node, $scope);
6667
}
6768

68-
if (! $node->name instanceof Name) {
69-
return null;
70-
}
71-
72-
if ($node->name->toString() !== 'is_a') {
69+
if (! NamingHelper::isName($node->name, 'is_a')) {
7370
return null;
7471
}
7572

src/Rules/Symfony/ConfigClosure/ServicesExcludedDirectoryMustExistRule.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use PhpParser\Node\Expr\BinaryOp\Concat;
1212
use PhpParser\Node\Expr\Closure;
1313
use PhpParser\Node\Expr\MethodCall;
14-
use PhpParser\Node\Identifier;
1514
use PhpParser\Node\Scalar\MagicConst\Dir;
1615
use PhpParser\Node\Scalar\String_;
1716
use PhpParser\NodeFinder;
@@ -20,6 +19,7 @@
2019
use PHPStan\Rules\Rule;
2120
use PHPStan\Rules\RuleErrorBuilder;
2221
use Symplify\PHPStanRules\Enum\RuleIdentifier\SymfonyRuleIdentifier;
22+
use Symplify\PHPStanRules\Helper\NamingHelper;
2323
use Symplify\PHPStanRules\Symfony\NodeAnalyzer\SymfonyClosureDetector;
2424

2525
/**
@@ -138,11 +138,7 @@ private function resolveExcludeMethodCalls(Closure $closure): array
138138
return false;
139139
}
140140

141-
if (! $node->name instanceof Identifier) {
142-
return false;
143-
}
144-
145-
return $node->name->toString() === 'exclude';
141+
return NamingHelper::isName($node->name, 'exclude');
146142
});
147143

148144
/** @var MethodCall[] $methodCalls */

src/Rules/Symfony/NoFindTaggedServiceIdsCallRule.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPStan\Rules\Rule;
1313
use PHPStan\Rules\RuleErrorBuilder;
1414
use Symplify\PHPStanRules\Enum\RuleIdentifier\SymfonyRuleIdentifier;
15+
use Symplify\PHPStanRules\Helper\NamingHelper;
1516

1617
/**
1718
* @implements Rule<MethodCall>
@@ -34,11 +35,7 @@ public function getNodeType(): string
3435
*/
3536
public function processNode(Node $node, Scope $scope): array
3637
{
37-
if (! $node->name instanceof Identifier) {
38-
return [];
39-
}
40-
41-
if ($node->name->toString() !== 'findTaggedServiceIds') {
38+
if (! NamingHelper::isName($node->name, 'findTaggedServiceIds')) {
4239
return [];
4340
}
4441

src/Rules/Symfony/NoRoutingPrefixRule.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPStan\Type\ObjectType;
1616
use Symplify\PHPStanRules\Enum\RuleIdentifier\SymfonyRuleIdentifier;
1717
use Symplify\PHPStanRules\Enum\SymfonyClass;
18+
use Symplify\PHPStanRules\Helper\NamingHelper;
1819

1920
/**
2021
* @implements Rule<MethodCall>
@@ -39,11 +40,7 @@ public function getNodeType(): string
3940
*/
4041
public function processNode(Node $node, Scope $scope): array
4142
{
42-
if (! $node->name instanceof Identifier) {
43-
return [];
44-
}
45-
46-
if ($node->name->toString() !== 'prefix') {
43+
if (! NamingHelper::isName($node->name, 'prefix')) {
4744
return [];
4845
}
4946

0 commit comments

Comments
 (0)