Completed
Push — master ( 9eb657...258270 )
by Nicolas
17s queued 11s
created

Module::getCachedServicesPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 10
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Nwidart\Modules\Laravel;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Illuminate\Foundation\AliasLoader;
7
use Illuminate\Foundation\ProviderRepository;
8
use Illuminate\Support\Str;
9
use Nwidart\Modules\Module as BaseModule;
10
11
class Module extends BaseModule
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16 3
    public function getCachedServicesPath(): string
17
    {
18
        // This checks if we are running on a Laravel Vapor managed instance
19
        // and sets the path to a writable one (services path is not on a writable storage in Vapor).
20 3
        if(!is_null(env('VAPOR_MAINTENANCE_MODE', null))) {
21
            return Str::replaceLast('config.php', $this->getSnakeName() . '_module.php', $this->app->getCachedConfigPath());
0 ignored issues
show
Bug introduced by
The method getCachedConfigPath() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean configPath()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
22
        }
23
24 3
        return Str::replaceLast('services.php', $this->getSnakeName() . '_module.php', $this->app->getCachedServicesPath());
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 2
    public function registerProviders(): void
31
    {
32 2
        (new ProviderRepository($this->app, new Filesystem(), $this->getCachedServicesPath()))
33 2
            ->load($this->get('providers', []));
34 2
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function registerAliases(): void
40
    {
41
        $loader = AliasLoader::getInstance();
42
        foreach ($this->get('aliases', []) as $aliasName => $aliasClass) {
43
            $loader->alias($aliasName, $aliasClass);
44
        }
45
    }
46
}
47