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 ( 3e29f4...a0257c )
by Gytis
03:40 queued 11s
created

FqcnConstSniff   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 20
dl 0
loc 58
ccs 22
cts 22
cp 1
rs 10
c 2
b 0
f 1
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 2 1
A register() 0 5 1
A process() 0 13 1
B reportUselessDocBlock() 0 15 7
1
<?php
2
3
namespace Gskema\TypeSniff\Sniffs\CodeElement;
4
5
use Gskema\TypeSniff\Core\DocBlock\Tag\VarTag;
6
use Gskema\TypeSniff\Inspection\DocTypeInspector;
7
use Gskema\TypeSniff\Inspection\Subject\ConstTypeSubject;
8
use PHP_CodeSniffer\Files\File;
9
use Gskema\TypeSniff\Core\CodeElement\Element\AbstractFqcnConstElement;
10
use Gskema\TypeSniff\Core\CodeElement\Element\ClassConstElement;
11
use Gskema\TypeSniff\Core\CodeElement\Element\CodeElementInterface;
12
use Gskema\TypeSniff\Core\CodeElement\Element\InterfaceConstElement;
13
14
class FqcnConstSniff implements CodeElementSniffInterface
15
{
16
    protected const CODE = 'FqcnConstSniff';
17
18
    /**
19
     * @inheritDoc
20
     */
21 6
    public function configure(array $config): void
22
    {
23
        // nothing to do
24 6
    }
25
26
    /**
27
     * @inheritDoc
28
     */
29 6
    public function register(): array
30
    {
31
        return [
32 6
            ClassConstElement::class,
33
            InterfaceConstElement::class,
34
        ];
35
    }
36
37
    /**
38
     * @inheritDoc
39
     *
40
     * @param AbstractFqcnConstElement $const
41
     */
42 2
    public function process(File $file, CodeElementInterface $const): void
43
    {
44 2
        $subject = ConstTypeSubject::fromElement($const);
45
46 2
        DocTypeInspector::reportMandatoryTypes($subject);
47 2
        DocTypeInspector::reportReplaceableTypes($subject);
48
49 2
        DocTypeInspector::reportRemovableTypes($subject);
50 2
        DocTypeInspector::reportMissingOrWrongTypes($subject);
51
52 2
        static::reportUselessDocBlock($subject);
53
54 2
        $subject->writeWarningsTo($file, static::CODE);
55 2
    }
56
57 2
    protected static function reportUselessDocBlock(ConstTypeSubject $subject): void
58
    {
59 2
        if (!$subject->hasDefinedDocBlock()) {
60 1
            return;
61
        }
62
63
        /** @var VarTag|null $varTag */
64 2
        $varTag = $subject->getDocBlock()->getTagsByName('var')[0] ?? null;
65
66 2
        $isUseful = $subject->getDocBlock()->hasDescription()
67 2
            || ($varTag && $varTag->hasDescription())
68 2
            || ($varTag && $varTag->getType() != $subject->getValueType());
69
70 2
        if (!$isUseful) {
71 1
            $subject->addFnTypeWarning('Useless PHPDoc');
72
        }
73 2
    }
74
}
75