Conditions | 10 |
Paths | 1 |
Total Lines | 40 |
Lines | 3 |
Ratio | 7.5 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php namespace Savannabits\JetstreamInertiaGenerator\Generators; |
||
71 | protected function buildClass(): string { |
||
72 | |||
73 | //Set belongsTo Relations |
||
74 | $this->setBelongsToRelations(); |
||
75 | |||
76 | return view('jig::'.$this->view, [ |
||
77 | 'repoBaseName' => $this->classBaseName, |
||
78 | 'repoNamespace' => $this->classNamespace, |
||
79 | 'modelBaseName' => $this->modelBaseName, |
||
80 | 'modelFullName' => $this->modelFullName, |
||
81 | 'modelPlural' => $this->modelPlural, |
||
82 | 'modelTitle' => $this->titleSingular, |
||
83 | 'modelVariableName' => $this->modelVariableName, |
||
84 | 'modelVariableNamePlural' => Str::plural($this->modelVariableName), |
||
85 | 'modelRouteAndViewName' => $this->modelRouteAndViewName, |
||
86 | 'modelViewsDirectory' => $this->modelViewsDirectory, |
||
87 | 'modelDotNotation' => $this->modelDotNotation, |
||
88 | 'modelWithNamespaceFromDefault' => $this->modelWithNamespaceFromDefault, |
||
89 | 'export' => $this->export, |
||
90 | 'withoutBulk' => $this->withoutBulk, |
||
91 | 'exportBaseName' => $this->exportBaseName, |
||
92 | 'resource' => $this->resource, |
||
93 | // index |
||
94 | 'columnsToQuery' => $this->readColumnsFromTable($this->tableName)->filter(function($column) { |
||
95 | return !($column['type'] == 'text' || $column['name'] == "password" || $column['name'] == "remember_token" || $column['name'] == "deleted_at"||Str::contains($column['name'],"_id")); |
||
96 | })->pluck('name')->toArray(), |
||
97 | 'columnsToSearchIn' => $this->readColumnsFromTable($this->tableName)->filter(function($column) { |
||
98 | return ($column['type'] == 'json' || $column['type'] == 'text' || $column['type'] == 'string' || $column['name'] == "id") && !($column['name'] == "password" || $column['name'] == "remember_token"); |
||
99 | })->pluck('name')->toArray(), |
||
100 | // 'filters' => $this->readColumnsFromTable($tableName)->filter(function($column) { |
||
101 | // return $column['type'] == 'boolean' || $column['type'] == 'date'; |
||
102 | // }), |
||
103 | // validation in store/update |
||
104 | 'columns' => $this->getVisibleColumns($this->tableName, $this->modelVariableName), |
||
105 | 'relations' => $this->relations, |
||
106 | 'hasSoftDelete' => $this->readColumnsFromTable($this->tableName)->filter(function($column) { |
||
107 | return $column['name'] == "deleted_at"; |
||
108 | })->count() > 0, |
||
109 | ])->render(); |
||
110 | } |
||
111 | |||
139 |