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

MissingTraitOnModel   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 38
loc 38
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 MissingTraitOnModel extends InvalidConfig 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
    protected string $trait;
14
15
    public static function make(string $modelClass, string $trait): self
16
    {
17
        return (new static("The method `resolveTransition` was not found on model `{$modelClass}`, are you sure it uses the `{$trait} trait?`"))
18
            ->setModelClass($modelClass)
19
            ->setTrait($trait);
20
    }
21
22
    public function setModelClass(string $modelClass): self
23
    {
24
        $this->modelClass = $modelClass;
25
26
        return $this;
27
    }
28
29
    public function setTrait(string $trait): self
30
    {
31
        $this->trait = $trait;
32
33
        return $this;
34
    }
35
36
    public function getSolution(): Solution
37
    {
38
        return BaseSolution::create('Missing trait on model')
39
            ->setSolutionDescription("Use the `{$this->trait}` trait on `{$this->modelClass}`")
40
            ->setDocumentationLinks([
41
                'Configuring states' => 'https://docs.spatie.be/laravel-model-states/v1/working-with-states/01-configuring-states/',
42
            ]);
43
    }
44
}
45