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

CouldNotResolveTransitionField::setModelClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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 View Code Duplication
class CouldNotResolveTransitionField extends CouldNotPerformTransition implements ProvidesSolution
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    /** @var string */
12
    protected $modelClass;
13
14
    public static function make(string $modelClass): self
15
    {
16
        return (new static("You tried to invoke {$modelClass}::transitionTo() directly, though there are multiple state fields configured."))
17
            ->setModelClass($modelClass);
18
    }
19
20
    public function setModelClass(string $modelClass): self
21
    {
22
        $this->modelClass = $modelClass;
23
24
        return $this;
25
    }
26
27
    public function getSolution(): Solution
28
    {
29
        return BaseSolution::create('Could not resolve transition field')
30
            ->setSolutionDescription("Use {$this->modelClass}->stateField->transitionTo()")
31
            ->setDocumentationLinks([
32
                'Using transitions' => 'https://docs.spatie.be/laravel-model-states/v1/working-with-transitions/01-configuring-transitions/#using-transitions'
33
            ]);
34
    }
35
}
36