Passed
Push — v2 ( 206d9a...8ecd15 )
by Alexander
02:16
created

ConvertToSnakeCase   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A cleanArray() 0 10 3
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 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
 * @see \Flugg\Responder\Responder
15
 */
16
class ConvertToSnakeCase extends TransformsRequest
17
{
18
    /**
19
     * A list of attributes that shouldn't be converted.
20
     *
21
     * @var array
22
     */
23
    protected $except = [
24
        //
25
    ];
26
27
    /**
28
     * Clean the data in the given array.
29
     *
30
     * @param  array $data
31
     * @return array
32
     */
33
    protected function cleanArray(array $data)
34
    {
35
        $parameters = [];
36
37
        foreach ($data as $key => $value) {
38
            $parameters[in_array($key, $this->except) ? $key : snake_case($key)] = $value;
39
        }
40
41
        return $parameters;
42
    }
43
}
44