Code Duplication    Length = 67-78 lines in 7 locations

src/Commands/EventMakeCommand.php 1 location

@@ 11-77 (lines=67) @@
8
use Nwidart\Modules\Traits\ModuleCommandTrait;
9
use Symfony\Component\Console\Input\InputArgument;
10
11
class EventMakeCommand extends GeneratorCommand
12
{
13
    use ModuleCommandTrait;
14
15
    protected $argumentName = 'name';
16
17
    /**
18
     * The console command name.
19
     *
20
     * @var string
21
     */
22
    protected $name = 'module:make-event';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Create a new event class for the specified module';
30
31
    public function getTemplateContents()
32
    {
33
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
34
35
        return (new Stub('/event.stub', [
36
            'NAMESPACE' => $this->getClassNamespace($module),
37
            'CLASS' => $this->getClass(),
38
        ]))->render();
39
    }
40
41
    public function getDestinationFilePath()
42
    {
43
        $path       = $this->laravel['modules']->getModulePath($this->getModuleName());
44
45
        $eventPath = GenerateConfigReader::read('event');
46
47
        return $path . $eventPath->getPath() . '/' . $this->getFileName() . '.php';
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    protected function getFileName()
54
    {
55
        return Str::studly($this->argument('name'));
56
    }
57
58
    public function getDefaultNamespace() : string
59
    {
60
        $module = $this->laravel['modules'];
61
62
        return $module->config('paths.generator.event.namespace') ?: $module->config('paths.generator.event.path', 'Events');
63
    }
64
65
    /**
66
     * Get the console command arguments.
67
     *
68
     * @return array
69
     */
70
    protected function getArguments()
71
    {
72
        return [
73
            ['name', InputArgument::REQUIRED, 'The name of the event.'],
74
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
75
        ];
76
    }
77
}
78

src/Commands/MailMakeCommand.php 1 location

@@ 11-87 (lines=77) @@
8
use Nwidart\Modules\Traits\ModuleCommandTrait;
9
use Symfony\Component\Console\Input\InputArgument;
10
11
class MailMakeCommand extends GeneratorCommand
12
{
13
    use ModuleCommandTrait;
14
15
    /**
16
     * The console command name.
17
     *
18
     * @var string
19
     */
20
    protected $name = 'module:make-mail';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Create a new email class for the specified module';
28
29
    protected $argumentName = 'name';
30
31
    public function getDefaultNamespace() : string
32
    {
33
        $module = $this->laravel['modules'];
34
35
        return $module->config('paths.generator.emails.namespace') ?: $module->config('paths.generator.emails.path', 'Emails');
36
    }
37
38
    /**
39
     * Get the console command arguments.
40
     *
41
     * @return array
42
     */
43
    protected function getArguments()
44
    {
45
        return [
46
            ['name', InputArgument::REQUIRED, 'The name of the mailable.'],
47
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
48
        ];
49
    }
50
51
    /**
52
     * Get template contents.
53
     *
54
     * @return string
55
     */
56
    protected function getTemplateContents()
57
    {
58
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
59
60
        return (new Stub('/mail.stub', [
61
            'NAMESPACE' => $this->getClassNamespace($module),
62
            'CLASS'     => $this->getClass(),
63
        ]))->render();
64
    }
65
66
    /**
67
     * Get the destination file path.
68
     *
69
     * @return string
70
     */
71
    protected function getDestinationFilePath()
72
    {
73
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
74
75
        $mailPath = GenerateConfigReader::read('emails');
76
77
        return $path . $mailPath->getPath() . '/' . $this->getFileName() . '.php';
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    private function getFileName()
84
    {
85
        return Str::studly($this->argument('name'));
86
    }
87
}
88

src/Commands/MiddlewareMakeCommand.php 1 location

@@ 11-88 (lines=78) @@
8
use Nwidart\Modules\Traits\ModuleCommandTrait;
9
use Symfony\Component\Console\Input\InputArgument;
10
11
class MiddlewareMakeCommand extends GeneratorCommand
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
    public function getDefaultNamespace() : string
37
    {
38
        $module = $this->laravel['modules'];
39
40
        return $module->config('paths.generator.filter.namespace') ?: $module->config('paths.generator.filter.path', 'Http/Middleware');
41
    }
42
43
    /**
44
     * Get the console command arguments.
45
     *
46
     * @return array
47
     */
48
    protected function getArguments()
49
    {
50
        return [
51
            ['name', InputArgument::REQUIRED, 'The name of the command.'],
52
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
53
        ];
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59
    protected function getTemplateContents()
60
    {
61
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
62
63
        return (new Stub('/middleware.stub', [
64
            'NAMESPACE' => $this->getClassNamespace($module),
65
            'CLASS'     => $this->getClass(),
66
        ]))->render();
67
    }
68
69
    /**
70
     * @return mixed
71
     */
72
    protected function getDestinationFilePath()
73
    {
74
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
75
76
        $middlewarePath = GenerateConfigReader::read('filter');
77
78
        return $path . $middlewarePath->getPath() . '/' . $this->getFileName() . '.php';
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    private function getFileName()
85
    {
86
        return Str::studly($this->argument('name'));
87
    }
88
}
89

src/Commands/NotificationMakeCommand.php 1 location

@@ 11-87 (lines=77) @@
8
use Nwidart\Modules\Traits\ModuleCommandTrait;
9
use Symfony\Component\Console\Input\InputArgument;
10
11
final class NotificationMakeCommand extends GeneratorCommand
12
{
13
    use ModuleCommandTrait;
14
15
    /**
16
     * The console command name.
17
     *
18
     * @var string
19
     */
20
    protected $name = 'module:make-notification';
21
22
    protected $argumentName = 'name';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Create a new notification class for the specified module.';
30
31
    public function getDefaultNamespace() : string
32
    {
33
        $module = $this->laravel['modules'];
34
35
        return $module->config('paths.generator.notifications.namespace') ?: $module->config('paths.generator.notifications.path', 'Notifications');
36
    }
37
38
    /**
39
     * Get template contents.
40
     *
41
     * @return string
42
     */
43
    protected function getTemplateContents()
44
    {
45
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
46
47
        return (new Stub('/notification.stub', [
48
            'NAMESPACE' => $this->getClassNamespace($module),
49
            'CLASS'     => $this->getClass(),
50
        ]))->render();
51
    }
52
53
    /**
54
     * Get the destination file path.
55
     *
56
     * @return string
57
     */
58
    protected function getDestinationFilePath()
59
    {
60
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
61
62
        $notificationPath = GenerateConfigReader::read('notifications');
63
64
        return $path . $notificationPath->getPath() . '/' . $this->getFileName() . '.php';
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    private function getFileName()
71
    {
72
        return Str::studly($this->argument('name'));
73
    }
74
75
    /**
76
     * Get the console command arguments.
77
     *
78
     * @return array
79
     */
80
    protected function getArguments()
81
    {
82
        return [
83
            ['name', InputArgument::REQUIRED, 'The name of the notification class.'],
84
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
85
        ];
86
    }
87
}
88

src/Commands/PolicyMakeCommand.php 1 location

@@ 11-88 (lines=78) @@
8
use Nwidart\Modules\Traits\ModuleCommandTrait;
9
use Symfony\Component\Console\Input\InputArgument;
10
11
class PolicyMakeCommand extends GeneratorCommand
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-policy';
28
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Create a new policy class for the specified module.';
35
36
    public function getDefaultNamespace() : string
37
    {
38
        $module = $this->laravel['modules'];
39
40
        return $module->config('paths.generator.policies.namespace') ?: $module->config('paths.generator.policies.path', 'Policies');
41
    }
42
43
    /**
44
     * Get the console command arguments.
45
     *
46
     * @return array
47
     */
48
    protected function getArguments()
49
    {
50
        return [
51
            ['name', InputArgument::REQUIRED, 'The name of the policy class.'],
52
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
53
        ];
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59
    protected function getTemplateContents()
60
    {
61
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
62
63
        return (new Stub('/policy.plain.stub', [
64
            'NAMESPACE' => $this->getClassNamespace($module),
65
            'CLASS'     => $this->getClass(),
66
        ]))->render();
67
    }
68
69
    /**
70
     * @return mixed
71
     */
72
    protected function getDestinationFilePath()
73
    {
74
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
75
76
        $policyPath = GenerateConfigReader::read('policies');
77
78
        return $path . $policyPath->getPath() . '/' . $this->getFileName() . '.php';
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    private function getFileName()
85
    {
86
        return Str::studly($this->argument('name'));
87
    }
88
}
89

src/Commands/RequestMakeCommand.php 1 location

@@ 11-88 (lines=78) @@
8
use Nwidart\Modules\Traits\ModuleCommandTrait;
9
use Symfony\Component\Console\Input\InputArgument;
10
11
class RequestMakeCommand extends GeneratorCommand
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-request';
28
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Create a new form request class for the specified module.';
35
36
    public function getDefaultNamespace() : string
37
    {
38
        $module = $this->laravel['modules'];
39
40
        return $module->config('paths.generator.request.namespace') ?: $module->config('paths.generator.request.path', 'Http/Requests');
41
    }
42
43
    /**
44
     * Get the console command arguments.
45
     *
46
     * @return array
47
     */
48
    protected function getArguments()
49
    {
50
        return [
51
            ['name', InputArgument::REQUIRED, 'The name of the form request class.'],
52
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
53
        ];
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59
    protected function getTemplateContents()
60
    {
61
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
62
63
        return (new Stub('/request.stub', [
64
            'NAMESPACE' => $this->getClassNamespace($module),
65
            'CLASS'     => $this->getClass(),
66
        ]))->render();
67
    }
68
69
    /**
70
     * @return mixed
71
     */
72
    protected function getDestinationFilePath()
73
    {
74
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
75
76
        $requestPath = GenerateConfigReader::read('request');
77
78
        return $path . $requestPath->getPath() . '/' . $this->getFileName() . '.php';
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    private function getFileName()
85
    {
86
        return Str::studly($this->argument('name'));
87
    }
88
}
89

src/Commands/RuleMakeCommand.php 1 location

@@ 11-88 (lines=78) @@
8
use Nwidart\Modules\Traits\ModuleCommandTrait;
9
use Symfony\Component\Console\Input\InputArgument;
10
11
class RuleMakeCommand extends GeneratorCommand
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-rule';
28
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Create a new validation rule for the specified module.';
35
36
    public function getDefaultNamespace() : string
37
    {
38
        $module = $this->laravel['modules'];
39
40
        return $module->config('paths.generator.rules.namespace') ?: $module->config('paths.generator.rules.path', 'Rules');
41
    }
42
43
    /**
44
     * Get the console command arguments.
45
     *
46
     * @return array
47
     */
48
    protected function getArguments()
49
    {
50
        return [
51
            ['name', InputArgument::REQUIRED, 'The name of the rule class.'],
52
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
53
        ];
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59
    protected function getTemplateContents()
60
    {
61
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
62
63
        return (new Stub('/rule.stub', [
64
            'NAMESPACE' => $this->getClassNamespace($module),
65
            'CLASS'     => $this->getClass(),
66
        ]))->render();
67
    }
68
69
    /**
70
     * @return mixed
71
     */
72
    protected function getDestinationFilePath()
73
    {
74
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
75
76
        $rulePath = GenerateConfigReader::read('rules');
77
78
        return $path . $rulePath->getPath() . '/' . $this->getFileName() . '.php';
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    private function getFileName()
85
    {
86
        return Str::studly($this->argument('name'));
87
    }
88
}
89