Passed
Push — github-funding ( a9bfc9 )
by Jonathan
13:50
created

afterMethodCallAnalysis()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 26
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 26
rs 9.9666
c 0
b 0
f 0
cc 3
nc 3
nop 9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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
Bug introduced by
The type Psalm\CodeLocation 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Psalm\Codebase;
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Psalm\Context;
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Psalm\FileManipulation;
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Psalm\IssueBuffer;
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Psalm\Issue\PluginIssue;
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Psalm\Plugin\Hook\AfterMethodCallAnalysisInterface;
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Psalm\StatementsSource;
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Psalm\Type\Union;
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use UsageFinder\ClassMethodReference;
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use UsageFinder\Issue\ClassMethodUsageFound;
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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