Passed
Push — master ( 762407...a7439c )
by Roy
04:51 queued 03:09
created

TranslationsLoader::loadFiles()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LaravelModulize\Services\Loaders;
4
5
use Illuminate\Support\Collection;
6
use LaravelModulize\Contracts\LoadsFiles;
7
8
class TranslationsLoader extends BaseFileLoader implements LoadsFiles
9
{
10
    /**
11
     * Load the files to load and register them
12
     *
13
     * @param string $module
14
     * @return void
15
     */
16
    public function loadFiles(string $module): void
17
    {
18
        if (!$this->getFilesToLoad($module)->isEmpty()) {
19
            $this->repo->addTranslation($this->getFilesPath($module), $module);
0 ignored issues
show
Bug introduced by
The method addTranslation() does not exist on LaravelModulize\Contract...izerRepositoryInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to LaravelModulize\Contract...izerRepositoryInterface. ( Ignorable by Annotation )

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

19
            $this->repo->/** @scrutinizer ignore-call */ 
20
                         addTranslation($this->getFilesPath($module), $module);
Loading history...
20
        }
21
    }
22
23
    /**
24
     * Retrieve the collection of files found for the given module
25
     *
26
     * @param string $module
27
     * @return \Illuminate\Support\Collection
28
     */
29
    public function getFilesToLoad(string $module): Collection
30
    {
31
        if (!$this->repo->filesExist($this->getFilesPath($module))) {
0 ignored issues
show
Bug introduced by
The method filesExist() does not exist on LaravelModulize\Contract...izerRepositoryInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to LaravelModulize\Contract...izerRepositoryInterface. ( Ignorable by Annotation )

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

31
        if (!$this->repo->/** @scrutinizer ignore-call */ filesExist($this->getFilesPath($module))) {
Loading history...
32
            return new Collection();
33
        }
34
35
        return $this->repo->glob(
0 ignored issues
show
Bug introduced by
The method glob() does not exist on LaravelModulize\Contract...izerRepositoryInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to LaravelModulize\Contract...izerRepositoryInterface. ( Ignorable by Annotation )

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

35
        return $this->repo->/** @scrutinizer ignore-call */ glob(
Loading history...
36
            $this->getFilesPath($module) . '/**/*.php'
37
        );
38
    }
39
40
    /**
41
     * Retrieve the path where the files to load should be at
42
     *
43
     * @param string $module
44
     * @return string
45
     */
46
    public function getFilesPath(string $module): string
47
    {
48
        return $this->repo->getModulePath($module) . "/resources/lang";
49
    }
50
51
    /**
52
     * Retrieve the namespace to be used when registering the files
53
     *
54
     * @param string $module
55
     * @return string
56
     */
57
    public function getNamespace(string $module): string
58
    {
59
        return $this->repo
60
            ->getModuleNamespace($module);
61
    }
62
63
}
64