Completed
Push — statistics_refactoring ( b2d9c2 )
by Luis
13:39
created

Attribute::isTyped()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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
    public $modifier;
19
20
    protected function __construct(string $name, Visibility $modifier, TypeDeclaration $type)
21
    {
22
        parent::__construct($name, $type);
23
        $this->modifier = $modifier;
24
    }
25
26
    public static function public(string $name, TypeDeclaration $type = null): Attribute
27
    {
28
        return new Attribute($name, Visibility::public(), $type ?? TypeDeclaration::absent());
29
    }
30
31
    public static function protected(string $name, TypeDeclaration $type = null): Attribute
32
    {
33
        return new Attribute($name, Visibility::protected(), $type ?? TypeDeclaration::absent());
34
    }
35
36
    public static function private(string $name, TypeDeclaration $type = null): Attribute
37
    {
38
        return new Attribute($name, Visibility::private(), $type ?? TypeDeclaration::absent());
39
    }
40
41
    public function isTyped(): bool
42
    {
43
        return $this->type->isPresent();
44
    }
45
46
    /**
47
     * It doesn't currently support information type
48
     *
49
     * @see GraphvizProcessor#getClassDefinition In its original version
50
     */
51
    public function __toString()
52
    {
53
        return sprintf('%s%s', $this->modifier, $this->name);
54
    }
55
}
56