ConditionTrait::else()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dgame\Expectation;
4
5
/**
6
 * Trait ConditionTrait
7
 * @package Dgame\Expectation
8
 */
9
trait ConditionTrait
10
{
11
    /**
12
     * @var mixed
13
     */
14
    protected $value;
15
    /**
16
     * @var bool
17
     */
18
    private $approved = true;
19
20
    /**
21
     * @param bool $condition
22
     *
23
     * @return $this
24
     */
25 37
    final protected function approveIf(bool $condition): self
26
    {
27 37
        $this->approved = $this->approved && $condition;
28
29 37
        return $this;
30
    }
31
32
    /**
33
     * @return bool
34
     */
35 37
    public function isApproved(): bool
36
    {
37 37
        return $this->approved;
38
    }
39
40
    /**
41
     * @param mixed $value
42
     *
43
     * @return mixed
44
     */
45 1
    public function then($value)
46
    {
47 1
        return $this->isApproved() ? $value : $this->value;
48
    }
49
50
    /**
51
     * @param mixed $default
52
     *
53
     * @return mixed
54
     */
55
    public function else($default)
56
    {
57
        return $this->isApproved() ? $this->value : $default;
58
    }
59
}
60