TranslationsLoader::loadFiles()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace LaravelModulize\Services\Loaders;
4
5
use Illuminate\Support\Collection;
6
7
class TranslationsLoader extends BaseFileLoader
8
{
9
    /**
10
     * Load the files to load and register them
11
     *
12
     * @param string $module
13
     * @return void
14
     */
15
    public function loadFiles(string $module): void
16
    {
17
        if (!$this->getFilesToLoad($module)->isEmpty()) {
18
            $this->repo->addTranslation($this->getFilesPath($module), $module);
19
        }
20
    }
21
22
    /**
23
     * Retrieve the collection of files found for the given module
24
     *
25
     * @param string $module
26
     * @return \Illuminate\Support\Collection
27
     */
28
    public function getFilesToLoad(string $module): Collection
29
    {
30
        if (!$this->repo->filesExist($this->getFilesPath($module))) {
31
            return new Collection();
32
        }
33
34
        return $this->repo->glob(
35
            $this->getFilesPath($module) . '/**/*.php'
36
        );
37
    }
38
39
    /**
40
     * Retrieve the path where the files to load should be at
41
     *
42
     * @param string $module
43
     * @return string
44
     */
45
    public function getFilesPath(string $module): string
46
    {
47
        return $this->repo->getModulePath($module) . "/resources/lang";
48
    }
49
50
    /**
51
     * Retrieve the namespace to be used when registering the files
52
     *
53
     * @param string $module
54
     * @return string
55
     */
56
    public function getNamespace(string $module): string
57
    {
58
        return $this->repo
59
            ->getModuleNamespace($module);
60
    }
61
62
}
63