Skip to content

Commit 735b390

Browse files
authored
Merge pull request #39 from shochdoerfer/feature/optimize_rule_config
Apply phpstan.rules.rule tag dynamically via DI
2 parents 64cb923 + 8611434 commit 735b390

File tree

5 files changed

+7
-72
lines changed

5 files changed

+7
-72
lines changed

extension.neon

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ parametersSchema:
99
checkServiceContracts: bool()
1010
])
1111

12+
conditionalTags:
13+
bitExpert\PHPStan\Magento\Rules\AbstractModelRetrieveCollectionViaFactoryRule:
14+
phpstan.rules.rule: %magento.checkCollectionViaFactory%
15+
bitExpert\PHPStan\Magento\Rules\AbstractModelUseServiceContractRule:
16+
phpstan.rules.rule: %magento.checkServiceContracts%
17+
1218
services:
1319
-
1420
class: bitExpert\PHPStan\Magento\Type\ObjectManagerDynamicReturnTypeExtension
@@ -24,13 +30,6 @@ services:
2430
- phpstan.broker.methodsClassReflectionExtension
2531
-
2632
class: bitExpert\PHPStan\Magento\Rules\AbstractModelRetrieveCollectionViaFactoryRule
27-
arguments:
28-
checkCollectionViaFactory: %magento.checkCollectionViaFactory%
29-
tags:
30-
- phpstan.rules.rule
3133
-
3234
class: bitExpert\PHPStan\Magento\Rules\AbstractModelUseServiceContractRule
33-
arguments:
34-
checkServiceContracts: %magento.checkServiceContracts%
35-
tags:
36-
- phpstan.rules.rule
35+

src/bitExpert/PHPStan/Magento/Rules/AbstractModelRetrieveCollectionViaFactoryRule.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,6 @@
2727
*/
2828
class AbstractModelRetrieveCollectionViaFactoryRule implements Rule
2929
{
30-
/**
31-
* @var bool
32-
*/
33-
private $checkCollectionViaFactory;
34-
35-
/**
36-
* AbstractModelRetrieveCollectionViaFactoryRule constructor.
37-
*
38-
* @param bool $checkCollectionViaFactory
39-
*/
40-
public function __construct(bool $checkCollectionViaFactory = true)
41-
{
42-
$this->checkCollectionViaFactory = $checkCollectionViaFactory;
43-
}
44-
4530
/**
4631
* @return string
4732
*/
@@ -58,10 +43,6 @@ public function getNodeType(): string
5843
*/
5944
public function processNode(Node $node, Scope $scope): array
6045
{
61-
if (!$this->checkCollectionViaFactory) {
62-
return [];
63-
}
64-
6546
if (!$node instanceof MethodCall) {
6647
throw new ShouldNotHappenException();
6748
}

src/bitExpert/PHPStan/Magento/Rules/AbstractModelUseServiceContractRule.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,6 @@
2727
*/
2828
class AbstractModelUseServiceContractRule implements Rule
2929
{
30-
/**
31-
* @var bool
32-
*/
33-
private $checkServiceContracts;
34-
35-
/**
36-
* AbstractModelUseServiceContractRule constructor.
37-
*
38-
* @param bool $checkServiceContracts
39-
*/
40-
public function __construct(bool $checkServiceContracts = true)
41-
{
42-
$this->checkServiceContracts = $checkServiceContracts;
43-
}
44-
4530
/**
4631
* @return string
4732
*/
@@ -58,10 +43,6 @@ public function getNodeType(): string
5843
*/
5944
public function processNode(Node $node, Scope $scope): array
6045
{
61-
if (!$this->checkServiceContracts) {
62-
return [];
63-
}
64-
6546
if (!$node instanceof MethodCall) {
6647
throw new ShouldNotHappenException();
6748
}

tests/bitExpert/PHPStan/Magento/Rules/AbstractModelRetrieveCollectionViaFactoryRuleUnitTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,4 @@ public function checkCaughtException(): void
3939
]
4040
]);
4141
}
42-
43-
/**
44-
* @test
45-
*/
46-
public function inactiveRuleReturnsArray(): void
47-
{
48-
$rule = new AbstractModelRetrieveCollectionViaFactoryRule(false);
49-
$node = $this->createMock(\PhpParser\Node::class);
50-
$scope = $this->createMock(\PHPStan\Analyser\Scope::class);
51-
52-
$return = $rule->processNode($node, $scope);
53-
$this->assertCount(0, $return);
54-
}
5542
}

tests/bitExpert/PHPStan/Magento/Rules/AbstractModelUseServiceContractRuleUnitTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,4 @@ public function checkCaughtExceptions(): void
4646
],
4747
]);
4848
}
49-
50-
/**
51-
* @test
52-
*/
53-
public function inactiveRuleReturnsArray(): void
54-
{
55-
$rule = new AbstractModelUseServiceContractRule(false);
56-
$node = $this->createMock(\PhpParser\Node::class);
57-
$scope = $this->createMock(\PHPStan\Analyser\Scope::class);
58-
59-
$return = $rule->processNode($node, $scope);
60-
$this->assertCount(0, $return);
61-
}
6249
}

0 commit comments

Comments
 (0)