GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 368282...c4d7dc )
by Gytis
03:56
created

FqcnConstSniff::process()   A

Complexity

Conditions 6
Paths 10

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 16
nc 10
nop 2
dl 0
loc 28
ccs 0
cts 21
cp 0
crap 42
rs 9.1111
c 0
b 0
f 0
1
<?php
2
3
namespace Gskema\TypeSniff\Sniffs\CodeElement;
4
5
use PHP_CodeSniffer\Files\File;
6
use Gskema\TypeSniff\Core\CodeElement\Element\AbstractFqcnConstElement;
7
use Gskema\TypeSniff\Core\CodeElement\Element\ClassConstElement;
8
use Gskema\TypeSniff\Core\CodeElement\Element\CodeElementInterface;
9
use Gskema\TypeSniff\Core\CodeElement\Element\InterfaceConstElement;
10
use Gskema\TypeSniff\Core\DocBlock\Tag\VarTag;
11
use Gskema\TypeSniff\Core\DocBlock\UndefinedDocBlock;
12
use Gskema\TypeSniff\Core\Type\Common\ArrayType;
13
14
class FqcnConstSniff implements CodeElementSniffInterface
15
{
16
    /**
17
     * @inheritDoc
18
     */
19
    public function configure(array $config): void
20
    {
21
        // nothing to do
22
    }
23
24
    /**
25
     * @inheritDoc
26
     */
27
    public function register(): array
28
    {
29
        return [
30
            ClassConstElement::class,
31
            InterfaceConstElement::class,
32
        ];
33
    }
34
35
    /**
36
     * @inheritDoc
37
     *
38
     * @param AbstractFqcnConstElement $const
39
     */
40
    public function process(File $file, CodeElementInterface $const): void
41
    {
42
        // @TODO Infer type from value?
43
        $docBlock = $const->getDocBlock();
44
45
        /** @var VarTag|null $varTag */
46
        $varTag = $docBlock->getTagsByName('var')[0] ?? null;
47
        $varType = $varTag ? $varTag->getType() : null;
48
49
        // PHPDoc for const are usually not necessary.
50
        if ($docBlock instanceof UndefinedDocBlock) {
51
            return;
52
        }
53
54
        if ($varType instanceof ArrayType) {
55
            $subject = $const->getConstName().' constant';
56
            $file->addWarningOnLine(
57
                'Replace array type with typed array type in PHPDoc for '.$subject.'. Use mixed[] for generic arrays.',
58
                $const->getLine(),
59
                'FqcnPropSniff'
60
            );
61
        }
62
63
        if ($varTag && null !== $varTag->getParamName()) {
64
            $file->addWarningOnLine(
65
                'Remove property name $'.$varTag->getParamName().' from @var tag',
66
                $const->getLine(),
67
                'FqcnPropSniff'
68
            );
69
        }
70
    }
71
}
72