Passed
Push — master ( 617e52...ff4e9f )
by Arthur
35:51
created

Larapi::getModuleNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 09.03.19
6
 * Time: 21:51.
7
 */
8
9
namespace Foundation\Core;
10
11
use Illuminate\Support\Str;
12
13
class Larapi
14
{
15
    /**
16
     * @return Module[]
17
     */
18 127
    public static function getModules(): array
19
    {
20 127
        $modules = [];
21
22 127
        foreach (self::getModuleNames() as $moduleName) {
23 127
            $modules[] = self::getModule($moduleName);
24
        }
25
26 127
        return $modules;
27
    }
28
29
    /**
30
     * @param string $name
31
     * @return Module
32
     * @throws \Foundation\Exceptions\Exception
33
     */
34 127
    public static function getModule(string $name): Module
35
    {
36 127
        $name = Str::studly($name);
37
38 127
        return new Module($name, self::getModulePath($name));
39
    }
40
41
    /**
42
     * @return string
43
     */
44 127
    public static function getModulesBasePath(): string
45
    {
46 127
        return base_path('src/Modules');
47
    }
48
49
    /**
50
     * @return string[]
51
     */
52 127
    public static function getModuleNames(): array
53
    {
54 127
        return array_diff(scandir(self::getModulesBasePath()), ['..', '.']);
0 ignored issues
show
Bug introduced by
It seems like scandir(self::getModulesBasePath()) can also be of type false; however, parameter $array1 of array_diff() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

54
        return array_diff(/** @scrutinizer ignore-type */ scandir(self::getModulesBasePath()), ['..', '.']);
Loading history...
55
    }
56
57
    /**
58
     * @param string $module
59
     * @return string
60
     */
61 127
    private static function getModulePath(string $module): string
62
    {
63 127
        return self::getModulesBasePath().'/'.$module;
64
    }
65
66 127
    public static function getApiDomainName()
67
    {
68 127
        $apiDomain = str_replace('http://', '', strtolower(env('API_URL')));
69 127
        $apiDomain = str_replace('https://', '', $apiDomain);
70
71 127
        return $apiDomain;
72
    }
73
}
74