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

HasDefaultValue   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 33.33%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 51
ccs 4
cts 12
cp 0.3333
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
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\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