Conditions | 18 |
Paths | 1 |
Total Lines | 47 |
Lines | 3 |
Ratio | 6.38 % |
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; |
||
78 | protected function buildView(): string |
||
79 | { |
||
80 | |||
81 | return view('jig::'.$this->view, [ |
||
82 | 'modelBaseName' => $this->modelBaseName, |
||
83 | 'modelRouteAndViewName' => str_plural($this->modelRouteAndViewName), |
||
84 | 'modelPlural' => $this->modelPlural, |
||
85 | 'modelViewsDirectory' => $this->modelViewsDirectory, |
||
86 | 'modelJSName' => $this->modelJSName, |
||
87 | 'modelVariableName' => $this->modelVariableName, |
||
88 | 'modelDotNotation' => $this->modelDotNotation, |
||
89 | 'modelLangFormat' => $this->modelLangFormat, |
||
90 | 'modelTitle' => $this->titleSingular, |
||
91 | 'modelTitlePlural' => $this->titlePlural, |
||
92 | 'resource' => $this->resource, |
||
93 | 'export' => $this->export, |
||
94 | 'containsPublishedAtColumn' => in_array("published_at", array_column($this->readColumnsFromTable($this->tableName)->toArray(), 'name')), |
||
95 | 'withoutBulk' => $this->withoutBulk, |
||
96 | 'columnsToQuery' => $this->readColumnsFromTable($this->tableName)->filter(function($column) { |
||
97 | 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")); |
||
98 | })->pluck('name')->toArray(), |
||
99 | 'columns' => $this->readColumnsFromTable($this->tableName)->reject(function($column) { |
||
100 | return ($column['type'] == 'text' |
||
101 | || in_array($column['name'], ["password", "remember_token", "slug", "created_at", "updated_at", "deleted_at"]) |
||
102 | || ($column['type'] == 'json' && in_array($column['name'], ["perex", "text", "body"])) |
||
103 | ); |
||
104 | })->map(function($col){ |
||
105 | |||
106 | $filters = collect([]); |
||
107 | $col['switch'] = false; |
||
108 | |||
109 | if ($col['type'] == 'date' || $col['type'] == 'time' || $col['type'] == 'datetime') { |
||
110 | $filters->push($col['type']); |
||
111 | } |
||
112 | |||
113 | if ($col['type'] == 'boolean' && ($col['name'] == 'enabled' || $col['name'] == 'activated' || $col['name'] == 'is_published')) { |
||
114 | $col['switch'] = true; |
||
115 | } |
||
116 | |||
117 | $col['filters'] = $filters->isNotEmpty() ? ' | '.implode(' | ', $filters->toArray()) : ''; |
||
118 | |||
119 | return $col; |
||
120 | }), |
||
121 | // 'filters' => $this->readColumnsFromTable($tableName)->filter(function($column) { |
||
122 | // return $column['type'] == 'boolean' || $column['type'] == 'date'; |
||
123 | // }), |
||
124 | ])->render(); |
||
125 | } |
||
138 |