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::setCurrentState()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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