Completed
Pull Request — master (#94)
by James
02:33 queued 01:10
created

MissingSemicolonSolutionProvider::getSolutions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
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 Facade\IgnitionContracts\HasSolutionsForThrowable;
7
use Facade\Ignition\Solutions\FixMissingSemicolonSolution;
8
use Symfony\Component\Debug\Exception\FatalThrowableError;
9
10
class MissingSemicolonSolutionProvider implements HasSolutionsForThrowable
11
{
12
    protected const REGEX = "/syntax error, unexpected \'(.*?)\'(.*?);/";
13
14
    public function canSolve(Throwable $throwable): bool
15
    {
16
        if (! $throwable instanceof FatalThrowableError) {
17
            return false;
18
        }
19
        preg_match(self::REGEX, $throwable->getMessage(), $matches);
20
21
        if (isset($matches[1])) {
22
            return true;
23
        }
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