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

Attribute::isTyped()   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
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