CheckIsQuery::isQueryClass()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\LaravelMicroscope\Checks;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Facades\DB;
7
use Imanghafoori\LaravelMicroscope\Analyzers\ParseUseStatement;
8
use Imanghafoori\LaravelMicroscope\ErrorReporters\ErrorPrinter;
9
10
class CheckIsQuery
11
{
12
    public static function check($tokens, $absPath)
13
    {
14
        [$classes,] = ParseUseStatement::findClassReferences($tokens, $absPath);
0 ignored issues
show
Bug introduced by
The variable $classes does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
15
16
        foreach ($classes as $class) {
17
            $c = $class['class'];
18
            if (self::isQueryClass($c)) {
19
                app(ErrorPrinter::class)->queryInBlade($absPath, $class['class'], $class['line']);
20
            }
21
        }
22
    }
23
24
    public static function isQueryClass($class)
25
    {
26
        $queryBuilder = ['\\'.DB::class, DB::class, '\DB', 'DB'];
27
28
        return is_subclass_of($class, Model::class) || \in_array($class, $queryBuilder);
29
    }
30
}
31