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 ( 57ffc6...e4cea5 )
by Gytis
02:04
created

FqcnPropSniff::process()   B

Complexity

Conditions 10
Paths 24

Size

Total Lines 50
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 36
CRAP Score 10

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 10
eloc 35
nc 24
nop 2
dl 0
loc 50
ccs 36
cts 36
cp 1
crap 10
rs 7.6666
c 3
b 0
f 1

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