Completed
Push — master ( e75247...dea0c3 )
by Nicolas
14s
created

Repository::scan()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 5
nop 0
dl 20
loc 20
ccs 10
cts 10
cp 1
crap 4
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace Nwidart\Modules\Laravel;
4
5
use Nwidart\Modules\Json;
6
use Nwidart\Modules\Repository as BaseRepository;
7
8 View Code Duplication
class Repository extends BaseRepository
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13 136
    public function scan()
14
    {
15 136
        $paths = $this->getScanPaths();
16
17 136
        $modules = [];
18
19 136
        foreach ($paths as $key => $path) {
20 136
            $manifests = $this->app['files']->glob("{$path}/module.json");
21
22 136
            is_array($manifests) || $manifests = [];
23
24 136
            foreach ($manifests as $manifest) {
25 69
                $name = Json::make($manifest)->get('name');
26
27 136
                $modules[$name] = new Module($this->app, $name, dirname($manifest));
28
            }
29
        }
30
31 136
        return $modules;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function formatCached($cached)
38
    {
39
        $modules = [];
40
41
        foreach ($cached as $name => $module) {
42
            $path = $this->config('paths.modules') . '/' . $name;
43
44
            $modules[$name] = new Module($this->app, $name, $path);
45
        }
46
47
        return $modules;
48
    }
49
}
50