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

ArgumentDefinition::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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