|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules; |
|
4
|
|
|
|
|
5
|
|
|
use PhpParser\Node; |
|
6
|
|
|
use PHPStan\Analyser\Scope; |
|
|
|
|
|
|
7
|
|
|
use PHPStan\Node\InClassNode; |
|
|
|
|
|
|
8
|
|
|
use PHPStan\Rules\Rule; |
|
|
|
|
|
|
9
|
|
|
use PHPStan\Rules\RuleError; |
|
|
|
|
|
|
10
|
|
|
use Shopware\Core\Checkout\Cart\Rule\AlwaysValidRule; |
|
11
|
|
|
use Shopware\Core\Checkout\Cart\Rule\GoodsCountRule; |
|
12
|
|
|
use Shopware\Core\Checkout\Cart\Rule\GoodsPriceRule; |
|
13
|
|
|
use Shopware\Core\Checkout\Cart\Rule\LineItemCustomFieldRule; |
|
14
|
|
|
use Shopware\Core\Checkout\Cart\Rule\LineItemGoodsTotalRule; |
|
15
|
|
|
use Shopware\Core\Checkout\Cart\Rule\LineItemGroupRule; |
|
16
|
|
|
use Shopware\Core\Checkout\Cart\Rule\LineItemInCategoryRule; |
|
17
|
|
|
use Shopware\Core\Checkout\Cart\Rule\LineItemPropertyRule; |
|
18
|
|
|
use Shopware\Core\Checkout\Cart\Rule\LineItemPurchasePriceRule; |
|
19
|
|
|
use Shopware\Core\Checkout\Cart\Rule\LineItemRule; |
|
20
|
|
|
use Shopware\Core\Checkout\Cart\Rule\LineItemsInCartRule; |
|
21
|
|
|
use Shopware\Core\Checkout\Cart\Rule\LineItemWithQuantityRule; |
|
22
|
|
|
use Shopware\Core\Checkout\Cart\Rule\LineItemWrapperRule; |
|
23
|
|
|
use Shopware\Core\Checkout\Customer\Rule\BillingZipCodeRule; |
|
24
|
|
|
use Shopware\Core\Checkout\Customer\Rule\CustomerCustomFieldRule; |
|
25
|
|
|
use Shopware\Core\Checkout\Customer\Rule\ShippingZipCodeRule; |
|
26
|
|
|
use Shopware\Core\Framework\Rule\Container\AndRule; |
|
27
|
|
|
use Shopware\Core\Framework\Rule\Container\Container; |
|
28
|
|
|
use Shopware\Core\Framework\Rule\Container\FilterRule; |
|
29
|
|
|
use Shopware\Core\Framework\Rule\Container\MatchAllLineItemsRule; |
|
30
|
|
|
use Shopware\Core\Framework\Rule\Container\NotRule; |
|
31
|
|
|
use Shopware\Core\Framework\Rule\Container\OrRule; |
|
32
|
|
|
use Shopware\Core\Framework\Rule\Container\XorRule; |
|
33
|
|
|
use Shopware\Core\Framework\Rule\Container\ZipCodeRule; |
|
34
|
|
|
use Shopware\Core\Framework\Rule\DateRangeRule; |
|
35
|
|
|
use Shopware\Core\Framework\Rule\Rule as ShopwareRule; |
|
36
|
|
|
use Shopware\Core\Framework\Rule\ScriptRule; |
|
37
|
|
|
use Shopware\Core\Framework\Rule\SimpleRule; |
|
38
|
|
|
use Shopware\Core\Framework\Rule\TimeRangeRule; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @implements Rule<InClassNode> |
|
42
|
|
|
* |
|
43
|
|
|
* @internal |
|
44
|
|
|
*/ |
|
45
|
|
|
class RuleConditionHasRuleConfigRule implements Rule |
|
46
|
|
|
{ |
|
47
|
|
|
/** |
|
48
|
|
|
* @var list<string> |
|
|
|
|
|
|
49
|
|
|
*/ |
|
50
|
|
|
private array $rulesAllowedToBeWithoutConfig = [ |
|
51
|
|
|
ZipCodeRule::class, |
|
52
|
|
|
FilterRule::class, |
|
53
|
|
|
Container::class, |
|
54
|
|
|
AndRule::class, |
|
55
|
|
|
NotRule::class, |
|
56
|
|
|
OrRule::class, |
|
57
|
|
|
XorRule::class, |
|
58
|
|
|
MatchAllLineItemsRule::class, |
|
59
|
|
|
ScriptRule::class, |
|
60
|
|
|
DateRangeRule::class, |
|
61
|
|
|
SimpleRule::class, |
|
62
|
|
|
TimeRangeRule::class, |
|
63
|
|
|
GoodsCountRule::class, |
|
64
|
|
|
GoodsPriceRule::class, |
|
65
|
|
|
LineItemRule::class, |
|
66
|
|
|
LineItemsInCartRule::class, |
|
67
|
|
|
LineItemWithQuantityRule::class, |
|
68
|
|
|
LineItemWrapperRule::class, |
|
69
|
|
|
BillingZipCodeRule::class, |
|
70
|
|
|
ShippingZipCodeRule::class, |
|
71
|
|
|
AlwaysValidRule::class, |
|
72
|
|
|
LineItemPropertyRule::class, |
|
73
|
|
|
LineItemPurchasePriceRule::class, |
|
74
|
|
|
LineItemInCategoryRule::class, |
|
75
|
|
|
LineItemCustomFieldRule::class, |
|
76
|
|
|
LineItemGoodsTotalRule::class, |
|
77
|
|
|
CustomerCustomFieldRule::class, |
|
78
|
|
|
LineItemGroupRule::class, |
|
79
|
|
|
]; |
|
80
|
|
|
|
|
81
|
|
|
public function getNodeType(): string |
|
82
|
|
|
{ |
|
83
|
|
|
return InClassNode::class; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param InClassNode $node |
|
88
|
|
|
* |
|
89
|
|
|
* @return array<array-key, RuleError|string> |
|
|
|
|
|
|
90
|
|
|
*/ |
|
91
|
|
|
public function processNode(Node $node, Scope $scope): array |
|
92
|
|
|
{ |
|
93
|
|
|
if (!$this->isRuleClass($scope) || $this->isAllowed($scope) || $this->isValid($scope)) { |
|
94
|
|
|
if ($this->isAllowed($scope) && $this->isValid($scope)) { |
|
95
|
|
|
return ['This class is implementing the getConfig function and has a own admin component. Remove getConfig or the component.']; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return []; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return ['This class has to implement getConfig or implement a new admin component.']; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
private function isValid(Scope $scope): bool |
|
105
|
|
|
{ |
|
106
|
|
|
$class = $scope->getClassReflection(); |
|
107
|
|
|
if ($class === null || !$class->hasMethod('getConfig')) { |
|
108
|
|
|
return false; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
$declaringClass = $class->getMethod('getConfig', $scope)->getDeclaringClass(); |
|
112
|
|
|
|
|
113
|
|
|
return $declaringClass->getName() !== ShopwareRule::class; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
private function isAllowed(Scope $scope): bool |
|
117
|
|
|
{ |
|
118
|
|
|
$class = $scope->getClassReflection(); |
|
119
|
|
|
if ($class === null) { |
|
120
|
|
|
return false; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return \in_array($class->getName(), $this->rulesAllowedToBeWithoutConfig, true); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
private function isRuleClass(Scope $scope): bool |
|
127
|
|
|
{ |
|
128
|
|
|
$class = $scope->getClassReflection(); |
|
129
|
|
|
if ($class === null) { |
|
130
|
|
|
return false; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
$namespace = $class->getName(); |
|
134
|
|
|
if (!\str_contains($namespace, 'Shopware\\Tests\\Unit\\') && !\str_contains($namespace, 'Shopware\\Tests\\Migration\\')) { |
|
135
|
|
|
return false; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
return $class->isSubclassOf(ShopwareRule::class); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths