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

CouldNotResolveTransitionField   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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