Completed
Push — master ( 389baa...c7c5a4 )
by Luis
14:17 queued 08:06
created

AttributeDocBlock::from()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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\Variables\TypeDeclaration;
12
13
/**
14
 * It creates a type declaration for an attribute from its `@var` tag
15
 */
16
class AttributeDocBlock extends DocBlock
17
{
18
    /** @var string */
19
    private static $varExpression = '/@var\s*([\w]+(\[\])?)/';
20
21 66
    public static function from(string $text): AttributeDocBlock
22
    {
23 66
        return new AttributeDocBlock($text);
24
    }
25
26 66
    public function extractType(): TypeDeclaration
27
    {
28 66
        $type = null;
29 66
        if (preg_match(self::$varExpression, $this->comment, $matches)) {
30 63
            $type = trim($matches[1]);
31
        }
32 66
        return TypeDeclaration::from($type);
33
    }
34
}
35