ResolvesClasses   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 38
ccs 0
cts 15
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getModuleClassName() 0 13 1
A resolveClass() 0 9 2
1
<?php
2
3
namespace Terranet\Administrator\Traits;
4
5
use Closure;
6
use Symfony\Component\Finder\SplFileInfo;
7
8
trait ResolvesClasses
9
{
10
    /**
11
     * Resolves and Initializes Class by filename.
12
     *
13
     * @param SplFileInfo $fileInfo
14
     * @param null|Closure $callback
15
     */
16
    public function resolveClass(SplFileInfo $fileInfo, Closure $callback = null)
17
    {
18
        /** @noinspection PhpIncludeInspection */
19
        require_once $fileInfo->getPathname();
20
21
        $instance = app()->make($this->getModuleClassName($fileInfo));
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
        $instance = /** @scrutinizer ignore-call */ app()->make($this->getModuleClassName($fileInfo));
Loading history...
22
23
        if (\is_callable($callback)) {
24
            $callback($instance);
25
        }
26
    }
27
28
    /**
29
     * @param SplFileInfo $fileInfo
30
     *
31
     * @return mixed
32
     */
33
    protected function getModuleClassName(SplFileInfo $fileInfo)
34
    {
35
        $name = str_replace('.php', '', $fileInfo->getBasename());
36
37
        $path = trim(str_replace(
38
            app_path(),
0 ignored issues
show
Bug introduced by
The function app_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
            /** @scrutinizer ignore-call */ 
39
            app_path(),
Loading history...
39
            '',
40
            \dirname($fileInfo->getPathname())
41
        ), \DIRECTORY_SEPARATOR);
42
43
        $location = str_replace('/', '\\', $path);
44
45
        return app()->getNamespace()."{$location}\\{$name}";
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        return /** @scrutinizer ignore-call */ app()->getNamespace()."{$location}\\{$name}";
Loading history...
46
    }
47
}
48