Completed
Pull Request — master (#94)
by James
01:30
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
        return isset($matches[1]);
22
    }
23
24
    public function getSolutions(Throwable $throwable): array
25
    {
26
        preg_match(self::REGEX, $throwable->getMessage(), $matches);
27
28
        $filePath = str_replace(app_path(), '', $throwable->getFile());
29
        $solution = new FixMissingSemicolonSolution($filePath, $throwable->getLine(), $matches[1]);
30
31
        return $solution->isRunnable()
32
            ? [$solution]
33
            : [];
34
    }
35
}
36