Completed
Pull Request — master (#32)
by Brent
01:07
created

TransitionNotAllowed   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 TransitionNotAllowed extends CouldNotPerformTransition implements ProvidesSolution
10
{
11
    protected string $transitionClass;
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, string $transitionClass): self
14
    {
15
        return (new static("The transition `{$transitionClass}` is not allowed on model `{$modelClass}` at the moment."))
16
            ->setTransitionClass($transitionClass);
17
    }
18
19
    public function setTransitionClass(string $transitionClass): self
20
    {
21
        $this->transitionClass = $transitionClass;
22
23
        return $this;
24
    }
25
26
    public function getSolution(): Solution
27
    {
28
        return BaseSolution::create('Transition not allowed')
29
            ->setSolutionDescription("Review your implementation of `canTransition` in {$this->transitionClass} if this is unexpected")
30
            ->setDocumentationLinks([
31
                'Custom transition classes' => 'https://docs.spatie.be/laravel-model-states/v1/working-with-transitions/02-custom-transition-classes/',
32
            ]);
33
    }
34
}
35