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

ViewModelMakeCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 0
loc 43
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 3
A getStub() 0 4 1
A getDefaultNamespace() 0 8 2
A getOptions() 0 6 1
A isCustomNamespace() 0 4 1
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