ControllerApiMakeCommand::replaceClass()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 7
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 12
rs 10
1
<?php
2
3
namespace Blok\Repository\Commands;
4
5
use Illuminate\Console\GeneratorCommand;
0 ignored issues
show
Bug introduced by
The type Illuminate\Console\GeneratorCommand was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\Console\Input\InputArgument;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputArgument was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\Console\Input\InputOption;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputOption was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class ControllerApiMakeCommand extends GeneratorCommand
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'make:apicontroller';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Create a new ApiController class based on Repository';
24
25
    /**
26
     * The type of class being generated.
27
     *
28
     * @var string
29
     */
30
    protected $type = 'Controller';
31
32
    /**
33
     * Get the stub file for the generator.
34
     *
35
     * @return string
36
     */
37
    protected function getStub()
38
    {
39
        return __DIR__.'/stubs/apicontroller.stub';
40
    }
41
42
    /**
43
     * Replace the class name for the given stub.
44
     *
45
     * @param  string  $stub
46
     * @param  string  $name
47
     * @return string
48
     */
49
    protected function replaceClass($stub, $name)
50
    {
51
        $class = str_replace($this->getNamespace($name).'\\', '', $name);
52
53
        if ($this->option('repository')) {
54
            $repository = $this->option('repository');
55
        } else {
56
            $repositoryName = "\App\\Repositories\\".str_replace("Controller", "", $class).'Repository';
57
            $repository = $this->ask("From which repository do you want to create the repository ?", $repositoryName);
58
        }
59
60
        return str_replace(['DummyClass', 'DummyRepository'], [$class, $repository], $stub);
61
    }
62
63
    /**
64
     * Get the default namespace for the class.
65
     *
66
     * @param  string  $rootNamespace
67
     * @return string
68
     */
69
    protected function getDefaultNamespace($rootNamespace)
70
    {
71
        return $rootNamespace.'\Http\Controllers\Api';
72
    }
73
74
75
76
    /**
77
     * Get the console command arguments.
78
     *
79
     * @return array
80
     */
81
    protected function getArguments()
82
    {
83
        return [
84
            [
85
                'name', InputArgument::REQUIRED, 'The name of the Repository'
86
            ],
87
        ];
88
    }
89
90
    /**
91
     * Get the console command options.
92
     *
93
     * @return array
94
     */
95
    protected function getOptions()
96
    {
97
        return [
98
            ['repository', 'r', InputOption::VALUE_OPTIONAL, 'The base repository of this controller.'],
99
        ];
100
    }
101
}
102