Completed
Push — master ( d43b57...61b043 )
by Randall
07:54 queued 04:32
created

getServiceProviderForModule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Rawilk\LaravelModules\Commands\Other;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Str;
7
8
class PublishConfigurationCommand extends Command
9
{
10
    /** @var string */
11
    protected $signature = 'module:publish-config
12
                            {module? : The module to publish the config files for}
13
                            {--f|force : Force the publishing of config files}';
14
15
    /** @var string */
16
    protected $description = 'Publish the config files for a module.';
17
18
    public function handle(): void
19
    {
20
        if ($module = $this->argument('module')) {
21
            $this->publishConfiguration($module);
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type string[]; however, parameter $module of Rawilk\LaravelModules\Co...:publishConfiguration() does only seem to accept string, 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

21
            $this->publishConfiguration(/** @scrutinizer ignore-type */ $module);
Loading history...
22
23
            return;
24
        }
25
26
        /** @var \Rawilk\LaravelModules\Module $module */
27
        foreach ($this->laravel['modules']->allEnabled() as $module) {
28
            $this->publishConfiguration($module->getName());
29
        }
30
    }
31
32
    private function getServiceProviderForModule(string $name): string
33
    {
34
        $namespace = $this->laravel['config']->get('modules.namespace');
35
        $studlyName = Str::studly($name);
36
37
        return "{$namespace}\\$studlyName\\Providers\\{$studlyName}ServiceProvider";
38
    }
39
40
    private function publishConfiguration(string $module): void
41
    {
42
        $this->call('vendor:publish', [
43
            '--provider' => $this->getServiceProviderForModule($module),
44
            '--force'    => $this->option('force'),
45
            '--tag'      => ['config']
46
        ]);
47
    }
48
}
49