Conditions | 20 |
Paths | 1 |
Total Lines | 56 |
Lines | 0 |
Ratio | 0 % |
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; |
||
53 | protected function buildClass(): string |
||
54 | { |
||
55 | |||
56 | return view('jig::'.$this->view, [ |
||
57 | 'modelFullName' => $this->modelFullName, |
||
58 | |||
59 | 'columns' => $this->readColumnsFromTable($this->tableName) |
||
60 | // we skip primary key |
||
61 | ->filter(function($col){ |
||
62 | return $col['name'] != 'id'; |
||
63 | }) |
||
64 | ->map(function($col) { |
||
65 | if($col['name'] == 'deleted_at') { |
||
66 | $type = 'null'; |
||
67 | } else if($col['name'] == 'remember_token') { |
||
68 | $type = 'null'; |
||
69 | } else { |
||
70 | if ($col['type'] == 'date') { |
||
71 | $type = '$faker->date()'; |
||
72 | } elseif ($col['type'] == 'time') { |
||
73 | $type = '$faker->time()'; |
||
74 | } elseif ($col['type'] == 'datetime') { |
||
75 | $type = '$faker->dateTime'; |
||
76 | } elseif ($col['type'] == 'text') { |
||
77 | $type = '$faker->text()'; |
||
78 | } elseif ($col['type'] == 'boolean') { |
||
79 | $type = '$faker->boolean()'; |
||
80 | } elseif ($col['type'] == 'integer' || $col['type'] == 'numeric' || $col['type'] == 'decimal') { |
||
81 | $type = '$faker->randomNumber(5)'; |
||
82 | } elseif ($col['type'] == 'float') { |
||
83 | $type = '$faker->randomFloat'; |
||
84 | } elseif ($col['name'] == 'title') { |
||
85 | $type = '$faker->sentence'; |
||
86 | } elseif ($col['name'] == 'email') { |
||
87 | $type = '$faker->email'; |
||
88 | } elseif ($col['name'] == 'name' || $col['name'] == 'first_name') { |
||
89 | $type = '$faker->firstName'; |
||
90 | } elseif ($col['name'] == 'surname' || $col['name'] == 'last_name') { |
||
91 | $type = '$faker->lastName'; |
||
92 | } elseif ($col['name'] == 'slug') { |
||
93 | $type = '$faker->unique()->slug'; |
||
94 | } elseif ($col['name'] == 'password') { |
||
95 | $type = 'bcrypt($faker->password)'; |
||
96 | } else { |
||
97 | $type = '$faker->sentence'; |
||
98 | } |
||
99 | } |
||
100 | return [ |
||
101 | 'name' => $col['name'], |
||
102 | 'faker' => $type, |
||
103 | ]; |
||
104 | }), |
||
105 | 'translatable' => $this->readColumnsFromTable($this->tableName)->filter(function($column) { |
||
106 | return $column['type'] == "json"; |
||
107 | })->pluck('name'), |
||
108 | ])->render(); |
||
109 | } |
||
121 |