CheckClassReferences::check()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\LaravelMicroscope\Checks;
4
5
use Imanghafoori\LaravelMicroscope\Analyzers\ParseUseStatement;
6
use Imanghafoori\LaravelMicroscope\ErrorReporters\ErrorPrinter;
7
8
class CheckClassReferences
9
{
10
    public static $refCount = 0;
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...
Bug introduced by
The variable $_ 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
        $p = app(ErrorPrinter::class);
17
        foreach ($classes as $class) {
18
            self::$refCount++;
19
            if (! self::exists($class['class'])) {
20
                $p->wrongUsedClassError($absPath, $class['class'], $class['line']);
21
            }
22
        }
23
    }
24
25
    private static function exists($class)
26
    {
27
        try {
28
            return class_exists($class) || interface_exists($class);
29
        } catch (\Error $e) {
30
            app(ErrorPrinter::class)->simplePendError($e->getMessage(), $e->getFile(), $e->getLine(), 'error', 'File error');
31
32
            return true;
33
        }
34
    }
35
}
36