Passed
Push — master ( 8d387d...2ce63d )
by Luis
03:13
created

Attribute   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A protected() 0 3 1
A __toString() 0 6 2
A __construct() 0 5 1
A private() 0 3 1
A public() 0 3 1
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;
9
10
/**
11
 * It represents a class attribute
12
 */
13
class Attribute extends Variable implements HasVisibility, CanBeStatic
14
{
15
    use WithVisibility, WithStaticModifier;
16
17 96
    protected function __construct(string $name, Visibility $modifier, TypeDeclaration $type)
18
    {
19 96
        parent::__construct($name, $type);
20 96
        $this->modifier = $modifier;
21 96
        $this->isStatic = false;
22 96
    }
23
24 60
    public static function public(string $name, TypeDeclaration $type = null): Attribute
25
    {
26 60
        return new static($name, Visibility::public(), $type ?? TypeDeclaration::absent());
27
    }
28
29 48
    public static function protected(string $name, TypeDeclaration $type = null): Attribute
30
    {
31 48
        return new static($name, Visibility::protected(), $type ?? TypeDeclaration::absent());
32
    }
33
34 72
    public static function private(string $name, TypeDeclaration $type = null): Attribute
35
    {
36 72
        return new static($name, Visibility::private(), $type ?? TypeDeclaration::absent());
37
    }
38
39 42
    public function __toString()
40
    {
41 42
        return sprintf('%s%s%s',
42 42
            $this->modifier,
43 42
            $this->name,
44 42
            $this->type->isPresent() ? ": {$this->type}" : ''
45
        );
46
    }
47
}
48