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

ConstTypeSubject::fromElement()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
nc 1
nop 1
dl 0
loc 14
ccs 10
cts 10
cp 1
crap 3
rs 9.9666
c 1
b 0
f 0
1
<?php
2
3
namespace Gskema\TypeSniff\Inspection\Subject;
4
5
use Gskema\TypeSniff\Core\CodeElement\Element\AbstractFqcnConstElement;
6
use Gskema\TypeSniff\Core\DocBlock\DocBlock;
7
use Gskema\TypeSniff\Core\DocBlock\Tag\VarTag;
8
use Gskema\TypeSniff\Core\Type\Common\UndefinedType;
9
use Gskema\TypeSniff\Core\Type\TypeInterface;
10
11
class ConstTypeSubject extends AbstractTypeSubject
12
{
13 2
    public function __construct(
14
        ?TypeInterface $docType,
15
        ?TypeInterface $valueType,
16
        ?int $docTypeLine,
17
        int $fnTypeLine,
18
        string $name,
19
        DocBlock $docBlock
20
    ) {
21 2
        parent::__construct(
22 2
            $docType,
23 2
            new UndefinedType(), // not in PHP 7.4 :(
24 2
            $valueType,
25 2
            $docTypeLine,
26 2
            $fnTypeLine,
27 2
            $name,
28 2
            $docBlock
29
        );
30 2
    }
31
32
    /**
33
     * @param AbstractFqcnConstElement $const
34
     *
35
     * @return static
36
     */
37 2
    public static function fromElement(AbstractFqcnConstElement $const)
38
    {
39 2
        $docBlock = $const->getDocBlock();
40
41
        /** @var VarTag|null $varTag */
42 2
        $varTag = $docBlock->getTagsByName('var')[0] ?? null;
43
44 2
        return new static(
45 2
            $varTag ? $varTag->getType() : null,
46 2
            $const->getValueType(),
47 2
            $varTag ? $varTag->getLine() : null,
48 2
            $const->getLine(),
49 2
            $const->getConstName().' constant',
50 2
            $docBlock
51
        );
52
    }
53
}
54