|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use PhpParser\Node; |
|
6
|
|
|
use PhpParser\Node\Stmt\ClassMethod; |
|
7
|
|
|
use PHPStan\Analyser\Scope; |
|
|
|
|
|
|
8
|
|
|
use PHPStan\Rules\Rule; |
|
|
|
|
|
|
9
|
|
|
use PHPStan\ShouldNotHappenException; |
|
|
|
|
|
|
10
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @implements Rule<Node\Stmt\ClassMethod> |
|
14
|
|
|
* |
|
15
|
|
|
* @internal |
|
16
|
|
|
*/ |
|
17
|
|
|
#[Package('core')] |
|
18
|
|
|
class PHPUnitDataProviderStaticRule implements Rule |
|
19
|
|
|
{ |
|
20
|
|
|
public function getNodeType(): string |
|
21
|
|
|
{ |
|
22
|
|
|
return ClassMethod::class; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param Node\Stmt\ClassMethod $node |
|
27
|
|
|
* |
|
28
|
|
|
* @return string[] |
|
29
|
|
|
*/ |
|
30
|
|
|
public function processNode(Node $node, Scope $scope): array |
|
31
|
|
|
{ |
|
32
|
|
|
// Check if the method has a dataProvider annotation |
|
33
|
|
|
$docComment = $node->getDocComment(); |
|
34
|
|
|
if ($docComment === null) { |
|
35
|
|
|
return []; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$dataProviderPattern = '/@dataProvider\s+([^\s]+)/'; |
|
39
|
|
|
if (!preg_match($dataProviderPattern, $docComment->getText(), $matches)) { |
|
40
|
|
|
return []; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
// Get the dataProvider method name |
|
44
|
|
|
$dataProviderName = $matches[1]; |
|
45
|
|
|
|
|
46
|
|
|
// Find the dataProvider method in the same class |
|
47
|
|
|
$classReflection = $scope->getClassReflection(); |
|
48
|
|
|
if ($classReflection === null) { |
|
49
|
|
|
throw new ShouldNotHappenException(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$dataProviderMethod = $classReflection->getNativeMethod($dataProviderName); |
|
53
|
|
|
|
|
54
|
|
|
// Check if the dataProvider method is static |
|
55
|
|
|
if (!$dataProviderMethod->isStatic()) { |
|
56
|
|
|
return [sprintf('DataProvider method %s should be static.', $dataProviderName)]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return []; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
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