Completed
Pull Request — master (#354)
by Martin
02:25
created

MiddlewareMakeCommand::getDefaultNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 4
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Illuminate\Support\Str;
6
use Nwidart\Modules\Support\Stub;
7
use Nwidart\Modules\Traits\ModuleCommandTrait;
8
use Symfony\Component\Console\Input\InputArgument;
9
10 View Code Duplication
class MiddlewareMakeCommand extends GeneratorCommand
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
    use ModuleCommandTrait;
14
15
    /**
16
     * The name of argument name.
17
     *
18
     * @var string
19
     */
20
    protected $argumentName = 'name';
21
22
    /**
23
     * The console command name.
24
     *
25
     * @var string
26
     */
27
    protected $name = 'module:make-middleware';
28
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Create a new middleware class for the specified module.';
35
36
37
    /**
38
     * Get default namespace.
39
     *
40
     * @return string
41
     */
42 2
    public function getDefaultNamespace()
43
    {
44 2
        return 'Http\Middleware';
45
    }
46
47
48
    /**
49
     * Get the console command arguments.
50
     *
51
     * @return array
52
     */
53 60
    protected function getArguments()
54
    {
55
        return [
56 60
            ['name', InputArgument::REQUIRED, 'The name of the command.'],
57
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
58
        ];
59
    }
60
61
62
    /**
63
     * @return mixed
64
     */
65 2
    protected function getTemplateContents()
66
    {
67 2
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
68
69 2
        return (new Stub('/middleware.stub', [
70 2
            'NAMESPACE' => $this->getClassNamespace($module),
71 2
            'CLASS'     => $this->getClass(),
72 2
        ]))->render();
73
    }
74
75
76
    /**
77
     * @return mixed
78
     */
79 2
    protected function getDestinationFilePath()
80
    {
81 2
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
82
83 2
        $seederPath = $this->laravel['modules']->config('paths.generator.filter');
84
85 2
        return $path.$seederPath.'/'.$this->getFileName().'.php';
86
    }
87
88
89
    /**
90
     * @return string
91
     */
92 2
    private function getFileName()
93
    {
94 2
        return Str::studly($this->argument('name'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('name') targeting Illuminate\Console\Command::argument() can also be of type array; however, Illuminate\Support\Str::studly() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
95
    }
96
}
97