Completed
Pull Request — master (#23)
by Travis
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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 6 6 1
A setModelClass() 6 6 1
A setTrait() 6 6 1
A getSolution() 8 8 1

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\Solution;
6
use Facade\IgnitionContracts\BaseSolution;
7
use Facade\IgnitionContracts\ProvidesSolution;
8
9 View Code Duplication
class MissingTraitOnModel extends InvalidConfig 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
    /** @var string */
15
    protected $trait;
16
17
    public static function make(string $modelClass, string $trait): self
18
    {
19
        return (new static("The method `resolveTransition` was not found on model `{$modelClass}`, are you sure it uses the `{$trait} trait?`"))
20
            ->setModelClass($modelClass)
21
            ->setTrait($trait);
22
    }
23
24
    public function setModelClass(string $modelClass): self
25
    {
26
        $this->modelClass = $modelClass;
27
28
        return $this;
29
    }
30
31
    public function setTrait(string $trait): self
32
    {
33
        $this->trait = $trait;
34
35
        return $this;
36
    }
37
38
    public function getSolution(): Solution
39
    {
40
        return BaseSolution::create('Missing trait on model')
41
            ->setSolutionDescription("Use the `{$this->trait}` trait on `{$this->modelClass}`")
42
            ->setDocumentationLinks([
43
                'Configuring states' => 'https://docs.spatie.be/laravel-model-states/v1/working-with-states/01-configuring-states/'
44
            ]);
45
    }
46
}
47