1 | <?php |
||
2 | |||
3 | namespace UsageFinder; |
||
4 | |||
5 | use PhpParser\Node\Expr; |
||
6 | use PhpParser\Node\Expr\MethodCall; |
||
7 | use PhpParser\Node\Expr\StaticCall; |
||
8 | use Psalm\CodeLocation; |
||
0 ignored issues
–
show
|
|||
9 | use Psalm\Codebase; |
||
0 ignored issues
–
show
The type
Psalm\Codebase was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
10 | use Psalm\Context; |
||
0 ignored issues
–
show
The type
Psalm\Context was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
11 | use Psalm\FileManipulation; |
||
0 ignored issues
–
show
The type
Psalm\FileManipulation was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
12 | use Psalm\IssueBuffer; |
||
0 ignored issues
–
show
The type
Psalm\IssueBuffer was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
13 | use Psalm\Issue\PluginIssue; |
||
0 ignored issues
–
show
The type
Psalm\Issue\PluginIssue was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
14 | use Psalm\Plugin\Hook\AfterMethodCallAnalysisInterface; |
||
0 ignored issues
–
show
The type
Psalm\Plugin\Hook\AfterMethodCallAnalysisInterface was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
15 | use Psalm\StatementsSource; |
||
0 ignored issues
–
show
The type
Psalm\StatementsSource was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
16 | use Psalm\Type\Union; |
||
0 ignored issues
–
show
The type
Psalm\Type\Union was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
17 | use UsageFinder\ClassMethodReference; |
||
0 ignored issues
–
show
The type
UsageFinder\ClassMethodReference was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
18 | use UsageFinder\Issue\ClassMethodUsageFound; |
||
0 ignored issues
–
show
The type
UsageFinder\Issue\ClassMethodUsageFound was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
19 | |||
20 | final class FindClassMethodUsagesPlugin implements AfterMethodCallAnalysisInterface |
||
21 | { |
||
22 | /** @var ClassMethodReference */ |
||
23 | public static $classMethodReference; |
||
24 | |||
25 | public static function afterMethodCallAnalysis( |
||
26 | Expr $expr, |
||
27 | string $method_id, |
||
28 | string $appearing_method_id, |
||
29 | string $declaring_method_id, |
||
30 | Context $context, |
||
31 | StatementsSource $statements_source, |
||
32 | Codebase $codebase, |
||
33 | array &$file_replacements = [], |
||
34 | Union &$return_type_candidate = null |
||
35 | ) { |
||
36 | if (!self::isMethodWeWant($declaring_method_id, $codebase)) { |
||
37 | return; |
||
38 | } |
||
39 | |||
40 | $message = sprintf("Found reference to %s\n", |
||
41 | self::getFindName() |
||
42 | ); |
||
43 | |||
44 | if (IssueBuffer::accepts( |
||
45 | new ClassMethodUsageFound( |
||
46 | $message, |
||
47 | new CodeLocation($statements_source, $expr->name) |
||
48 | ), |
||
49 | $statements_source->getSuppressedIssues() |
||
50 | )) { |
||
51 | // fall through |
||
52 | } |
||
53 | } |
||
54 | |||
55 | private static function isMethodWeWant(string $declaring_method_id, Codebase $codebase) : bool |
||
56 | { |
||
57 | list($className, $methodName) = explode('::', $declaring_method_id); |
||
58 | |||
59 | if ($declaring_method_id === self::getFindName()) { |
||
60 | return true; |
||
61 | } |
||
62 | |||
63 | if ($methodName === self::getFindMethodName() |
||
64 | && $codebase->classImplements($className, self::getFindClassName())) { |
||
65 | return true; |
||
66 | } |
||
67 | |||
68 | return false; |
||
69 | } |
||
70 | |||
71 | private static function getFindName() : string |
||
72 | { |
||
73 | return 'Doctrine\Common\Collections\Collection::slice'; |
||
74 | |||
75 | // return self::$classMethodReference->getName(); |
||
76 | } |
||
77 | |||
78 | private static function getFindClassName() : string |
||
79 | { |
||
80 | return 'Doctrine\Common\Collections\Collection'; |
||
81 | |||
82 | // return self::$classMethodReference->getClassName(); |
||
83 | } |
||
84 | |||
85 | private static function getFindMethodName() : string |
||
86 | { |
||
87 | return 'slice'; |
||
88 | |||
89 | // self::$classMethodReference->getMethodName() |
||
90 | } |
||
91 | } |
||
92 |
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