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   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 54
ccs 0
cts 31
cp 0
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 28 6
A configure() 0 2 1
A register() 0 5 1
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