Completed
Pull Request — master (#108)
by Brent
01:10
created

TransitionNotFound   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 64
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
    protected string $from;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
12
13
    protected string $to;
14
15
    protected string $modelClass;
16
17
    public static function make(string $from, string $to, string $modelClass): self
18
    {
19
        return (new static("Transition from `{$from}` to `{$to}` on model `{$modelClass}` was not found, did you forget to register it in `{$modelClass}::registerStates()`?"))
20
            ->setFrom($from)
21
            ->setTo($to)
22
            ->setModelClass($modelClass);
23
    }
24
25
    public function setFrom(string $from): self
26
    {
27
        $this->from = $from;
28
29
        return $this;
30
    }
31
32
    public function getFrom(): string
33
    {
34
        return $this->from;
35
    }
36
37
    public function setTo(string $to): self
38
    {
39
        $this->to = $to;
40
41
        return $this;
42
    }
43
44
    public function getTo(): string
45
    {
46
        return $this->to;
47
    }
48
49
    public function setModelClass(string $modelClass): self
50
    {
51
        $this->modelClass = $modelClass;
52
53
        return $this;
54
    }
55
56
    public function getModelClass(): string
57
    {
58
        return $this->modelClass;
59
    }
60
61
    public function getSolution(): Solution
62
    {
63
        return BaseSolution::create('Transition not found')
64
            ->setSolutionDescription("Register the transition in `{$this->modelClass}::registerStates()`")
65
            ->setDocumentationLinks([
66
                'Configuring transitions' => 'https://docs.spatie.be/laravel-model-states/v1/working-with-transitions/01-configuring-transitions/',
67
            ]);
68
    }
69
}
70