Completed
Pull Request — master (#203)
by
unknown
03:29
created

getServiceProviderForModule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Illuminate\Console\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputOption;
8
9
class PublishConfigurationCommand extends Command
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'module:publish-config';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Publish a module\'s config files to the application';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return mixed
29
     */
30
    public function fire()
31
    {
32
        if ($module = $this->argument('module')) {
33
            $this->publishConfiguration($module);
0 ignored issues
show
Bug introduced by
It seems like $module defined by $this->argument('module') on line 32 can also be of type array; however, Nwidart\Modules\Commands...:publishConfiguration() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
34
35
            return;
36
        }
37
38
        foreach ($this->laravel['modules']->enabled() as $module) {
39
            $this->publishConfiguration($module->getName());
40
        }
41
    }
42
43
    /**
44
     * @param string $module
45
     * @return string
46
     */
47
    private function getServiceProviderForModule($module)
48
    {
49
        $namespace = $this->laravel['config']->get('modules.namespace');
50
        $studlyName = studly_case($module);
51
52
        return "$namespace\\$studlyName\\Providers\\{$studlyName}ServiceProvider";
53
    }
54
55
    /**
56
     * @param string $module
57
     */
58
    private function publishConfiguration($module)
59
    {
60
        $this->call('vendor:publish', [
61
            '--provider' => $this->getServiceProviderForModule($module),
62
            '--force' => $this->option('force'),
63
            '--tag' => ['config'],
64
        ]);
65
    }
66
67
    /**
68
     * Get the console command arguments.
69
     *
70
     * @return array
71
     */
72 43
    protected function getArguments()
73
    {
74
        return [
75 43
            ['module', InputArgument::OPTIONAL, 'The name of module being used.'],
76
        ];
77
    }
78
79
    /**
80
     * @return array
81
     */
82 43
    protected function getOptions()
83
    {
84
        return [
85 43
            ['--force', '-f', InputOption::VALUE_NONE, 'Force the publishing of config files'],
86
        ];
87
    }
88
}
89