Conditions | 12 |
Paths | 1 |
Total Lines | 42 |
Lines | 3 |
Ratio | 7.14 % |
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; |
||
79 | protected function buildClass():string { |
||
80 | |||
81 | //Set belongsTo Relations |
||
82 | $this->setBelongsToRelations(); |
||
83 | return view('jig::'.$this->view, [ |
||
84 | 'controllerBaseName' => $this->classBaseName, |
||
85 | 'controllerNamespace' => $this->classNamespace, |
||
86 | 'repoBaseName' => $this->getRepositoryBaseName(), |
||
87 | "repoFullName" => $this->getRepoNamespace($this->rootNamespace()).'\\'.$this->getRepositoryBaseName(), |
||
88 | 'modelBaseName' => $this->modelBaseName, |
||
89 | 'modelFullName' => $this->modelFullName, |
||
90 | 'modelPlural' => $this->modelPlural, |
||
91 | 'modelTitle' => $this->titleSingular, |
||
92 | 'modelVariableName' => $this->modelVariableName, |
||
93 | 'modelVariableNamePlural' => Str::plural($this->modelVariableName), |
||
94 | 'modelRouteAndViewName' => $this->modelRouteAndViewName, |
||
95 | 'modelViewsDirectory' => $this->modelViewsDirectory, |
||
96 | 'modelDotNotation' => $this->modelDotNotation, |
||
97 | 'modelWithNamespaceFromDefault' => $this->modelWithNamespaceFromDefault, |
||
98 | 'export' => $this->export, |
||
99 | 'withoutBulk' => $this->withoutBulk, |
||
100 | 'exportBaseName' => $this->exportBaseName, |
||
101 | 'resource' => $this->resource, |
||
102 | 'containsPublishedAtColumn' => in_array("published_at", array_column($this->readColumnsFromTable($this->tableName)->toArray(), 'name')), |
||
103 | // index |
||
104 | 'columnsToQuery' => $this->readColumnsFromTable($this->tableName)->filter(function($column) { |
||
105 | return !($column['type'] == 'text' || $column['name'] == "password" || $column['name'] == "remember_token" || $column['name'] == "slug" || $column['name'] == "created_at" || $column['name'] == "deleted_at"||Str::contains($column['name'],"_id")); |
||
106 | })->pluck('name')->toArray(), |
||
107 | 'columnsToSearchIn' => $this->readColumnsFromTable($this->tableName)->filter(function($column) { |
||
108 | return ($column['type'] == 'json' || $column['type'] == 'text' || $column['type'] == 'string' || $column['name'] == "id") && !($column['name'] == "password" || $column['name'] == "remember_token"); |
||
109 | })->pluck('name')->toArray(), |
||
110 | // 'filters' => $this->readColumnsFromTable($tableName)->filter(function($column) { |
||
111 | // return $column['type'] == 'boolean' || $column['type'] == 'date'; |
||
112 | // }), |
||
113 | // validation in store/update |
||
114 | 'columns' => $this->getVisibleColumns($this->tableName, $this->modelVariableName), |
||
115 | 'relations' => $this->relations, |
||
116 | 'hasSoftDelete' => $this->readColumnsFromTable($this->tableName)->filter(function($column) { |
||
117 | return $column['name'] == "deleted_at"; |
||
118 | })->count() > 0, |
||
119 | ])->render(); |
||
120 | } |
||
121 | |||
158 |