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.
Passed
Push — master ( 47e701...44fa06 )
by Gytis
03:06
created

FqcnPropSniff   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 40
dl 0
loc 77
ccs 41
cts 41
cp 1
rs 10
c 0
b 0
f 0
wmc 14

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 2 1
A register() 0 5 1
C process() 0 52 12
1
<?php
2
3
namespace Gskema\TypeSniff\Sniffs\CodeElement;
4
5
use Gskema\TypeSniff\Core\Type\DocBlock\TypedArrayType;
6
use PHP_CodeSniffer\Files\File;
7
use Gskema\TypeSniff\Core\CodeElement\Element\AbstractFqcnPropElement;
8
use Gskema\TypeSniff\Core\CodeElement\Element\ClassPropElement;
9
use Gskema\TypeSniff\Core\CodeElement\Element\CodeElementInterface;
10
use Gskema\TypeSniff\Core\CodeElement\Element\TraitPropElement;
11
use Gskema\TypeSniff\Core\DocBlock\Tag\VarTag;
12
use Gskema\TypeSniff\Core\DocBlock\UndefinedDocBlock;
13
use Gskema\TypeSniff\Core\Type\Common\ArrayType;
14
use Gskema\TypeSniff\Core\Type\Common\UndefinedType;
15
use Gskema\TypeSniff\Core\Type\DocBlock\CompoundType;
16
17
class FqcnPropSniff implements CodeElementSniffInterface
18
{
19
    /**
20
     * @inheritDoc
21
     */
22 2
    public function configure(array $config): void
23
    {
24
        // nothing to do
25 2
    }
26
27
    /**
28
     * @inheritDoc
29
     */
30 2
    public function register(): array
31
    {
32
        return [
33 2
            ClassPropElement::class,
34
            TraitPropElement::class,
35
        ];
36
    }
37
38
    /**
39
     * @inheritDoc
40
     * @param AbstractFqcnPropElement $prop
41
     */
42 1
    public function process(File $file, CodeElementInterface $prop): void
43
    {
44
        // @TODO Infer type from initial value?
45 1
        $docBlock = $prop->getDocBlock();
46
47
        /** @var VarTag|null $varTag */
48 1
        $varTag = $docBlock->getTagsByName('var')[0] ?? null;
49 1
        $docType = $varTag ? $varTag->getType() : null;
50
51 1
        $subject = 'property $'.$prop->getPropName();
1 ignored issue
show
Bug introduced by
The method getPropName() does not exist on Gskema\TypeSniff\Core\Co...nt\CodeElementInterface. It seems like you code against a sub-type of Gskema\TypeSniff\Core\Co...nt\CodeElementInterface such as Gskema\TypeSniff\Core\Co...AbstractFqcnPropElement. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $subject = 'property $'.$prop->/** @scrutinizer ignore-call */ getPropName();
Loading history...
52
53 1
        if ($docBlock instanceof UndefinedDocBlock) {
54 1
            $file->addWarningOnLine(
55 1
                'Add PHPDoc for '.$subject,
56 1
                $prop->getLine(),
57 1
                'FqcnPropSniff'
58
            );
59 1
        } elseif (null === $varTag) {
60 1
            $file->addWarningOnLine(
61 1
                'Add @var tag for '.$subject,
62 1
                $prop->getLine(),
63 1
                'FqcnPropSniff'
64
            );
65 1
        } elseif ($docType instanceof UndefinedType) {
66 1
            $file->addWarningOnLine(
67 1
                'Add type hint to @var tag for '.$subject,
68 1
                $prop->getLine(),
69 1
                'FqcnPropSniff'
70
            );
71 1
        } elseif ($docType instanceof ArrayType
72 1
              || ($docType instanceof CompoundType && $docType->containsType(ArrayType::class))
73
        ) {
74 1
            $file->addWarningOnLine(
75 1
                'Replace array type with typed array type in PHPDoc for '.$subject.'. Use mixed[] for generic arrays.',
76 1
                $prop->getLine(),
77 1
                'FqcnPropSniff'
78
            );
79 1
        } elseif (is_a($prop->getDefaultValueType(), ArrayType::class)
1 ignored issue
show
Bug introduced by
The method getDefaultValueType() does not exist on Gskema\TypeSniff\Core\Co...nt\CodeElementInterface. It seems like you code against a sub-type of Gskema\TypeSniff\Core\Co...nt\CodeElementInterface such as Gskema\TypeSniff\Core\Co...AbstractFqcnPropElement. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

79
        } elseif (is_a($prop->/** @scrutinizer ignore-call */ getDefaultValueType(), ArrayType::class)
Loading history...
80 1
              && !is_a($docType, TypedArrayType::class)
81
        ) {
82 1
            $file->addWarningOnLine(
83 1
                'Add PHPDoc with typed array type hint for '.$subject.'. Use mixed[] for generic arrays.',
84 1
                $prop->getLine(),
85 1
                'FqcnPropSniff'
86
            );
87
        }
88
89 1
        if ($varTag && null !== $varTag->getParamName()) {
90 1
            $file->addWarningOnLine(
91 1
                'Remove property name $'.$varTag->getParamName().' from @var tag',
92 1
                $prop->getLine(),
93 1
                'FqcnPropSniff'
94
            );
95
        }
96 1
    }
97
}
98