Completed
Pull Request — master (#94)
by James
01:30
created

MissingSemicolonSolutionProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A canSolve() 0 9 2
A getSolutions() 0 11 2
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