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

MissingSemicolonSolutionProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

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