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

FqcnPropSniff   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 68
ccs 0
cts 48
cp 0
rs 10
c 0
b 0
f 0
wmc 12

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 2 1
A register() 0 5 1
B process() 0 43 10
1
<?php
2
3
namespace Gskema\TypeSniff\Sniffs\CodeElement;
4
5
use PHP_CodeSniffer\Files\File;
6
use Gskema\TypeSniff\Core\CodeElement\Element\AbstractFqcnPropElement;
7
use Gskema\TypeSniff\Core\CodeElement\Element\ClassPropElement;
8
use Gskema\TypeSniff\Core\CodeElement\Element\CodeElementInterface;
9
use Gskema\TypeSniff\Core\CodeElement\Element\TraitPropElement;
10
use Gskema\TypeSniff\Core\DocBlock\Tag\VarTag;
11
use Gskema\TypeSniff\Core\DocBlock\UndefinedDocBlock;
12
use Gskema\TypeSniff\Core\Type\Common\ArrayType;
13
use Gskema\TypeSniff\Core\Type\Common\UndefinedType;
14
use Gskema\TypeSniff\Core\Type\DocBlock\CompoundType;
15
16
class FqcnPropSniff implements CodeElementSniffInterface
17
{
18
    /**
19
     * @inheritDoc
20
     */
21
    public function configure(array $config): void
22
    {
23
        // nothing to do
24
    }
25
26
    /**
27
     * @inheritDoc
28
     */
29
    public function register(): array
30
    {
31
        return [
32
            ClassPropElement::class,
33
            TraitPropElement::class,
34
        ];
35
    }
36
37
    /**
38
     * @inheritDoc
39
     * @param AbstractFqcnPropElement $prop
40
     */
41
    public function process(File $file, CodeElementInterface $prop): void
42
    {
43
        // @TODO Infer type from initial value?
44
        $docBlock = $prop->getDocBlock();
45
46
        /** @var VarTag|null $varTag */
47
        $varTag = $docBlock->getTagsByName('var')[0] ?? null;
48
        $varType = $varTag ? $varTag->getType() : null;
49
50
        if ($docBlock instanceof UndefinedDocBlock) {
51
            $file->addWarningOnLine(
52
                'Add PHPDoc for property $'.$prop->getPropName(),
53
                $prop->getLine(),
54
                'FqcnPropSniff'
55
            );
56
        } elseif (null === $varTag) {
57
            $file->addWarningOnLine(
58
                'Add @var tag for property $'.$prop->getPropName(),
59
                $prop->getLine(),
60
                'FqcnPropSniff'
61
            );
62
        } elseif ($varType instanceof UndefinedType) {
63
            $file->addWarningOnLine(
64
                'Add type hint to @var tag for property $'.$prop->getPropName(),
65
                $prop->getLine(),
66
                'FqcnPropSniff'
67
            );
68
        } elseif ($varType instanceof ArrayType
69
              || ($varType instanceof CompoundType && $varType->containsType(ArrayType::class))
70
        ) {
71
            $subject = '$'.$prop->getPropName();
72
            $file->addWarningOnLine(
73
                'Replace array type with typed array type in PHPDoc for '.$subject.'. Use mixed[] for generic arrays.',
74
                $prop->getLine(),
75
                'FqcnPropSniff'
76
            );
77
        }
78
79
        if ($varTag && null !== $varTag->getParamName()) {
80
            $file->addWarningOnLine(
81
                'Remove property name $'.$varTag->getParamName().' from @var tag',
82
                $prop->getLine(),
83
                'FqcnPropSniff'
84
            );
85
        }
86
    }
87
}
88