StateMetadata::isInState()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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 "StateMetadata.php" doesn't match the expected filename "statemetadata.php"
Loading history...
2
3
namespace Star\Component\State;
4
5
use Star\Component\State\Builder\StateBuilder;
6
use Star\Component\State\Callbacks\TransitionCallback;
7
8
abstract class StateMetadata
0 ignored issues
show
Coding Style Documentation introduced by
Missing class doc comment
Loading history...
9
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class StateMetadata
Loading history...
10
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
11
     * @var string
12
     */
13
    protected $current;
0 ignored issues
show
Coding Style introduced by
Protected member variable "current" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
14
15
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
16
     * @param string $initial The initial state name
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
17
     */
18 15
    public function __construct(string $initial)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
19
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
20 15
        $this->current = $initial;
21 15
    }
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...
22
23
    /**
24
     * Returns the state workflow configuration.
25
     *
26
     * @param StateBuilder $builder
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
27
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
28
    abstract protected function configure(StateBuilder $builder): void;
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
29
30 18
    private function getMachine(): StateMachine
0 ignored issues
show
Coding Style introduced by
Private method name "StateMetadata::getMachine" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
31
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
32 18
        $this->configure($builder = new StateBuilder());
0 ignored issues
show
Coding Style introduced by
Assignments must be the first block of code on a line
Loading history...
33
34
        // todo implement caching for faster building
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
Coding Style Documentation introduced by
Inline comments must start with a capital letter
Loading history...
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
35 18
        return $builder->create($this->current);
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 getMachine()
Loading history...
37
38
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
39
     * @param string $name
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 18 spaces after parameter type; 1 found
Loading history...
40
     * @param mixed $context
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 19 spaces after parameter type; 1 found
Loading history...
41
     * @param TransitionCallback|null $callback
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
42
     *
43
     * @return static
44
     */
45 12
    final public function transit(string $name, $context, TransitionCallback $callback = null): StateMetadata
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
46
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
47 12
        $this->current = $this->getMachine()->transit($name, $context, $callback);
48
49 11
        return $this;
50
    }
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 transit()
Loading history...
51
52 6
    final public function hasAttribute(string $attribute): bool
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
53
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
54 6
        return $this->getMachine()->hasAttribute($attribute);
55
    }
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 hasAttribute()
Loading history...
56
57 16
    final public function isInState(string $state): bool
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
58
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
59 16
        return $this->getMachine()->isInState($state);
60
    }
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 isInState()
Loading history...
61
62 1
    final public function getCurrent(): string
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
63
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
64 1
        return $this->current;
65
    }
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 getCurrent()
Loading history...
66
}
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...
67