Completed
Push — master ( 90fee7...b987a2 )
by Freek
9s
created

ViewModelMakeCommand::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Spatie\ViewModels\Console;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Console\GeneratorCommand;
7
use Symfony\Component\Console\Input\InputOption;
8
9
class ViewModelMakeCommand extends GeneratorCommand
10
{
11
    protected $name = 'make:view-model';
12
13
    protected $description = 'Create a new ViewModel class';
14
15
    protected $type = 'ViewModel';
16
17
    public function handle()
18
    {
19
        if (parent::handle() === false) {
20
            if (! $this->option('force')) {
21
                return;
22
            }
23
        }
24
    }
25
26
    protected function getStub()
27
    {
28
        return __DIR__.'/../../stubs/DummyViewModel.stub';
29
    }
30
31
    protected function getDefaultNamespace($rootNamespace)
32
    {
33
        if ($this->isCustomNamespace()) {
34
            return $rootNamespace;
35
        }
36
37
        return $rootNamespace.'\ViewModels';
38
    }
39
40
    protected function getOptions(): array
41
    {
42
        return [
43
            ['force', null, InputOption::VALUE_NONE, 'Create the class even if the view-model already exists'],
44
        ];
45
    }
46
47
    protected function isCustomNamespace(): bool
48
    {
49
        return Str::contains($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 or null; however, Illuminate\Support\Str::contains() 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...
50
    }
51
}
52