Completed
Push — master ( 4fafa1...e65f27 )
by Nicolas
12:12
created

src/Commands/EventMakeCommand.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Illuminate\Support\Str;
6
use Nwidart\Modules\Support\Config\GenerateConfigReader;
7
use Nwidart\Modules\Support\Stub;
8
use Nwidart\Modules\Traits\ModuleCommandTrait;
9
use Symfony\Component\Console\Input\InputArgument;
10
11 View Code Duplication
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 4
    public function getTemplateContents()
32
    {
33 4
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
34
35 4
        return (new Stub('/event.stub', [
36 4
            'NAMESPACE' => $this->getClassNamespace($module),
37 4
            'CLASS' => $this->getClass(),
38 4
        ]))->render();
39
    }
40
41 4
    public function getDestinationFilePath()
42
    {
43 4
        $path       = $this->laravel['modules']->getModulePath($this->getModuleName());
44
45 4
        $eventPath = GenerateConfigReader::read('event');
46
47 4
        return $path . $eventPath->getPath() . '/' . $this->getFileName() . '.php';
48
    }
49
50
    /**
51
     * @return string
52
     */
53 4
    protected function getFileName()
54
    {
55 4
        return Str::studly($this->argument('name'));
0 ignored issues
show
It seems like $this->argument('name') targeting Illuminate\Console\Command::argument() can also be of type array or null; 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...
56
    }
57
58 4
    public function getDefaultNamespace() : string
59
    {
60 4
        $module = $this->laravel['modules'];
61
62 4
        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 120
    protected function getArguments()
71
    {
72
        return [
73 120
            ['name', InputArgument::REQUIRED, 'The name of the event.'],
74
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
75
        ];
76
    }
77
}
78