Completed
Pull Request — master (#94)
by James
02:02 queued 46s
created

MissingSemicolonSolutionProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A canSolve() 0 12 3
A getSolutions() 0 11 2
1
<?php
2
3
namespace Facade\Ignition\SolutionProviders;
4
5
use Throwable;
6
use Illuminate\Support\Str;
7
use Facade\IgnitionContracts\HasSolutionsForThrowable;
8
use Facade\Ignition\Solutions\FixMissingSemicolonSolution;
9
use Symfony\Component\Debug\Exception\FatalThrowableError;
10
11
class MissingSemicolonSolutionProvider implements HasSolutionsForThrowable
12
{
13
    protected const REGEX = "/syntax error, unexpected \'(.*?)\'(.*?);/";
14
15
    public function canSolve(Throwable $throwable): bool
16
    {
17
        if (! $throwable instanceof FatalThrowableError) {
18
            return false;
19
        }
20
        preg_match(self::REGEX, $throwable->getMessage(), $matches);
21
22
        if (isset($matches[1])) {
23
            return true;
24
        }
25
        return false;
26
    }
27
28
    public function getSolutions(Throwable $throwable): array
29
    {
30
        preg_match(self::REGEX, $throwable->getMessage(), $matches);
31
32
        $filePath = str_replace(app_path(), '', $throwable->getFile());
33
        $solution = new FixMissingSemicolonSolution($filePath, $throwable->getLine(), $matches[1]);
34
35
        return $solution->isRunnable()
36
            ? [$solution]
37
            : [];
38
    }
39
}
40