Completed
Push — master ( 2ce63d...389baa )
by Luis
11:05 queued 03:24
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 private() 0 3 1
A public() 0 3 1
A __construct() 0 5 1
A protected() 0 3 1
A __toString() 0 6 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\CanBeStatic;
11
use PhUml\Code\HasVisibility;
12
use PhUml\Code\TypeDeclaration;
13
use PhUml\Code\Variable;
14
use PhUml\Code\Visibility;
15
use PhUml\Code\WithStaticModifier;
16
use PhUml\Code\WithVisibility;
17
18
/**
19
 * It represents an instance variable
20
 */
21
class Attribute extends Variable implements HasVisibility, CanBeStatic
22
{
23
    use WithVisibility, WithStaticModifier;
24
25 96
    protected function __construct(string $name, Visibility $modifier, TypeDeclaration $type)
26
    {
27 96
        parent::__construct($name, $type);
28 96
        $this->modifier = $modifier;
29 96
        $this->isStatic = false;
30 96
    }
31
32 60
    public static function public(string $name, TypeDeclaration $type = null): Attribute
33
    {
34 60
        return new static($name, Visibility::public(), $type ?? TypeDeclaration::absent());
35
    }
36
37 48
    public static function protected(string $name, TypeDeclaration $type = null): Attribute
38
    {
39 48
        return new static($name, Visibility::protected(), $type ?? TypeDeclaration::absent());
40
    }
41
42 72
    public static function private(string $name, TypeDeclaration $type = null): Attribute
43
    {
44 72
        return new static($name, Visibility::private(), $type ?? TypeDeclaration::absent());
45
    }
46
47 42
    public function __toString()
48
    {
49 42
        return sprintf('%s%s%s',
50 42
            $this->modifier,
51 42
            $this->name,
52 42
            $this->type->isPresent() ? ": {$this->type}" : ''
53
        );
54
    }
55
}
56