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

Attribute   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A protected() 0 3 1
A isTyped() 0 3 1
A __toString() 0 3 1
A __construct() 0 4 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
 * 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