CheckClassReferences   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 12 3
A exists() 0 10 3
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