FactoryMakeCommand::getStub()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Larafast\Fastapi\Console\Commands;
4
5
use Larafast\Fastapi\Console\Contracts\GeneratorCommand;
6
use Symfony\Component\Console\Input\InputOption;
7
8
class FactoryMakeCommand extends GeneratorCommand
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $name = 'fastApi:factory';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Create a new model factory';
23
24
    /**
25
     * The type of class being generated.
26
     *
27
     * @var string
28
     */
29
    protected $type = 'Factory';
30
31
    /**
32
     * Get the stub file for the generator.
33
     *
34
     * @return string
35
     */
36
    protected function getStub()
37
    {
38
        return config('fastApi.stubs_dir').'/factory.stub';
39
    }
40
41
    /**
42
     * Build the class with the given name.
43
     *
44
     * @param string $name
45
     *
46
     * @return string
47
     */
48
    protected function buildClass($name)
49
    {
50
        $model = $this->option('model')
51
            ? $this->qualifyClass($this->option('model'))
0 ignored issues
show
Bug introduced by
It seems like $this->option('model') can also be of type string[]; however, parameter $name of Larafast\Fastapi\Console...Command::qualifyClass() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
            ? $this->qualifyClass(/** @scrutinizer ignore-type */ $this->option('model'))
Loading history...
52
            : 'Model';
53
54
        return str_replace(
55
            'DummyModel', $model, parent::buildClass($name)
56
        );
57
    }
58
59
    /**
60
     * Get the destination class path.
61
     *
62
     * @param string $name
63
     *
64
     * @return string
65
     */
66
    protected function getPath($name)
67
    {
68
        $name = str_replace(
69
            ['\\', '/'], '', $this->argument('name')
70
        );
71
72
        return $this->laravel->databasePath() . "/factories/{$name}.php";
73
    }
74
75
    /**
76
     * Get the console command options.
77
     *
78
     * @return array
79
     */
80
    protected function getOptions()
81
    {
82
        return [
83
            ['model', 'm', InputOption::VALUE_OPTIONAL, 'The name of the model'],
84
        ];
85
    }
86
}
87