StateBuilder   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 70
ccs 22
cts 22
cp 1
rs 10
c 1
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A allowCustomTransition() 0 3 1
A __construct() 0 4 1
A addAttribute() 0 8 2
A build() 0 3 1
A allowTransition() 0 11 2
A create() 0 3 1
1
<?php declare(strict_types=1);
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "StateBuilder.php" doesn't match the expected filename "statebuilder.php"
Loading history...
2
3
namespace Star\Component\State\Builder;
4
5
use Star\Component\State\EventRegistry;
6
use Star\Component\State\Port\Symfony\EventDispatcherAdapter;
7
use Star\Component\State\StateMachine;
8
use Star\Component\State\StateTransition;
9
use Star\Component\State\TransitionRegistry;
10
use Star\Component\State\Transitions\ManyToOneTransition;
11
use Star\Component\State\Transitions\OneToOneTransition;
12
13
/**
14
 * Tool to build the StateMachine.
15
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
16
final class StateBuilder
17
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class StateBuilder
Loading history...
18
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
19
     * @var TransitionRegistry
20
     */
21
    private $registry;
0 ignored issues
show
Coding Style introduced by
Private member variable "registry" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
Coding Style introduced by
Private member variable "registry" must be prefixed with an underscore
Loading history...
22
23
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
24
     * @var EventRegistry
25
     */
26
    private $listeners;
0 ignored issues
show
Coding Style introduced by
Private member variable "listeners" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "listeners" must be prefixed with an underscore
Loading history...
27
28 36
    public function __construct()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
29
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
30 36
        $this->registry = new TransitionRegistry();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
31 36
        $this->listeners = new EventDispatcherAdapter();
32 36
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end __construct()
Loading history...
33
34
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
35
     * @param string $name
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
36
     * @param string|string[] $from
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
37
     * @param string $to
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
38
     *
39
     * @return StateBuilder
40
     */
41 36
    public function allowTransition(string $name, $from, string $to): StateBuilder
42
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
43 36
        if (\is_array($from)) {
44 16
            $transition = new ManyToOneTransition($name, $to, ...$from);
45
        } else {
46 36
            $transition = new OneToOneTransition($name, $from, $to);
47
        }
48
49 36
        $this->allowCustomTransition($transition);
50
51 36
        return $this;
52
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end allowTransition()
Loading history...
53
54
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
55
     * @param StateTransition $transition
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
56
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
57 36
    public function allowCustomTransition(StateTransition $transition): void
58
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
59 36
        $this->registry->addTransition($transition);
60 36
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end allowCustomTransition()
Loading history...
61
62
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
63
     * @param string $attribute The attribute
0 ignored issues
show
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
introduced by
Parameter comment must end with a full stop
Loading history...
64
     * @param string|string[] $states The list of states that this attribute applies to
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
introduced by
Parameter comment must end with a full stop
Loading history...
65
     *
66
     * @return StateBuilder
67
     */
68 31
    public function addAttribute(string $attribute, $states): StateBuilder
69
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
70 31
        $states = (array) $states;
0 ignored issues
show
Coding Style introduced by
A cast statement should not be followed as per the coding-style.
Loading history...
71 31
        foreach ($states as $stateName) {
72 31
            $this->registry->addAttribute($stateName, $attribute);
73
        }
74
75 31
        return $this;
76
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end addAttribute()
Loading history...
77
78 36
    public function create(string $currentState): StateMachine
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
79
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
80 36
        return new StateMachine($currentState, $this->registry, $this->listeners);
81
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end create()
Loading history...
82
83 18
    public static function build(): StateBuilder
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
84
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
85 18
        return new static();
86
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end build()
Loading history...
87
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
88