Completed
Push — master ( 9d6b90...0a141c )
by Randy
11:08
created

ConditionTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A approveIf() 0 6 2
A isApproved() 0 4 1
A then() 0 4 2
A else() 0 4 2
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
    final protected function approveIf(bool $condition)
26
    {
27
        $this->approved = $this->approved && $condition;
28
29
        return $this;
30
    }
31
32
    /**
33
     * @return bool
34
     */
35
    public function isApproved(): bool
36
    {
37
        return $this->approved;
38
    }
39
40
    /**
41
     * @param $value
42
     *
43
     * @return mixed
44
     */
45
    public function then($value)
46
    {
47
        return $this->isApproved() ? $value : $this->value;
48
    }
49
50
    /**
51
     * @param $default
52
     *
53
     * @return mixed
54
     */
55
    public function else($default)
0 ignored issues
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
56
    {
57
        return $this->isApproved() ? $this->value : $default;
58
    }
59
}