We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 16 | 
| Paths | 122 | 
| Total Lines | 77 | 
| Code Lines | 37 | 
| 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  | 
            ||
| 79 | private function getRelationDetailsFromInput($input, $crudFields = [], $relationMethod = false)  | 
            ||
| 80 |     { | 
            ||
| 81 | // main entity  | 
            ||
| 82 |         if (empty($crudFields)) { | 
            ||
| 83 | $relationFields = $this->getRelationFields();  | 
            ||
| 84 |         } else { | 
            ||
| 85 | // relations sends the fields that represent them so we can parse the input accordingly.  | 
            ||
| 86 | $relationFields = $crudFields;  | 
            ||
| 87 | |||
| 88 |             foreach ($crudFields as $key => $crudField) { | 
            ||
| 89 |                 if (isset($crudField['subfields'])) { | 
            ||
| 90 |                     foreach ($crudField['subfields'] as $crudSubField) { | 
            ||
| 91 |                         if (isset($crudSubField['relation_type'])) { | 
            ||
| 92 | $relationFields[] = $crudSubField;  | 
            ||
| 93 | }  | 
            ||
| 94 | }  | 
            ||
| 95 | }  | 
            ||
| 96 | }  | 
            ||
| 97 | }  | 
            ||
| 98 | |||
| 99 | //remove fields that are not in the submitted form input  | 
            ||
| 100 |         $relationFields = array_filter($relationFields, function ($field) use ($input) { | 
            ||
| 101 | return Arr::has($input, $field['name']) || isset($input[$field['name']]) || Arr::has($input, Str::afterLast($field['name'], '.'));  | 
            ||
| 102 | });  | 
            ||
| 103 | |||
| 104 | $relationDetails = [];  | 
            ||
| 105 | |||
| 106 |         foreach ($relationFields as $field) { | 
            ||
| 107 | // if relationMethod is set we strip it out of the fieldName that we use to create the relations array  | 
            ||
| 108 | $fieldName = $relationMethod ? Str::after($field['name'], $relationMethod.'.') : $field['name'];  | 
            ||
| 109 | |||
| 110 | $key = Str::before($this->getOnlyRelationEntity(['entity' => $fieldName]), '.');  | 
            ||
| 111 | |||
| 112 | // if the field entity contains the attribute we want to add that attribute in the correct relation key.  | 
            ||
| 113 | // eg: adress.street, we want to add `street` as an attribute in `address` relation, `street` is not  | 
            ||
| 114 | // a relation of `address`  | 
            ||
| 115 |             if ($this->getOnlyRelationEntity($field) !== $field['entity']) { | 
            ||
| 116 |                 if (Str::before($field['entity'], '.') === $relationMethod) { | 
            ||
| 117 | $key = Str::before($this->getOnlyRelationEntity($field), '.');  | 
            ||
| 118 | }  | 
            ||
| 119 | }  | 
            ||
| 120 | |||
| 121 |             $attributeName = (string) Str::of($field['name'])->afterLast('.'); | 
            ||
| 122 | |||
| 123 |             switch ($field['relation_type']) { | 
            ||
| 124 | case 'BelongsTo':  | 
            ||
| 125 | // when it's a nested belongsTo relation we want to make sure  | 
            ||
| 126 | // the key used to store the values is the main relation key  | 
            ||
| 127 | $key = Str::beforeLast($this->getOnlyRelationEntity($field), '.');  | 
            ||
| 128 | |||
| 129 | break;  | 
            ||
| 130 | }  | 
            ||
| 131 | |||
| 132 | // we don't need to re-setup this relation method values, we just want the relations  | 
            ||
| 133 |             if ($key === $relationMethod) { | 
            ||
| 134 | continue;  | 
            ||
| 135 | }  | 
            ||
| 136 | |||
| 137 | $fieldDetails = Arr::get($relationDetails, $key, []);  | 
            ||
| 138 | |||
| 139 | $fieldDetails['values'][$attributeName] = Arr::get($input, $fieldName);  | 
            ||
| 140 | $fieldDetails['model'] = $fieldDetails['model'] ?? $field['model'];  | 
            ||
| 141 | $fieldDetails['relation_type'] = $fieldDetails['relation_type'] ?? $field['relation_type'];  | 
            ||
| 142 | $fieldDetails['crudFields'][] = $field;  | 
            ||
| 143 | $fieldDetails['entity'] = $this->getOnlyRelationEntity($field);  | 
            ||
| 144 | |||
| 145 |             if (isset($field['fallback_id'])) { | 
            ||
| 146 | $fieldDetails['fallback_id'] = $field['fallback_id'];  | 
            ||
| 147 | }  | 
            ||
| 148 |             if (isset($field['force_delete'])) { | 
            ||
| 149 | $fieldDetails['force_delete'] = $field['force_delete'];  | 
            ||
| 150 | }  | 
            ||
| 151 | |||
| 152 | Arr::set($relationDetails, $key, $fieldDetails);  | 
            ||
| 153 | }  | 
            ||
| 154 | |||
| 155 | return $relationDetails;  | 
            ||
| 156 | }  | 
            ||
| 196 |