ConvertToSnakeCase::cleanArray()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 10
ccs 0
cts 5
cp 0
crap 12
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Flugg\Responder\Http\Middleware;
4
5
use Illuminate\Foundation\Http\Middleware\TransformsRequest;
6
7
/**
8
 * A middleware class responsible for converting incoming parameter keys to snake case.
9
 *
10
 * @package flugger/laravel-responder
11
 * @author  Alexander Tømmerås <[email protected]>
12
 * @license The MIT License
13
 */
14
class ConvertToSnakeCase extends TransformsRequest
15
{
16
    /**
17
     * A list of attributes that shouldn't be converted.
18
     *
19
     * @var array
20
     */
21
    protected $except = [
22
        //
23
    ];
24
25
    /**
26
     * Clean the data in the given array.
27
     *
28
     * @param  array $data
29
     * @param  string $keyPrefix
30
     * @return array
31
     */
32
    protected function cleanArray(array $data, $keyPrefix = '')
33
    {
34
        $parameters = [];
35
36
        foreach ($data as $key => $value) {
37
            $parameters[in_array($keyPrefix.$key, $this->except) ? $keyPrefix.$key : snake_case($keyPrefix.$key)] = $value;
38
        }
39
40
        return $parameters;
41
    }
42
}
43