Completed
Push — master ( e2d103...eb2586 )
by Sherif
01:46
created

Core::__call()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php namespace App\Modules\Core;
2
3
use App\Modules\Core\Interfaces\BaseFactoryInterface;
4
use App\Modules\Core\Decorators\CachingDecorator;
5
6
class Core implements BaseFactoryInterface
7
{
8
    /**
9
     * Construct the repository class name based on
10
     * the method name called, search in the
11
     * given namespaces for the class and
12
     * return an instance.
13
     *
14
     * @param  string $name the called method name
15
     * @param  array  $arguments the method arguments
16
     * @return object
17
     */
18
    public function __call($name, $arguments)
19
    {
20
        foreach (\Module::all() as $module) {
21
            $nameSpace = 'App\\Modules\\' . $module['basename'] ;
22
            $model = ucfirst(\Str::singular($name));
23
            $class = $nameSpace . '\\Repositories\\' . $model . 'Repository';
24
            $decoratedClass = $class . '\\Decorated';
0 ignored issues
show
Unused Code introduced by
$decoratedClass is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
25
26
            if (class_exists($class)) {
27
                $classObj = \App::make($class);
28
                \App::singleton($class, function ($app) use ($classObj) {
29
                    return new CachingDecorator($classObj, $app['cache.store']);
30
                });
31
32
                return \App::make($class);
33
            }
34
        }
35
    }
36
}
37