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 Encore\Admin\Console; |
||
4 | |||
5 | use Illuminate\Console\GeneratorCommand; |
||
6 | |||
7 | class FormCommand extends GeneratorCommand |
||
8 | { |
||
9 | /** |
||
10 | * The console command name. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $signature = 'admin:form {name} |
||
15 | {--title=} |
||
16 | {--step} |
||
17 | {--namespace=}'; |
||
18 | |||
19 | /** |
||
20 | * The console command description. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $description = 'Make admin form widget'; |
||
25 | |||
26 | /** |
||
27 | * Replace the class name for the given stub. |
||
28 | * |
||
29 | * @param string $stub |
||
30 | * @param string $name |
||
31 | * |
||
32 | * @return string |
||
33 | */ |
||
34 | protected function replaceClass($stub, $name) |
||
35 | { |
||
36 | $stub = parent::replaceClass($stub, $name); |
||
37 | |||
38 | return str_replace('DummyTitle', $this->option('title'), $stub); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Get the stub file for the generator. |
||
43 | * |
||
44 | * @return string |
||
45 | */ |
||
46 | protected function getStub() |
||
47 | { |
||
48 | if ($this->option('step')) { |
||
49 | return __DIR__.'/stubs/step-form.stub'; |
||
50 | } |
||
51 | |||
52 | return __DIR__.'/stubs/form.stub'; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Get the default namespace for the class. |
||
57 | * |
||
58 | * @param string $rootNamespace |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | protected function getDefaultNamespace($rootNamespace) |
||
63 | { |
||
64 | if ($namespace = $this->option('namespace')) { |
||
65 | return $namespace; |
||
0 ignored issues
–
show
|
|||
66 | } |
||
67 | |||
68 | return str_replace('Controllers', 'Forms', config('admin.route.namespace')); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Get the desired class name from the input. |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | protected function getNameInput() |
||
77 | { |
||
78 | $name = trim($this->argument('name')); |
||
79 | |||
80 | $this->type = $this->qualifyClass($name); |
||
81 | |||
82 | return $name; |
||
83 | } |
||
84 | } |
||
85 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.