@@ -55,13 +55,13 @@ discard block |
||
| 55 | 55 | $id = serialize($value); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - if (isset($ids[ $id ])) { |
|
| 59 | - unset($array[ $key ]); |
|
| 60 | - $ids[ $id ][] = $key; |
|
| 58 | + if (isset($ids[$id])) { |
|
| 59 | + unset($array[$key]); |
|
| 60 | + $ids[$id][] = $key; |
|
| 61 | 61 | continue; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $ids[ $id ] = [$key]; |
|
| 64 | + $ids[$id] = [$key]; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | return $array; |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | else { |
| 83 | 83 | throw new \InvalidArgumentException( |
| 84 | - "keyExists() method missing on :\n". var_export($array, true) |
|
| 84 | + "keyExists() method missing on :\n".var_export($array, true) |
|
| 85 | 85 | ); |
| 86 | 86 | } |
| 87 | 87 | |
@@ -157,16 +157,16 @@ discard block |
||
| 157 | 157 | throw new \InvalidArgumentException( |
| 158 | 158 | "Different number of " |
| 159 | 159 | ." values and weights for weight mean calculation: \n" |
| 160 | - .var_export($values, true)."\n\n" |
|
| 160 | + .var_export($values, true)."\n\n" |
|
| 161 | 161 | .var_export($weights, true) |
| 162 | 162 | ); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - if (!$values) |
|
| 165 | + if ( ! $values) |
|
| 166 | 166 | return null; |
| 167 | 167 | |
| 168 | - $weights_sum = array_sum($weights); |
|
| 169 | - if (!$weights_sum) |
|
| 168 | + $weights_sum = array_sum($weights); |
|
| 169 | + if ( ! $weights_sum) |
|
| 170 | 170 | return 0; |
| 171 | 171 | |
| 172 | 172 | $weighted_sum = 0; |
@@ -215,8 +215,8 @@ discard block |
||
| 215 | 215 | ); |
| 216 | 216 | |
| 217 | 217 | // The true location of the throw is still available through the backtrace |
| 218 | - $trace_location = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]; |
|
| 219 | - $reflectionClass = new \ReflectionClass( get_class($exception) ); |
|
| 218 | + $trace_location = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]; |
|
| 219 | + $reflectionClass = new \ReflectionClass(get_class($exception)); |
|
| 220 | 220 | |
| 221 | 221 | // file |
| 222 | 222 | if (isset($trace_location['file'])) { |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | ); |
| 254 | 254 | |
| 255 | 255 | // The true location of the throw is still available through the backtrace |
| 256 | - $trace_location = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]; |
|
| 257 | - $reflectionClass = new \ReflectionClass( get_class($exception) ); |
|
| 256 | + $trace_location = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]; |
|
| 257 | + $reflectionClass = new \ReflectionClass(get_class($exception)); |
|
| 258 | 258 | |
| 259 | 259 | // file |
| 260 | 260 | if (isset($trace_location['file'])) { |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | * |
| 295 | 295 | * @return string The unique identifier of the group |
| 296 | 296 | */ |
| 297 | - public static function generateGroupId($row, array $groups_definitions, array $options=[]) |
|
| 297 | + public static function generateGroupId($row, array $groups_definitions, array $options = []) |
|
| 298 | 298 | { |
| 299 | 299 | Arrays::mustBeCountable($row); |
| 300 | 300 | |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | : ':' |
| 304 | 304 | ; |
| 305 | 305 | |
| 306 | - $groups_separator = ! empty($options['groups_separator']) |
|
| 306 | + $groups_separator = ! empty($options['groups_separator']) |
|
| 307 | 307 | ? $options['groups_separator'] |
| 308 | 308 | : '-' |
| 309 | 309 | ; |
@@ -317,32 +317,32 @@ discard block |
||
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | if (is_string($group_definition_value)) { |
| 320 | - if ( (is_array($row) && ! array_key_exists($group_definition_value, $row)) |
|
| 320 | + if ((is_array($row) && ! array_key_exists($group_definition_value, $row)) |
|
| 321 | 321 | || ($row instanceof \ArrayAcces && ! $row->offsetExists($group_definition_value)) |
| 322 | 322 | ) { |
| 323 | 323 | throw new UsageException( |
| 324 | 324 | 'Unset column for group id generation: ' |
| 325 | 325 | .var_export($group_definition_value, true) |
| 326 | - ."\n" . var_export($row, true) |
|
| 326 | + ."\n".var_export($row, true) |
|
| 327 | 327 | ); |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | $part_name .= $group_definition_value; |
| 331 | - $group_result_value = $row[ $group_definition_value ]; |
|
| 331 | + $group_result_value = $row[$group_definition_value]; |
|
| 332 | 332 | } |
| 333 | 333 | elseif (is_int($group_definition_value)) { |
| 334 | - if ( (is_array($row) && ! array_key_exists($group_definition_value, $row)) |
|
| 334 | + if ((is_array($row) && ! array_key_exists($group_definition_value, $row)) |
|
| 335 | 335 | || ($row instanceof \ArrayAcces && ! $row->offsetExists($group_definition_value)) |
| 336 | 336 | ) { |
| 337 | 337 | throw new UsageException( |
| 338 | 338 | 'Unset column for group id generation: ' |
| 339 | 339 | .var_export($group_definition_value, true) |
| 340 | - ."\n" . var_export($row, true) |
|
| 340 | + ."\n".var_export($row, true) |
|
| 341 | 341 | ); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - $part_name .= $group_definition_value ? : '0'; |
|
| 345 | - $group_result_value = $row[ $group_definition_value ]; |
|
| 344 | + $part_name .= $group_definition_value ?: '0'; |
|
| 345 | + $group_result_value = $row[$group_definition_value]; |
|
| 346 | 346 | } |
| 347 | 347 | elseif (is_callable($group_definition_value)) { |
| 348 | 348 | |
@@ -366,12 +366,12 @@ discard block |
||
| 366 | 366 | throw new UsageException( |
| 367 | 367 | 'Bad value provided for group id generation: ' |
| 368 | 368 | .var_export($group_definition_value, true) |
| 369 | - ."\n" . var_export($row, true) |
|
| 369 | + ."\n".var_export($row, true) |
|
| 370 | 370 | ); |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - if (!is_null($part_name)) |
|
| 374 | - $group_parts[ $part_name ] = $group_result_value; |
|
| 373 | + if ( ! is_null($part_name)) |
|
| 374 | + $group_parts[$part_name] = $group_result_value; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | // sort the groups by names (without it the same group could have multiple ids) |
@@ -383,13 +383,13 @@ discard block |
||
| 383 | 383 | if (is_object($group_value)) { |
| 384 | 384 | $group_value = get_class($group_value) |
| 385 | 385 | . '_' |
| 386 | - . hash( 'crc32b', var_export($group_value, true) ); |
|
| 386 | + . hash('crc32b', var_export($group_value, true)); |
|
| 387 | 387 | } |
| 388 | 388 | elseif (is_array($group_value)) { |
| 389 | - $group_value = 'array_' . hash( 'crc32b', var_export($group_value, true) ); |
|
| 389 | + $group_value = 'array_'.hash('crc32b', var_export($group_value, true)); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - $out[] = $group_name . $key_value_separator . $group_value; |
|
| 392 | + $out[] = $group_name.$key_value_separator.$group_value; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | return implode($groups_separator, $out); |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | $location_parts = [$location_parts]; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - if (! is_array($location_parts)) { |
|
| 430 | + if ( ! is_array($location_parts)) { |
|
| 431 | 431 | throw new \InvalidArgumentException( |
| 432 | 432 | "\$location_parts must be a scalar or an array of scalars (as entries of array/ArrayAccess)" |
| 433 | 433 | ." instead of ".var_export($location_parts, true) |
@@ -50,8 +50,7 @@ discard block |
||
| 50 | 50 | foreach ($array as $key => $value) { |
| 51 | 51 | if (is_scalar($value)) { |
| 52 | 52 | $id = $value; |
| 53 | - } |
|
| 54 | - else { |
|
| 53 | + } else { |
|
| 55 | 54 | $id = serialize($value); |
| 56 | 55 | } |
| 57 | 56 | |
@@ -75,11 +74,9 @@ discard block |
||
| 75 | 74 | |
| 76 | 75 | if (is_array($array)) { |
| 77 | 76 | return array_key_exists($key, $array); |
| 78 | - } |
|
| 79 | - elseif ($array instanceof ChainableArray || method_exists($array, 'keyExists')) { |
|
| 77 | + } elseif ($array instanceof ChainableArray || method_exists($array, 'keyExists')) { |
|
| 80 | 78 | return $array->keyExists($key); |
| 81 | - } |
|
| 82 | - else { |
|
| 79 | + } else { |
|
| 83 | 80 | throw new \InvalidArgumentException( |
| 84 | 81 | "keyExists() method missing on :\n". var_export($array, true) |
| 85 | 82 | ); |
@@ -105,16 +102,13 @@ discard block |
||
| 105 | 102 | foreach ($array as $key => &$value) { // &for optimization |
| 106 | 103 | if (is_scalar($value)) { |
| 107 | 104 | $sum += $value; |
| 108 | - } |
|
| 109 | - elseif (is_null($value)) { |
|
| 105 | + } elseif (is_null($value)) { |
|
| 110 | 106 | continue; |
| 111 | - } |
|
| 112 | - elseif (is_array($value)) { |
|
| 107 | + } elseif (is_array($value)) { |
|
| 113 | 108 | throw new \InvalidArgumentException( |
| 114 | 109 | "Trying to sum an array with '$sum': ".var_export($value, true) |
| 115 | 110 | ); |
| 116 | - } |
|
| 117 | - elseif (is_object($value)) { |
|
| 111 | + } elseif (is_object($value)) { |
|
| 118 | 112 | if ( ! method_exists($value, 'toNumber')) { |
| 119 | 113 | throw new \InvalidArgumentEXception( |
| 120 | 114 | "Trying to sum a ".get_class($value)." object which cannot be casted as a number. " |
@@ -141,17 +135,21 @@ discard block |
||
| 141 | 135 | */ |
| 142 | 136 | public static function weightedMean($values, $weights) |
| 143 | 137 | { |
| 144 | - if ($values instanceof ChainableArray) |
|
| 145 | - $values = $values->toArray(); |
|
| 138 | + if ($values instanceof ChainableArray) { |
|
| 139 | + $values = $values->toArray(); |
|
| 140 | + } |
|
| 146 | 141 | |
| 147 | - if ($weights instanceof ChainableArray) |
|
| 148 | - $weights = $weights->toArray(); |
|
| 142 | + if ($weights instanceof ChainableArray) { |
|
| 143 | + $weights = $weights->toArray(); |
|
| 144 | + } |
|
| 149 | 145 | |
| 150 | - if ( ! is_array($values)) |
|
| 151 | - $values = [$values]; |
|
| 146 | + if ( ! is_array($values)) { |
|
| 147 | + $values = [$values]; |
|
| 148 | + } |
|
| 152 | 149 | |
| 153 | - if ( ! is_array($weights)) |
|
| 154 | - $weights = [$weights]; |
|
| 150 | + if ( ! is_array($weights)) { |
|
| 151 | + $weights = [$weights]; |
|
| 152 | + } |
|
| 155 | 153 | |
| 156 | 154 | if (count($values) != count($weights)) { |
| 157 | 155 | throw new \InvalidArgumentException( |
@@ -162,12 +160,14 @@ discard block |
||
| 162 | 160 | ); |
| 163 | 161 | } |
| 164 | 162 | |
| 165 | - if (!$values) |
|
| 166 | - return null; |
|
| 163 | + if (!$values) { |
|
| 164 | + return null; |
|
| 165 | + } |
|
| 167 | 166 | |
| 168 | 167 | $weights_sum = array_sum($weights); |
| 169 | - if (!$weights_sum) |
|
| 170 | - return 0; |
|
| 168 | + if (!$weights_sum) { |
|
| 169 | + return 0; |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | 172 | $weighted_sum = 0; |
| 173 | 173 | foreach ($values as $i => $value) { |
@@ -206,8 +206,9 @@ discard block |
||
| 206 | 206 | */ |
| 207 | 207 | public static function mustBeCountable($value) |
| 208 | 208 | { |
| 209 | - if (static::isCountable($value)) |
|
| 210 | - return true; |
|
| 209 | + if (static::isCountable($value)) { |
|
| 210 | + return true; |
|
| 211 | + } |
|
| 211 | 212 | |
| 212 | 213 | $exception = new \InvalidArgumentException( |
| 213 | 214 | "A value must be Countable instead of: \n" |
@@ -244,8 +245,9 @@ discard block |
||
| 244 | 245 | */ |
| 245 | 246 | public static function mustBeTraversable($value) |
| 246 | 247 | { |
| 247 | - if (static::isTraversable($value)) |
|
| 248 | - return true; |
|
| 248 | + if (static::isTraversable($value)) { |
|
| 249 | + return true; |
|
| 250 | + } |
|
| 249 | 251 | |
| 250 | 252 | $exception = new \InvalidArgumentException( |
| 251 | 253 | "A value must be Traversable instead of: \n" |
@@ -329,8 +331,7 @@ discard block |
||
| 329 | 331 | |
| 330 | 332 | $part_name .= $group_definition_value; |
| 331 | 333 | $group_result_value = $row[ $group_definition_value ]; |
| 332 | - } |
|
| 333 | - elseif (is_int($group_definition_value)) { |
|
| 334 | + } elseif (is_int($group_definition_value)) { |
|
| 334 | 335 | if ( (is_array($row) && ! array_key_exists($group_definition_value, $row)) |
| 335 | 336 | || ($row instanceof \ArrayAcces && ! $row->offsetExists($group_definition_value)) |
| 336 | 337 | ) { |
@@ -343,8 +344,7 @@ discard block |
||
| 343 | 344 | |
| 344 | 345 | $part_name .= $group_definition_value ? : '0'; |
| 345 | 346 | $group_result_value = $row[ $group_definition_value ]; |
| 346 | - } |
|
| 347 | - elseif (is_callable($group_definition_value)) { |
|
| 347 | + } elseif (is_callable($group_definition_value)) { |
|
| 348 | 348 | |
| 349 | 349 | if (is_string($group_definition_value)) { |
| 350 | 350 | $part_name .= $group_definition_value; |
@@ -353,16 +353,14 @@ discard block |
||
| 353 | 353 | elseif (is_object($group_definition_value) && ($group_definition_value instanceof \Closure)) { |
| 354 | 354 | $part_name .= 'unnamed-closure-' |
| 355 | 355 | . hash('crc32b', var_export($group_definition_value, true)); |
| 356 | - } |
|
| 357 | - elseif (is_array($group_definition_value)) { |
|
| 356 | + } elseif (is_array($group_definition_value)) { |
|
| 358 | 357 | $part_name .= implode('::', $group_definition_value); |
| 359 | 358 | } |
| 360 | 359 | |
| 361 | 360 | $group_result_value = call_user_func_array($group_definition_value, [ |
| 362 | 361 | $row, &$part_name |
| 363 | 362 | ]); |
| 364 | - } |
|
| 365 | - else { |
|
| 363 | + } else { |
|
| 366 | 364 | throw new UsageException( |
| 367 | 365 | 'Bad value provided for group id generation: ' |
| 368 | 366 | .var_export($group_definition_value, true) |
@@ -370,8 +368,9 @@ discard block |
||
| 370 | 368 | ); |
| 371 | 369 | } |
| 372 | 370 | |
| 373 | - if (!is_null($part_name)) |
|
| 374 | - $group_parts[ $part_name ] = $group_result_value; |
|
| 371 | + if (!is_null($part_name)) { |
|
| 372 | + $group_parts[ $part_name ] = $group_result_value; |
|
| 373 | + } |
|
| 375 | 374 | } |
| 376 | 375 | |
| 377 | 376 | // sort the groups by names (without it the same group could have multiple ids) |
@@ -384,8 +383,7 @@ discard block |
||
| 384 | 383 | $group_value = get_class($group_value) |
| 385 | 384 | . '_' |
| 386 | 385 | . hash( 'crc32b', var_export($group_value, true) ); |
| 387 | - } |
|
| 388 | - elseif (is_array($group_value)) { |
|
| 386 | + } elseif (is_array($group_value)) { |
|
| 389 | 387 | $group_value = 'array_' . hash( 'crc32b', var_export($group_value, true) ); |
| 390 | 388 | } |
| 391 | 389 | |
@@ -439,8 +437,7 @@ discard block |
||
| 439 | 437 | foreach ($location_parts as $location_part) { |
| 440 | 438 | if (isset($value[$location_part])) { |
| 441 | 439 | $value = $value[$location_part]; |
| 442 | - } |
|
| 443 | - else { |
|
| 440 | + } else { |
|
| 444 | 441 | return $default_value; |
| 445 | 442 | } |
| 446 | 443 | } |