Completed
Pull Request — master (#18)
by Randy
01:46
created

JSendStatusTrait   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getStatus() 0 4 1
A isFail() 0 4 1
A isSuccess() 0 4 1
A isError() 0 4 1
A onSuccess() 0 10 2
A onFail() 0 10 2
A onError() 0 10 2
1
<?php
2
3
namespace Demv\JSend;
4
5
/**
6
 * Trait JSendStatusTrait
7
 * @package Demv\JSend
8
 */
9
trait JSendStatusTrait
10
{
11
    /**
12
     * @var Status
13
     */
14
    private $status;
15
16
    /**
17
     * @return Status
18
     */
19
    final public function getStatus(): Status
20
    {
21
        return $this->status;
22
    }
23
24
    /**
25
     * @return bool
26
     */
27
    final public function isFail(): bool
28
    {
29
        return $this->status->isFail();
30
    }
31
32
    /**
33
     * @return bool
34
     */
35
    final public function isSuccess(): bool
36
    {
37
        return $this->status->isSuccess();
38
    }
39
40
    /**
41
     * @return bool
42
     */
43
    final public function isError(): bool
44
    {
45
        return $this->status->isError();
46
    }
47
48
    /**
49
     * @param callable $closure
50
     *
51
     * @return bool
52
     */
53
    final public function onSuccess(callable $closure): bool
54
    {
55
        if ($this->isSuccess()) {
56
            $closure($this);
57
58
            return true;
59
        }
60
61
        return false;
62
    }
63
64
    /**
65
     * @param callable $closure
66
     *
67
     * @return bool
68
     */
69
    final public function onFail(callable $closure): bool
70
    {
71
        if ($this->isFail()) {
72
            $closure($this);
73
74
            return true;
75
        }
76
77
        return false;
78
    }
79
80
    /**
81
     * @param callable $closure
82
     *
83
     * @return bool
84
     */
85
    final public function onError(callable $closure): bool
86
    {
87
        if ($this->isError()) {
88
            $closure($this);
89
90
            return true;
91
        }
92
93
        return false;
94
    }
95
}
96