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

MakeRequestCommand::getArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Illuminate\Support\Str;
6
use Pingpong\Support\Stub;
7
use Nwidart\Modules\Traits\ModuleCommandTrait;
8
use Symfony\Component\Console\Input\InputArgument;
9
10 View Code Duplication
class MakeRequestCommand 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
    use ModuleCommandTrait;
13
14
    /**
15
     * The name of argument name.
16
     *
17
     * @var string
18
     */
19
    protected $argumentName = 'name';
20
21
    /**
22
     * The console command name.
23
     *
24
     * @var string
25
     */
26
    protected $name = 'module:make-request';
27
28
    /**
29
     * The console command description.
30
     *
31
     * @var string
32
     */
33
    protected $description = 'Generate new form request class for the specified module.';
34
35
    /**
36
     * Get the console command arguments.
37
     *
38
     * @return array
39
     */
40 16
    protected function getArguments()
41
    {
42
        return array(
43 16
            array('name', InputArgument::REQUIRED, 'The name of the form request class.'),
44 16
            array('module', InputArgument::OPTIONAL, 'The name of module will be used.'),
45 16
        );
46
    }
47
48
    /**
49
     * @return mixed
50
     */
51 2
    protected function getTemplateContents()
52
    {
53 2
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
54
55 2
        return (new Stub('/request.stub', [
56 2
            'NAMESPACE'         => $this->getClassNamespace($module),
57 2
            'CLASS'             => $this->getClass(),
58 2
            'LOWER_NAME'        => $module->getLowerName(),
59 2
            'MODULE'            => $this->getModuleName(),
60 2
            'NAME'              => $this->getFileName(),
61 2
            'STUDLY_NAME'       => $module->getStudlyName(),
62 2
            'MODULE_NAMESPACE'  => $this->laravel['modules']->config('namespace'),
63 2
        ]))->render();
64
    }
65
66
    /**
67
     * @return mixed
68
     */
69 2
    protected function getDestinationFilePath()
70
    {
71 2
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
72
73 2
        $seederPath = $this->laravel['modules']->config('paths.generator.request');
74
75 2
        return $path.$seederPath.'/'.$this->getFileName().'.php';
76
    }
77
78
    /**
79
     * @return string
80
     */
81 2
    private function getFileName()
82
    {
83 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...
84
    }
85
86
    /**
87
     * Get default namespace.
88
     *
89
     * @return string
90
     */
91 2
    public function getDefaultNamespace()
92
    {
93 2
        return 'Http\Requests';
94
    }
95
}
96