Passed
Push — trunk ( 516571...cb9bb6 )
by Christian
10:00 queued 11s
created

NoSuperGlobalsInsideCompilerPassRule   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 33
rs 10
c 1
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A processNode() 0 21 5
A getNodeType() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules;
4
5
use PhpParser\Node;
6
use PhpParser\Node\Expr\ArrayDimFetch;
7
use PHPStan\Analyser\Scope;
0 ignored issues
show
Bug introduced by
The type PHPStan\Analyser\Scope 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...
8
use PHPStan\Rules\Rule;
0 ignored issues
show
Bug introduced by
The type PHPStan\Rules\Rule 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 PHPStan\Rules\RuleError;
0 ignored issues
show
Bug introduced by
The type PHPStan\Rules\RuleError 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 Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
11
12
/**
13
 * @internal
14
 *
15
 * @implements Rule<ArrayDimFetch>
16
 */
17
class NoSuperGlobalsInsideCompilerPassRule implements Rule
18
{
19
    public function getNodeType(): string
20
    {
21
        return ArrayDimFetch::class;
22
    }
23
24
    /**
25
     * @param ArrayDimFetch $node
26
     *
27
     * @return array<array-key, RuleError|string>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<array-key, RuleError|string> at position 2 could not be parsed: Unknown type name 'array-key' at position 2 in array<array-key, RuleError|string>.
Loading history...
28
     */
29
    public function processNode(Node $node, Scope $scope): array
30
    {
31
        $class = $scope->getClassReflection();
32
33
        if ($class === null) {
34
            return [];
35
        }
36
37
        if (!$class->implementsInterface(CompilerPassInterface::class)) {
38
            return [];
39
        }
40
41
        if (!$node->var instanceof Node\Expr\Variable) {
0 ignored issues
show
Bug introduced by
Accessing var on the interface PhpParser\Node suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
42
            return [];
43
        }
44
45
        if (!\in_array($node->var->name, ['_GET', '_POST', '_COOKIE', '_SERVER', '_FILES', '_REQUEST'], true)) {
46
            return [];
47
        }
48
49
        return ['Do not use super globals inside compiler passes.'];
50
    }
51
}
52