UseStatements   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 17 4
1
<?php
2
3
namespace Cerbero\EloquentInspector\Components;
4
5
use Cerbero\EloquentInspector\Concerns\ReadsModel;
6
7
/**
8
 * The use statements component.
9
 *
10
 */
11
class UseStatements extends Component
12
{
13
    use ReadsModel;
14
15
    /**
16
     * Retrieve the model `use` statements
17
     *
18
     * @return array
19
     */
20 1
    public function get(): array
21
    {
22 1
        $useStatements = [];
23
24 1
        foreach ($this->readModel($this->model) as $line) {
25 1
            if (strpos($line, 'class') === 0) {
26 1
                break;
27 1
            } elseif (strpos($line, 'use') === 0) {
28 1
                preg_match('/([\w\\\_]+)(?:\s+as\s+([\w_]+))?;/i', $line, $matches);
29
30 1
                $segments = explode('\\', $matches[1]);
31 1
                $alias = $matches[2] ?? end($segments);
32 1
                $useStatements[$alias] = $matches[1];
33
            }
34
        }
35
36 1
        return $useStatements;
37
    }
38
}
39