getServiceProviderForComponent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Consigliere\Components\Commands;
4
5
use Illuminate\Console\Command as ComponentCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputOption;
8
9
class PublishConfigurationCommand extends ComponentCommand
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'component:publish-config';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Publish a component\'s config files to the application';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return mixed
29
     */
30 View Code Duplication
    public function fire()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        if ($component = $this->argument('component')) {
33
            $this->publishConfiguration($component);
0 ignored issues
show
Bug introduced by
It seems like $component defined by $this->argument('component') on line 32 can also be of type array; however, Consigliere\Components\C...: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['components']->enabled() as $component) {
39
            $this->publishConfiguration($component->getName());
40
        }
41
    }
42
43
    /**
44
     * @param string $component
45
     *
46
     * @return string
47
     */
48
    private function getServiceProviderForComponent($component)
49
    {
50
        $studlyName = studly_case($component);
51
52
        return "Components\\$studlyName\\Providers\\{$studlyName}ServiceProvider";
53
    }
54
55
    /**
56
     * @param string $component
57
     */
58
    private function publishConfiguration($component)
59
    {
60
        $this->call('vendor:publish', [
61
            '--provider' => $this->getServiceProviderForComponent($component),
62
            '--force'    => $this->option('force'),
63
            '--tag'      => ['config'],
64
        ]);
65
    }
66
67
    /**
68
     * Get the console command arguments.
69
     *
70
     * @return array
71
     */
72
    protected function getArguments()
73
    {
74
        return [
75
            ['component', InputArgument::OPTIONAL, 'The name of component being used.'],
76
        ];
77
    }
78
79
    /**
80
     * @return array
81
     */
82
    protected function getOptions()
83
    {
84
        return [
85
            ['--force', '-f', InputOption::VALUE_NONE, 'Force the publishing of config files'],
86
        ];
87
    }
88
}
89