Completed
Pull Request — master (#83)
by James
01:41
created

MissingColumnSolutionProvider::canSolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Facade\Ignition\SolutionProviders;
4
5
use Throwable;
6
use Illuminate\Database\QueryException;
7
use Facade\Ignition\Solutions\RunMigrationsSolution;
8
use Facade\IgnitionContracts\HasSolutionsForThrowable;
9
10 View Code Duplication
class MissingColumnSolutionProvider implements HasSolutionsForThrowable
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...
11
{
12
    /**
13
     * See https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html#error_er_bad_field_error.
14
     */
15
    const MYSQL_BAD_TABLE_CODE = '42S22';
16
17
    public function canSolve(Throwable $throwable): bool
18
    {
19
        if (! $throwable instanceof QueryException) {
20
            return false;
21
        }
22
23
        return  $this->isBadTableErrorCode($throwable->getCode());
24
    }
25
26
    protected function isBadTableErrorCode($code): bool
27
    {
28
        return $code === static::MYSQL_BAD_TABLE_CODE;
29
    }
30
31
    public function getSolutions(Throwable $throwable): array
32
    {
33
        $solution = new RunMigrationsSolution('A column was not found');
34
        return [$solution];
35
    }
36
}
37