Completed
Push — master ( 716959...c2acd0 )
by Luis
04:37 queued 02:39
created

Attribute::modifier()   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 0
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;
9
10
/**
11
 * It represents a class attribute
12
 *
13
 * It does not distinguish yet static attributes
14
 */
15
class Attribute extends Variable
16
{
17
    /** @var Visibility */
18
    private $modifier;
19
20 81
    protected function __construct(string $name, Visibility $modifier, TypeDeclaration $type)
21
    {
22 81
        parent::__construct($name, $type);
23 81
        $this->modifier = $modifier;
24 81
    }
25
26 51
    public static function public(string $name, TypeDeclaration $type = null): Attribute
27
    {
28 51
        return new Attribute($name, Visibility::public(), $type ?? TypeDeclaration::absent());
29
    }
30
31 42
    public static function protected(string $name, TypeDeclaration $type = null): Attribute
32
    {
33 42
        return new Attribute($name, Visibility::protected(), $type ?? TypeDeclaration::absent());
34
    }
35
36 60
    public static function private(string $name, TypeDeclaration $type = null): Attribute
37
    {
38 60
        return new Attribute($name, Visibility::private(), $type ?? TypeDeclaration::absent());
39
    }
40
41 12
    public function isTyped(): bool
42
    {
43 12
        return $this->type->isPresent();
44
    }
45
46 12
    public function hasVisibility(Visibility $modifier): bool
47
    {
48 12
        return $this->modifier()->equals($modifier);
49
    }
50
51 21
    public function modifier(): Visibility
52
    {
53 21
        return $this->modifier;
54
    }
55
56
    /**
57
     * It doesn't currently support information type
58
     *
59
     * @see GraphvizProcessor#getClassDefinition In its original version
60
     */
61 24
    public function __toString()
62
    {
63 24
        return sprintf('%s%s', $this->modifier, $this->name);
64
    }
65
}
66