Test Setup Failed
Push — v2 ( 74186a...c94b75 )
by Alexander
06:56
created

ConvertToSnakeCase   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A cleanArray() 0 8 2
1
<?php
2
3
namespace App\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
        return collect($data)->mapWithKeys(function ($value, $key) {
36
            $key = in_array($key, $this->except) ? $key : snake_case($key);
37
38
            return [$key => $value];
39
        })->all();
40
    }
41
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
42