InteractsWithRequest::exists()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

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