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

AttributeDocBlock   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A from() 0 3 1
A extractType() 0 7 2
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