GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

StateMaintainer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 59
ccs 15
cts 15
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasCurrentState() 0 4 1
A getCurrentState() 0 6 1
A getCurrentStateName() 0 6 1
A setCurrentState() 0 4 1
A assertHasCurrentState() 0 7 2
1
<?php
2
3
declare (strict_types = 1);
4
5
namespace Noodle\Stateful;
6
7
use Noodle\State\Exception\StateNotSet;
8
use Noodle\State\State;
9
10
trait StateMaintainer
11
{
12
    /**
13
     * The object's current state
14
     *
15
     * @var State
16
     */
17
    private $currentState;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 15
    public function hasCurrentState() : bool
23
    {
24 15
        return !empty($this->currentState);
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 10
    public function getCurrentState() : State
31
    {
32 10
        $this->assertHasCurrentState();
33
34 9
        return $this->currentState;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     *
40
     */
41 4
    public function getCurrentStateName() : string
42
    {
43 4
        $this->assertHasCurrentState();
44
45 3
        return $this->currentState->getName();
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 12
    public function setCurrentState(State $currentState)
52
    {
53 12
        $this->currentState = $currentState;
54 12
    }
55
56
    /**
57
     * Checks if the object has a current state set and throws an exception if not.
58
     *
59
     * @throws StateNotSet If the object does not have a current state
60
     */
61 13
    private function assertHasCurrentState()
62
    {
63 13
        if (!$this->hasCurrentState()) {
64 2
            throw new StateNotSet(sprintf('%s has no current state', __CLASS__));
65
        }
66
67 11
    }
68
}
69