Conditions | 10 |
Paths | 1 |
Total Lines | 41 |
Lines | 3 |
Ratio | 7.32 % |
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; |
||
103 | protected function buildClass() : string { |
||
104 | |||
105 | //Set belongsTo Relations |
||
106 | $this->setBelongsToRelations(); |
||
107 | return view('jig::'.$this->view, [ |
||
108 | 'controllerBaseName' => $this->classBaseName, |
||
109 | 'controllerNamespace' => $this->classNamespace, |
||
110 | 'repoBaseName' => $this->getRepositoryBaseName(), |
||
111 | "repoFullName" => $this->getRepoNamespace($this->rootNamespace()).'\\'.$this->getRepositoryBaseName(), |
||
112 | 'modelBaseName' => $this->modelBaseName, |
||
113 | 'modelFullName' => $this->modelFullName, |
||
114 | 'modelPlural' => $this->modelPlural, |
||
115 | 'modelTitle' => $this->titleSingular, |
||
116 | 'modelVariableName' => $this->modelVariableName, |
||
117 | 'modelRouteAndViewName' => $this->modelRouteAndViewName, |
||
118 | 'modelViewsDirectory' => $this->modelViewsDirectory, |
||
119 | 'modelDotNotation' => $this->modelDotNotation, |
||
120 | 'modelWithNamespaceFromDefault' => $this->modelWithNamespaceFromDefault, |
||
121 | 'export' => $this->export, |
||
122 | 'withoutBulk' => $this->withoutBulk, |
||
123 | 'exportBaseName' => $this->exportBaseName, |
||
124 | 'resource' => $this->resource, |
||
125 | 'containsPublishedAtColumn' => in_array("published_at", array_column($this->readColumnsFromTable($this->tableName)->toArray(), 'name')), |
||
126 | // index |
||
127 | 'columnsToQuery' => $this->readColumnsFromTable($this->tableName)->filter(function($column) { |
||
128 | return !($column['type'] == 'text' || $column['name'] == "password" || $column['name'] == "remember_token" || $column['name'] == "deleted_at"||Str::contains($column['name'],"_id")); |
||
129 | })->pluck('name')->toArray(), |
||
130 | 'columnsToSearchIn' => $this->readColumnsFromTable($this->tableName)->filter(function($column) { |
||
131 | return ($column['type'] == 'json' || $column['type'] == 'text' || $column['type'] == 'string' || $column['name'] == "id") && !($column['name'] == "password" || $column['name'] == "remember_token"); |
||
132 | })->pluck('name')->toArray(), |
||
133 | // 'filters' => $this->readColumnsFromTable($tableName)->filter(function($column) { |
||
134 | // return $column['type'] == 'boolean' || $column['type'] == 'date'; |
||
135 | // }), |
||
136 | // validation in store/update |
||
137 | 'columns' => $this->getVisibleColumns($this->tableName, $this->modelVariableName), |
||
138 | 'relations' => $this->relations, |
||
139 | 'hasSoftDelete' => $this->readColumnsFromTable($this->tableName)->filter(function($column) { |
||
140 | return $column['name'] == "deleted_at"; |
||
141 | })->count() > 0, |
||
142 | ])->render(); |
||
143 | } |
||
144 | |||
181 |