Test Failed
Push — master ( 3b7232...dbe410 )
by Kirill
02:20
created

ArgumentDefinition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 44.44%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 75
ccs 8
cts 18
cp 0.4444
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getType() 0 4 1
A getDefaultValue() 0 4 1
A withDefaultValue() 0 7 1
A hasDefaultValue() 0 4 1
A withoutDefaultValue() 0 7 1
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Reflection\Definition\Dependent;
11
12
use Railt\Reflection\Contracts\Definition\Dependent\ArgumentDefinition as ArgumentDefinitionInterface;
13
use Railt\Reflection\Contracts\Definition\TypeDefinition;
14
use Railt\Reflection\Contracts\Type as TypeInterface;
15
use Railt\Reflection\Definition\Behaviour\HasTypeIndication;
16
use Railt\Reflection\Document;
17
use Railt\Reflection\Type;
18
19
/**
20
 * Class ArgumentDefinition
21
 */
22
class ArgumentDefinition extends AbstractDependentTypeDefinition implements ArgumentDefinitionInterface
23
{
24
    use HasTypeIndication;
25
26
    /**
27
     * @var mixed
28
     */
29
    protected $defaultValue;
30
31
    /**
32
     * @var bool
33
     */
34
    protected $hasDefaultValue = false;
35
36
    /**
37
     * ArgumentDefinition constructor.
38
     * @param TypeDefinition $parent
39
     * @param Document $document
40
     * @param string $name
41
     * @param string $type
42
     */
43 9
    public function __construct(TypeDefinition $parent, Document $document, string $name, string $type)
44
    {
45 9
        parent::__construct($parent, $document, $name);
46
47 9
        $this->withTypeDefinition($type);
48 9
    }
49
50
    /**
51
     * @return TypeInterface
52
     */
53
    public static function getType(): TypeInterface
54
    {
55
        return Type::of(Type::ARGUMENT);
56
    }
57
58
    /**
59
     * @return mixed
60
     */
61
    public function getDefaultValue()
62
    {
63
        return $this->defaultValue;
64
    }
65
66
    /**
67
     * @param mixed $value
68
     * @return ArgumentDefinitionInterface|$this
69
     */
70 9
    public function withDefaultValue($value): ArgumentDefinitionInterface
71
    {
72 9
        $this->defaultValue    = $value;
73 9
        $this->hasDefaultValue = true;
74
75 9
        return $this;
76
    }
77
78
    /**
79
     * @return bool
80
     */
81
    public function hasDefaultValue(): bool
82
    {
83
        return $this->hasDefaultValue;
84
    }
85
86
    /**
87
     * @return ArgumentDefinitionInterface
88
     */
89
    public function withoutDefaultValue(): ArgumentDefinitionInterface
90
    {
91
        $this->defaultValue    = null;
92
        $this->hasDefaultValue = false;
93
94
        return $this;
95
    }
96
}
97