| Conditions | 10 |
| Paths | 7 |
| Total Lines | 34 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 96 | public static function setResponseDataAttributes(array &$mappings, array &$array) |
||
| 97 | { |
||
| 98 | $attributes = []; |
||
| 99 | $type = $array[Serializer::CLASS_IDENTIFIER_KEY]; |
||
| 100 | $idProperties = RecursiveFormatterHelper::getIdProperties($mappings, $type); |
||
| 101 | |||
| 102 | foreach ($array as $propertyName => $value) { |
||
| 103 | if (\in_array($propertyName, $idProperties, true)) { |
||
| 104 | continue; |
||
| 105 | } |
||
| 106 | |||
| 107 | $keyName = self::transformToValidMemberName(RecursiveFormatterHelper::camelCaseToUnderscore($propertyName)); |
||
| 108 | |||
| 109 | if (!empty($value[Serializer::CLASS_IDENTIFIER_KEY]) && empty($mappings[$value[Serializer::CLASS_IDENTIFIER_KEY]])) { |
||
| 110 | $copy = $value; |
||
| 111 | self::recursiveSetKeysToUnderScore($copy); |
||
| 112 | $attributes[$keyName] = $copy; |
||
| 113 | continue; |
||
| 114 | } |
||
| 115 | |||
| 116 | if (self::isScalarValue($value) && empty($mappings[$value[Serializer::SCALAR_TYPE]])) { |
||
| 117 | $attributes[$keyName] = $value; |
||
| 118 | continue; |
||
| 119 | } |
||
| 120 | |||
| 121 | if (\is_array($value) && !array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $value)) { |
||
| 122 | if (self::containsClassIdentifierKey($value)) { |
||
| 123 | $attributes[$keyName] = $value; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | return [JsonApiTransformer::ATTRIBUTES_KEY => $attributes]; |
||
| 129 | } |
||
| 130 | |||
| 190 |