Completed
Pull Request — master (#23)
by Travis
01:10
created

TransitionNotFound   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 49
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 7 1
A setFrom() 0 6 1
A setTo() 0 6 1
A setModelClass() 0 6 1
A getSolution() 0 8 1
1
<?php
2
3
namespace Spatie\ModelStates\Exceptions;
4
5
use Facade\IgnitionContracts\Solution;
6
use Facade\IgnitionContracts\BaseSolution;
7
use Facade\IgnitionContracts\ProvidesSolution;
8
9
class TransitionNotFound extends CouldNotPerformTransition implements ProvidesSolution
10
{
11
    /** @var string */
12
    protected $from;
13
14
    /** @var string */
15
    protected $to;
16
17
    /** @var string */
18
    protected $modelClass;
19
20
    public static function make(string $from, string $to, string $modelClass): self
21
    {
22
        return (new static("Transition from `{$from}` to `{$to}` on model `{$modelClass}` was not found, did you forget to register it in `{$modelClass}::registerStates()`?"))
23
            ->setFrom($from)
24
            ->setTo($to)
25
            ->setModelClass($modelClass);
26
    }
27
28
    public function setFrom(string $from): self
29
    {
30
        $this->from = $from;
31
32
        return $this;
33
    }
34
35
    public function setTo(string $to): self
36
    {
37
        $this->to = $to;
38
39
        return $this;
40
    }
41
42
    public function setModelClass(string $modelClass): self
43
    {
44
        $this->modelClass = $modelClass;
45
46
        return $this;
47
    }
48
49
    public function getSolution(): Solution
50
    {
51
        return BaseSolution::create('Transition not found')
52
            ->setSolutionDescription("Register the transition in `{$modelClass}::registerStates()`")
0 ignored issues
show
Bug introduced by
The variable $modelClass does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
53
            ->setDocumentationLinks([
54
                'Configuring transitions' => 'https://docs.spatie.be/laravel-model-states/v1/working-with-transitions/01-configuring-transitions/'
55
            ]);
56
    }
57
}
58