1 | <?php |
||
9 | class FieldDoesNotExtendState extends InvalidConfig implements ProvidesSolution |
||
10 | { |
||
11 | protected string $field; |
||
|
|||
12 | |||
13 | protected string $expectedStateClass; |
||
14 | |||
15 | protected string $actualClass; |
||
16 | |||
17 | public static function make(string $field, string $expectedStateClass, string $actualClass): self |
||
18 | { |
||
19 | return (new static("State field `{$field}` expects state to be of type `{$expectedStateClass}`, instead got `{$actualClass}`")) |
||
20 | ->setField($field) |
||
21 | ->setExpectedStateClass($expectedStateClass) |
||
22 | ->setActualClass($actualClass); |
||
23 | } |
||
24 | |||
25 | public function setField(string $field): self |
||
26 | { |
||
27 | $this->field = $field; |
||
28 | |||
29 | return $this; |
||
30 | } |
||
31 | |||
32 | public function setExpectedStateClass(string $expectedStateClass): self |
||
33 | { |
||
34 | $this->expectedStateClass = $expectedStateClass; |
||
35 | |||
36 | return $this; |
||
37 | } |
||
38 | |||
39 | public function setActualClass(string $actualClass): self |
||
40 | { |
||
41 | $this->actualClass = $actualClass; |
||
42 | |||
43 | return $this; |
||
44 | } |
||
45 | |||
46 | public function getSolution(): Solution |
||
47 | { |
||
48 | return BaseSolution::create("State field `{$this->field}` is the wrong type") |
||
49 | ->setSolutionDescription("Make sure that states for state field `{$this->field}` extend `{$this->expectedStateClass}`, not `{$this->actualClass}`") |
||
50 | ->setDocumentationLinks([ |
||
51 | 'Configuring states' => 'https://docs.spatie.be/laravel-model-states/v1/working-with-states/01-configuring-states/', |
||
52 | ]); |
||
53 | } |
||
54 | } |
||
55 |