|
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 Symfony\Component\Messenger\Handler\MessageHandlerInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @package core |
|
14
|
|
|
* @implements Rule<InClassNode> |
|
15
|
|
|
* |
|
16
|
|
|
* @internal |
|
17
|
|
|
*/ |
|
18
|
|
|
class FinalClassRule implements Rule |
|
19
|
|
|
{ |
|
20
|
|
|
public function getNodeType(): string |
|
21
|
|
|
{ |
|
22
|
|
|
return InClassNode::class; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param InClassNode $node |
|
27
|
|
|
* |
|
28
|
|
|
* @return array<array-key, RuleError|string> |
|
|
|
|
|
|
29
|
|
|
*/ |
|
30
|
|
|
public function processNode(Node $node, Scope $scope): array |
|
31
|
|
|
{ |
|
32
|
|
|
if ($node->getClassReflection()->isFinal()) { |
|
|
|
|
|
|
33
|
|
|
return []; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if ($this->isMessageHandler($node)) { |
|
37
|
|
|
$classDeprecation = $node->getClassReflection()->getDeprecatedDescription() ?? ''; |
|
38
|
|
|
/** |
|
39
|
|
|
* @deprecated tag:v6.5.0 - remove deprecation check, as all message handlers become final in v6.5.0 |
|
40
|
|
|
*/ |
|
41
|
|
|
if (\str_contains($classDeprecation, 'tag:v6.5.0')) { |
|
42
|
|
|
return []; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return ['MessageHandlers must be final, so they cannot be extended/overwritten.']; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return []; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
private function isMessageHandler(InClassNode $node): bool |
|
52
|
|
|
{ |
|
53
|
|
|
$class = $node->getClassReflection(); |
|
54
|
|
|
|
|
55
|
|
|
if ($class->isAbstract()) { |
|
56
|
|
|
// abstract base classes should not be final |
|
57
|
|
|
return false; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
foreach ($class->getInterfaces() as $interface) { |
|
61
|
|
|
if ($interface->getName() === MessageHandlerInterface::class) { |
|
62
|
|
|
return true; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return false; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
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