| Conditions | 13 |
| Paths | 96 |
| Total Lines | 52 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 137 | protected function prepareRelationship($relationship, $relationText = null) |
||
| 138 | { |
||
| 139 | $singularRelation = (false === empty($relationship->relationName)) ? $relationship->relationName : Str::camel(Str::singular($relationText)); |
||
| 140 | $pluralRelation = (false === empty($relationship->relationName)) ? $relationship->relationName : Str::camel(Str::plural($relationText)); |
||
| 141 | |||
| 142 | switch ($relationship->type) { |
||
| 143 | case '1t1': |
||
| 144 | $functionName = $singularRelation; |
||
| 145 | $template = '$FUNCTION_NAME$: $TYPE$$RELATION_GRAPHQL_NAME$'; |
||
| 146 | $templateFile = ''; |
||
| 147 | break; |
||
| 148 | case '1tm': |
||
| 149 | $functionName = $pluralRelation; |
||
| 150 | $template = '$FUNCTION_NAME$: $TYPE$$RELATION_GRAPHQL_NAME$HasMany'; |
||
| 151 | $templateFile = 'hasMany'; |
||
| 152 | break; |
||
| 153 | case 'mt1': |
||
| 154 | if (false === empty($relationship->relationName)) { |
||
| 155 | $singularRelation = $relationship->relationName; |
||
| 156 | } elseif (isset($relationship->inputs[1])) { |
||
| 157 | $singularRelation = Str::camel(str_replace('_id', '', strtolower($relationship->inputs[1]))); |
||
| 158 | } |
||
| 159 | $functionName = $singularRelation; |
||
| 160 | $template = '$FUNCTION_NAME$: $TYPE$$RELATION_GRAPHQL_NAME$BelongsTo'; |
||
| 161 | $templateFile = 'belongsTo'; |
||
| 162 | break; |
||
| 163 | case 'mtm': |
||
| 164 | $functionName = $pluralRelation; |
||
| 165 | $template = '$FUNCTION_NAME$: $TYPE$$RELATION_GRAPHQL_NAME$BelongsToMany'; |
||
| 166 | $templateFile = 'belongsToMany'; |
||
| 167 | break; |
||
| 168 | case 'hmt': |
||
| 169 | $functionName = $pluralRelation; |
||
| 170 | $template = ''; |
||
| 171 | $templateFile = ''; |
||
| 172 | break; |
||
| 173 | default: |
||
| 174 | $functionName = ''; |
||
| 175 | $template = ''; |
||
| 176 | $templateFile = ''; |
||
| 177 | break; |
||
| 178 | } |
||
| 179 | if (false === empty($templateFile)) { |
||
| 180 | $templateFile = get_artomator_template('graphql.relations.'.$templateFile); |
||
| 181 | $templateFile = str_replace('$RELATION_GRAPHQL_NAME$', ucfirst(Str::singular($functionName)), $templateFile); |
||
| 182 | |||
| 183 | if (false === Str::contains($this->fileContents, $templateFile) && false === Str::contains($this->templateData, $templateFile)) { |
||
| 184 | $this->templateData .= $templateFile; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | |||
| 188 | return compact('functionName', 'template'); |
||
| 189 | } |
||
| 191 |