Completed
Push — master ( cf06dc...76f035 )
by Brent
01:20
created

TransitionNotFound::getFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\ModelStates\Exceptions;
4
5
use Facade\IgnitionContracts\BaseSolution;
6
use Facade\IgnitionContracts\ProvidesSolution;
7
use Facade\IgnitionContracts\Solution;
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 getFrom(): string
36
    {
37
        return $this->from;
38
    }
39
40
    public function setTo(string $to): self
41
    {
42
        $this->to = $to;
43
44
        return $this;
45
    }
46
47
    public function getTo(): string
48
    {
49
       return $this->to;
50
    }
51
52
    public function setModelClass(string $modelClass): self
53
    {
54
        $this->modelClass = $modelClass;
55
56
        return $this;
57
    }
58
59
    public function getModelClass(): string
60
    {
61
        return $this->modelClass;
62
    }
63
64
    public function getSolution(): Solution
65
    {
66
        return BaseSolution::create('Transition not found')
67
            ->setSolutionDescription("Register the transition in `{$this->modelClass}::registerStates()`")
68
            ->setDocumentationLinks([
69
                'Configuring transitions' => 'https://docs.spatie.be/laravel-model-states/v1/working-with-transitions/01-configuring-transitions/',
70
            ]);
71
    }
72
}
73