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::process()   B

Complexity

Conditions 10
Paths 20

Size

Total Lines 43
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 110

Importance

Changes 0
Metric Value
cc 10
eloc 30
nc 20
nop 2
dl 0
loc 43
ccs 0
cts 38
cp 0
crap 110
rs 7.6666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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