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

AttributeDocBlock::extractType()   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\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