Completed
Push — master ( 3e29f4...a0257c )
by Gytis
03:40 queued 11s
created

FqcnPropSniff::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 8
Bugs 0 Features 1
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 12
ccs 8
cts 8
cp 1
crap 1
rs 10
c 8
b 0
f 1
1
<?php
2
3
namespace Gskema\TypeSniff\Sniffs\CodeElement;
4
5
use Gskema\TypeSniff\Inspection\DocTypeInspector;
6
use Gskema\TypeSniff\Inspection\Subject\PropTypeSubject;
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
13
class FqcnPropSniff implements CodeElementSniffInterface
14
{
15
    protected const CODE = 'FqcnPropSniff';
16
17
    /**
18
     * @inheritDoc
19
     */
20 6
    public function configure(array $config): void
21
    {
22
        // nothing to do
23 6
    }
24
25
    /**
26
     * @inheritDoc
27
     */
28 6
    public function register(): array
29
    {
30
        return [
31 6
            ClassPropElement::class,
32
            TraitPropElement::class,
33
        ];
34
    }
35
36
    /**
37
     * @inheritDoc
38
     * @param AbstractFqcnPropElement $prop
39
     */
40 4
    public function process(File $file, CodeElementInterface $prop): void
41
    {
42 4
        $subject = PropTypeSubject::fromElement($prop);
43
44 4
        DocTypeInspector::reportMandatoryTypes($subject);
45 4
        DocTypeInspector::reportReplaceableTypes($subject);
46 4
        DocTypeInspector::reportRemovableTypes($subject);
47 4
        DocTypeInspector::reportMissingOrWrongTypes($subject);
48
49 4
        static::reportInvalidDescription($subject);
50
51 4
        $subject->writeWarningsTo($file, static::CODE);
52 4
    }
53
54 4
    protected static function reportInvalidDescription(PropTypeSubject $subject): void
55
    {
56 4
        $varTag = $subject->getDocBlock()->getTagsByName('var')[0] ?? null;
57
58 4
        if ($varTag && null !== $varTag->getParamName()) {
59 1
            $subject->addDocTypeWarning('Remove property name $'.$varTag->getParamName().' from @var tag');
60
        }
61 4
    }
62
}
63