Completed
Push — master ( 2ce63d...389baa )
by Luis
11:05 queued 03:24
created

AttributeDocBlock::getType()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Code\Attributes;
9
10
use PhUml\Code\DocBlock;
11
use PhUml\Code\TypeDeclaration;
12
13
/**
14
 * It used to create a type declaration for the attribute
15
 */
16
class AttributeDocBlock extends DocBlock
17
{
18
    private static $varExpression = '/@var\s*([\w]+(\[\])?)/';
19
20 54
    public static function from(string $text): AttributeDocBlock
21
    {
22 54
        return new AttributeDocBlock($text);
23
    }
24
25 54
    public function getType(): TypeDeclaration
26
    {
27 54
        $type = null;
28 54
        if (preg_match(self::$varExpression, $this->comment, $matches)) {
29 51
            $type = trim($matches[1]);
30
        }
31 54
        return TypeDeclaration::from($type);
32
    }
33
}
34