GenerateNotificationCommand::getTemplateContents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Consigliere\Components\Commands;
4
5
use Consigliere\Components\Support\Stub;
6
use Consigliere\Components\Traits\ComponentCommandTrait;
7
use Symfony\Component\Console\Input\InputArgument;
8
9 View Code Duplication
final class GenerateNotificationCommand 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...
10
{
11
    use ComponentCommandTrait;
12
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'component:make-notification';
19
20
    protected $argumentName = 'name';
21
22
    /**
23
     * Get template contents.
24
     *
25
     * @return string
26
     */
27
    protected function getTemplateContents()
28
    {
29
        $component = $this->laravel['components']->findOrFail($this->getComponentName());
30
31
        return (new Stub('/notification.stub', [
32
            'NAMESPACE' => $this->getClassNamespace($component),
33
            'CLASS'     => $this->getClass(),
34
        ]))->render();
35
    }
36
37
    /**
38
     * Get the destination file path.
39
     *
40
     * @return string
41
     */
42
    protected function getDestinationFilePath()
43
    {
44
        $path = $this->laravel['components']->getComponentPath($this->getComponentName());
45
46
        $mailPath = $this->laravel['components']->config('paths.generator.notifications', 'Notifications');
47
48
        return $path . $mailPath . '/' . $this->getFileName() . '.php';
49
    }
50
51
    /**
52
     * Get the console command arguments.
53
     *
54
     * @return array
55
     */
56
    protected function getArguments()
57
    {
58
        return [
59
            ['name', InputArgument::REQUIRED, 'The name of the notification class.'],
60
            ['component', InputArgument::OPTIONAL, 'The name of component will be used.'],
61
        ];
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    private function getFileName()
68
    {
69
        return studly_case($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, studly_case() 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...
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getDefaultNamespace()
76
    {
77
        return $this->laravel['components']->config('paths.generator.notifications', 'Notifications');
78
    }
79
}
80