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

ClassDoesNotExtendBaseClass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 40
rs 10
c 0
b 0
f 0
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
use Illuminate\Support\Str;
9
10
class ClassDoesNotExtendBaseClass extends InvalidConfig implements ProvidesSolution
11
{
12
    protected string $class;
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...
13
14
    protected string $baseClass;
15
16
    public static function make(string $class, string $baseClass): self
17
    {
18
        return (new static("Class {$class} does not extend the `{$baseClass}` base class."))
19
            ->setClass($class)
20
            ->setBaseClass($baseClass);
21
    }
22
23
    public function setClass(string $class): self
24
    {
25
        $this->class = $class;
26
27
        return $this;
28
    }
29
30
    public function setBaseClass(string $baseClass): self
31
    {
32
        $this->baseClass = $baseClass;
33
34
        return $this;
35
    }
36
37
    public function getSolution(): Solution
38
    {
39
        $documentationLinks = Str::endsWith($this->baseClass, 'State')
40
            ? ['Configuring states' => 'https://docs.spatie.be/laravel-model-states/v1/working-with-states/01-configuring-states/']
41
            : ['Custom transition classes' => 'https://docs.spatie.be/laravel-model-states/v1/working-with-transitions/02-custom-transition-classes/'];
42
43
        return BaseSolution::create('')
44
            ->setSolutionDescription("Make sure that `{$this->class}` extends `{$this->baseClass}`")
45
            ->setDocumentationLinks($documentationLinks);
46
    }
47
}
48