Test Setup Failed
Pull Request — master (#11)
by Benjamin
04:12
created

PhpParser::analyze()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 16
rs 9.9332
1
<?php
2
declare(strict_types=1);
3
4
namespace Bdelespierre\LaravelBladeLinter\Backend;
5
6
use Bdelespierre\LaravelBladeLinter\Backend;
7
use Bdelespierre\LaravelBladeLinter\ErrorRecord;
8
use PhpParser\Error;
9
use PhpParser\ParserFactory;
10
11
final class PhpParser implements Backend
12
{
13
    /**
14
     * @param \SplFileInfo $file
15
     * @param string $code
16
     * @return list<ErrorRecord>
0 ignored issues
show
Bug introduced by
The type Bdelespierre\LaravelBladeLinter\Backend\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
     */
18
    public function analyze(\SplFileInfo $file, string $code): array
19
    {
20
        $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
21
        try {
22
            $parser->parse($code);
23
        } catch (Error $e) {
24
            return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array(new Bdelesp...), $e->getStartLine())) returns the type array<integer,Bdelespier...ladeLinter\ErrorRecord> which is incompatible with the documented return type Bdelespierre\LaravelBladeLinter\Backend\list.
Loading history...
25
                new ErrorRecord(
26
                    'Parse error: ' . $e->getRawMessage(),
27
                    $file->getPathname(),
28
                    $e->getStartLine()
29
                )
30
            ];
31
        }
32
33
        return [];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array() returns the type array which is incompatible with the documented return type Bdelespierre\LaravelBladeLinter\Backend\list.
Loading history...
34
    }
35
36
    public static function name(): string
37
    {
38
        return 'php-parser';
39
    }
40
}
41