Conditions | 10 |
Paths | 15 |
Total Lines | 43 |
Code Lines | 26 |
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 |
||
72 | private function parseValidationRules($id, $rules, $name) |
||
73 | { |
||
74 | if (is_string($rules)) { |
||
75 | $exp = explode('|', $rules); |
||
76 | } elseif(is_array($rules)) { |
||
77 | $exp = $rules; |
||
78 | } |
||
79 | |||
80 | $uniqueRules = array_filter($exp, function($item){ |
||
|
|||
81 | return starts_with($item, 'unique'); |
||
82 | }); |
||
83 | |||
84 | foreach ($uniqueRules as &$validationItem) { |
||
85 | $parseUnique = explode(',', str_replace('unique:', '', $validationItem)); |
||
86 | $uniqueTable = ($parseUnique[0]) ?: $this->table; |
||
87 | $uniqueColumn = ($parseUnique[1]) ?: $name; |
||
88 | $uniqueIgnoreId = ($parseUnique[2]) ?: (($id) ?: ''); |
||
89 | |||
90 | //Make sure table name |
||
91 | $uniqueTable = CRUDBooster::parseSqlTable($uniqueTable)['table']; |
||
92 | |||
93 | //Rebuild unique rule |
||
94 | $uniqueRebuild = []; |
||
95 | $uniqueRebuild[] = $uniqueTable; |
||
96 | $uniqueRebuild[] = $uniqueColumn; |
||
97 | |||
98 | if ($uniqueIgnoreId) { |
||
99 | $uniqueRebuild[] = $uniqueIgnoreId; |
||
100 | } else { |
||
101 | $uniqueRebuild[] = 'NULL'; |
||
102 | } |
||
103 | |||
104 | //Check whether deleted_at exists or not |
||
105 | if (\Schema::hasColumn($uniqueTable, 'deleted_at')) { |
||
106 | $uniqueRebuild[] = DbInspector::findPK($uniqueTable); |
||
107 | $uniqueRebuild[] = 'deleted_at'; |
||
108 | $uniqueRebuild[] = 'NULL'; |
||
109 | } |
||
110 | $uniqueRebuild = array_filter($uniqueRebuild); |
||
111 | $validationItem = 'unique:'.implode(',', $uniqueRebuild); |
||
112 | } |
||
113 | |||
114 | return implode('|', $exp); |
||
115 | } |
||
134 | } |