Code Duplication    Length = 86-86 lines in 2 locations

src/Commands/GenerateMiddlewareCommand.php 1 location

@@ 10-95 (lines=86) @@
7
use Consigliere\Components\Traits\ComponentCommandTrait;
8
use Symfony\Component\Console\Input\InputArgument;
9
10
class GenerateMiddlewareCommand extends Command
11
{
12
    use ComponentCommandTrait;
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 = 'component:make-middleware';
27
28
    /**
29
     * The console command description.
30
     *
31
     * @var string
32
     */
33
    protected $description = 'Generate new middleware class for the specified component.';
34
35
    /**
36
     * Get the console command arguments.
37
     *
38
     * @return array
39
     */
40
    protected function getArguments()
41
    {
42
        return [
43
            ['name', InputArgument::REQUIRED, 'The name of the command.'],
44
            ['component', InputArgument::OPTIONAL, 'The name of component will be used.'],
45
        ];
46
    }
47
48
    /**
49
     * @return mixed
50
     */
51
    protected function getTemplateContents()
52
    {
53
        $component = $this->laravel['components']->findOrFail($this->getComponentName());
54
55
        return (new Stub('/middleware.stub', [
56
            'NAMESPACE'           => $this->getClassNamespace($component),
57
            'CLASS'               => $this->getClass(),
58
            'LOWER_NAME'          => $component->getLowerName(),
59
            'COMPONENT'           => $this->getComponentName(),
60
            'NAME'                => $this->getFileName(),
61
            'STUDLY_NAME'         => $this->getFileName(),
62
            'COMPONENT_NAMESPACE' => $this->laravel['components']->config('namespace'),
63
        ]))->render();
64
    }
65
66
    /**
67
     * @return mixed
68
     */
69
    protected function getDestinationFilePath()
70
    {
71
        $path = $this->laravel['components']->getComponentPath($this->getComponentName());
72
73
        $seederPath = $this->laravel['components']->config('paths.generator.middleware');
74
75
        return $path . $seederPath . '/' . $this->getFileName() . '.php';
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    private function getFileName()
82
    {
83
        return Str::studly($this->argument('name'));
84
    }
85
86
    /**
87
     * Get default namespace.
88
     *
89
     * @return string
90
     */
91
    public function getDefaultNamespace()
92
    {
93
        return 'Http\Middleware';
94
    }
95
}
96

src/Commands/MakeRequestCommand.php 1 location

@@ 10-95 (lines=86) @@
7
use Consigliere\Components\Traits\ComponentCommandTrait;
8
use Symfony\Component\Console\Input\InputArgument;
9
10
class MakeRequestCommand extends Command
11
{
12
    use ComponentCommandTrait;
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 = 'component: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 component.';
34
35
    /**
36
     * Get the console command arguments.
37
     *
38
     * @return array
39
     */
40
    protected function getArguments()
41
    {
42
        return [
43
            ['name', InputArgument::REQUIRED, 'The name of the form request class.'],
44
            ['component', InputArgument::OPTIONAL, 'The name of component will be used.'],
45
        ];
46
    }
47
48
    /**
49
     * @return mixed
50
     */
51
    protected function getTemplateContents()
52
    {
53
        $component = $this->laravel['components']->findOrFail($this->getComponentName());
54
55
        return (new Stub('/request.stub', [
56
            'NAMESPACE'           => $this->getClassNamespace($component),
57
            'CLASS'               => $this->getClass(),
58
            'LOWER_NAME'          => $component->getLowerName(),
59
            'COMPONENT'           => $this->getComponentName(),
60
            'NAME'                => $this->getFileName(),
61
            'STUDLY_NAME'         => $component->getStudlyName(),
62
            'COMPONENT_NAMESPACE' => $this->laravel['components']->config('namespace'),
63
        ]))->render();
64
    }
65
66
    /**
67
     * @return mixed
68
     */
69
    protected function getDestinationFilePath()
70
    {
71
        $path = $this->laravel['components']->getComponentPath($this->getComponentName());
72
73
        $seederPath = $this->laravel['components']->config('paths.generator.request');
74
75
        return $path . $seederPath . '/' . $this->getFileName() . '.php';
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    private function getFileName()
82
    {
83
        return Str::studly($this->argument('name'));
84
    }
85
86
    /**
87
     * Get default namespace.
88
     *
89
     * @return string
90
     */
91
    public function getDefaultNamespace()
92
    {
93
        return 'Http\Requests';
94
    }
95
}
96