Completed
Pull Request — master (#1048)
by
unknown
02:46
created

Module   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 53.85%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 7
cts 13
cp 0.5385
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCachedServicesPath() 0 10 2
A registerProviders() 0 5 1
A registerAliases() 0 7 2
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