Completed
Push — master ( 15e02a...758c52 )
by Nicolas
05:13
created

PublishCommand::fire()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
ccs 0
cts 5
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Illuminate\Console\Command;
6
use Nwidart\Modules\Module;
7
use Nwidart\Modules\Publishing\AssetPublisher;
8
use Symfony\Component\Console\Input\InputArgument;
9
10 View Code Duplication
class PublishCommand extends Command
0 ignored issues
show
Duplication introduced by
This class 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...
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'module:publish';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Publish a module\'s assets to the application';
25
26
    /**
27
     * Execute the console command.
28
     *
29
     * @return mixed
30
     */
31
    public function fire()
32
    {
33
        if ($name = $this->argument('module')) {
34
            return $this->publish($name);
0 ignored issues
show
Bug introduced by
It seems like $name defined by $this->argument('module') on line 33 can also be of type array; however, Nwidart\Modules\Commands\PublishCommand::publish() 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...
35
        }
36
37
        $this->publishAll();
38
    }
39
40
    /**
41
     * Publish assets from all modules.
42
     */
43
    public function publishAll()
44
    {
45
        foreach ($this->laravel['modules']->enabled() as $module) {
46
            $this->publish($module);
47
        }
48
    }
49
50
    /**
51
     * Publish assets from the specified module.
52
     *
53
     * @param string $name
54
     */
55
    public function publish($name)
56
    {
57
        if ($name instanceof Module) {
58
            $module = $name;
59
        } else {
60
            $module = $this->laravel['modules']->findOrFail($name);
61
        }
62
63
        with(new AssetPublisher($module))
64
            ->setRepository($this->laravel['modules'])
65
            ->setConsole($this)
66
            ->publish();
67
68
        $this->line("<info>Published</info>: {$module->getStudlyName()}");
69
    }
70
71
    /**
72
     * Get the console command arguments.
73
     *
74
     * @return array
75
     */
76 16
    protected function getArguments()
77
    {
78
        return [
79 16
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
80 16
        ];
81
    }
82
}
83