BaseFileLoader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 11
dl 0
loc 80
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrap() 0 4 1
A getFilesToLoad() 0 8 2
A __construct() 0 4 1
1
<?php
2
3
namespace LaravelModulize\Services\Loaders;
4
5
use Illuminate\Contracts\Foundation\Application;
6
use Illuminate\Support\Collection;
7
use LaravelModulize\Contracts\ModulizerRepositoryInterface;
8
9
abstract class BaseFileLoader
10
{
11
    /**
12
     * Instance of Application
13
     *
14
     * @var \Illuminate\Contracts\Foundation\Application $app
15
     */
16
    protected $app;
17
18
    /**
19
     * Instance of the repository
20
     *
21
     * @var \LaravelModulize\Contracts\ModulizerRepositoryInterface
22
     */
23
    protected $repo;
24
25
    /**
26
     * Construct the RoutesLoader
27
     *
28
     * @param \LaravelModulize\Contracts\ModulizerRepositoryInterface $repository
29
     * @param \Illuminate\Contracts\Foundation\Application $app
30
     */
31
    public function __construct(ModulizerRepositoryInterface $repository, Application $app)
32
    {
33
        $this->app = $app;
34
        $this->repo = $repository;
35
    }
36
37
    /**
38
     * Go through each of the module and load the necesary files
39
     *
40
     * @return void
41
     */
42
    public function bootstrap(): void
43
    {
44
        $this->repo->getModules()->each(function ($module) {
45
            $this->loadFiles($module);
46
        });
47
    }
48
49
    /**
50
     * Retrieve the collection of files found for the given module
51
     *
52
     * @param string $module
53
     * @return \Illuminate\Support\Collection
54
     */
55
    public function getFilesToLoad(string $module): Collection
56
    {
57
        if (!$this->repo->filesExist($this->getFilesPath($module))) {
58
            return new Collection();
59
        }
60
61
        return $this->repo->getFiles(
62
            $this->getFilesPath($module)
63
        );
64
    }
65
66
    /**
67
     * Load the files to load and register them
68
     *
69
     * @param string $module
70
     * @return void
71
     */
72
    abstract public function loadFiles(string $module): void;
73
74
    /**
75
     * Retrieve the path where the files to load should be at
76
     *
77
     * @param string $module
78
     * @return string
79
     */
80
    abstract public function getFilesPath(string $module): string;
81
82
    /**
83
     * Retrieve the namespace to be used when registering the files
84
     *
85
     * @param string $module
86
     * @return string
87
     */
88
    abstract public function getNamespace(string $module): string;
89
}
90