Test Failed
Push — master ( 89c2b4...542ea2 )
by noitran
03:15
created

InteractsWithRequest::getQueryParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Noitran\Repositories\Requests;
4
5
use Illuminate\Support\Arr;
6
7
/**
8
 * Trait InteractsWithRequest
9
 */
10
trait InteractsWithRequest
11
{
12
    /**
13
     * Get a subset containing the provided keys with values from the input data.
14
     *
15
     * @param $keys
16
     * @param array $input
17
     *
18
     * @return array
19
     */
20
    public function only($keys, array $input = []): array
21
    {
22
        $keys = \is_array($keys) ? $keys : \func_get_args();
23
24
        $output = [];
25
26
        foreach ($keys as $key) {
27
            Arr::set($output, $key, data_get($input, $key));
28
        }
29
30
        return $output;
31
    }
32
33
    /**
34
     * Get all of the input except for a specified array of items.
35
     *
36
     * @param $keys
37
     * @param array $input
38
     *
39
     * @return array
40
     */
41
    public function except($keys, array $input = []): array
42
    {
43
        $keys = \is_array($keys) ? $keys : \func_get_args();
44
45
        Arr::forget($input, $keys);
46
47
        return $input;
48
    }
49
50
    /**
51
     * Determine if the input array contains a given input item key.
52
     *
53
     * @param $key
54
     * @param array $input
55
     *
56
     * @return bool
57
     */
58
    public function exists($key, array $input = []): bool
59
    {
60
        $keys = \is_array($key) ? $key : \func_get_args();
61
62
        foreach ($keys as $value) {
63
            if (! Arr::has($input, $value)) {
64
                return false;
65
            }
66
        }
67
68
        return true;
69
    }
70
71
    /**
72
     * Returns array of query param keys.
73
     *
74
     * @param array $queryFilters
75
     *
76
     * @return array
77
     */
78
    public function getQueryParams(array $queryFilters): array
79
    {
80
        return array_map(function ($param) {
81
            return $param['queryParameter'];
82
        }, $queryFilters);
83
    }
84
}
85