yvoyer /
php-state
| 1 | <?php declare(strict_types=1); |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 2 | |||
| 3 | namespace Star\Component\State\Transitions; |
||
| 4 | |||
| 5 | use Star\Component\State\RegistryBuilder; |
||
| 6 | use Star\Component\State\StateTransition; |
||
| 7 | use Webmozart\Assert\Assert; |
||
| 8 | |||
| 9 | final class ManyToOneTransition implements StateTransition |
||
|
0 ignored issues
–
show
|
|||
| 10 | { |
||
|
0 ignored issues
–
show
|
|||
| 11 | /** |
||
|
0 ignored issues
–
show
|
|||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | private $name; |
||
|
0 ignored issues
–
show
|
|||
| 15 | |||
| 16 | /** |
||
|
0 ignored issues
–
show
|
|||
| 17 | * @var string[] |
||
| 18 | */ |
||
| 19 | private $fromStates; |
||
|
0 ignored issues
–
show
|
|||
| 20 | |||
| 21 | /** |
||
|
0 ignored issues
–
show
|
|||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | private $to; |
||
|
0 ignored issues
–
show
|
|||
| 25 | |||
| 26 | 20 | public function __construct(string $name, string $to, string ...$fromStates) |
|
|
0 ignored issues
–
show
|
|||
| 27 | { |
||
|
0 ignored issues
–
show
|
|||
| 28 | 20 | $this->name = $name; |
|
| 29 | 20 | Assert::greaterThanEq(\count($fromStates), 1, 'Expected at least %2$s state. Got: %s'); |
|
| 30 | 20 | $this->fromStates = $fromStates; |
|
| 31 | 20 | $this->to = $to; |
|
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 9 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...
|
|||
| 32 | 20 | } |
|
|
0 ignored issues
–
show
|
|||
| 33 | |||
| 34 | 18 | public function getName(): string |
|
|
0 ignored issues
–
show
|
|||
| 35 | { |
||
|
0 ignored issues
–
show
|
|||
| 36 | 18 | return $this->name; |
|
| 37 | } |
||
|
0 ignored issues
–
show
|
|||
| 38 | |||
| 39 | 18 | public function onRegister(RegistryBuilder $registry): void |
|
|
0 ignored issues
–
show
|
|||
| 40 | { |
||
|
0 ignored issues
–
show
|
|||
| 41 | 18 | foreach ($this->fromStates as $from) { |
|
| 42 | 18 | $registry->registerStartingState($this->name, $from, []); |
|
|
0 ignored issues
–
show
|
|||
| 43 | } |
||
| 44 | |||
| 45 | 18 | $registry->registerDestinationState($this->name, $this->to, []); |
|
|
0 ignored issues
–
show
|
|||
| 46 | 18 | } |
|
|
0 ignored issues
–
show
|
|||
| 47 | |||
| 48 | public function getDestinationState(): string |
||
|
0 ignored issues
–
show
|
|||
| 49 | { |
||
|
0 ignored issues
–
show
|
|||
| 50 | return $this->to; |
||
| 51 | } |
||
|
0 ignored issues
–
show
|
|||
| 52 | } |
||
|
0 ignored issues
–
show
|
|||
| 53 |