Test Failed
Push — master ( dbe410...b8c007 )
by Kirill
02:19
created

HasDefaultValue::getDefaultValue()   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\Behaviour;
11
12
use Railt\Reflection\Contracts\Definition\Behaviour\ProvidesDefaultValue;
13
14
/**
15
 * Trait HasDefaultValue
16
 * @mixin ProvidesDefaultValue
17
 */
18
trait HasDefaultValue
19
{
20
    /**
21
     * @var mixed
22
     */
23
    protected $defaultValue;
24
25
    /**
26
     * @var bool
27
     */
28
    protected $hasDefaultValue = false;
29
30
    /**
31
     * @return mixed
32
     */
33
    public function getDefaultValue()
34
    {
35
        return $this->defaultValue;
36
    }
37
38
    /**
39
     * @param mixed $value
40
     * @return ProvidesDefaultValue|$this
41
     */
42 9
    public function withDefaultValue($value): ProvidesDefaultValue
43
    {
44 9
        $this->defaultValue = $value;
45 9
        $this->hasDefaultValue = true;
46
47 9
        return $this;
48
    }
49
50
    /**
51
     * @return bool
52
     */
53
    public function hasDefaultValue(): bool
54
    {
55
        return $this->hasDefaultValue;
56
    }
57
58
    /**
59
     * @return ProvidesDefaultValue|$this
60
     */
61
    public function withoutDefaultValue(): ProvidesDefaultValue
62
    {
63
        $this->defaultValue = null;
64
        $this->hasDefaultValue = false;
65
66
        return $this;
67
    }
68
}
69