Passed
Push — master ( 74cbab...62dc6b )
by Stephen
02:33
created

ParamGetter::getParam()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 14
rs 10
1
<?php
2
3
4
namespace Sfneal\Queries\Traits;
5
6
7
use Illuminate\Http\Request;
8
9
trait ParamGetter
10
{
11
    /**
12
     * Retrieve a parameter that can be set by a variable or request input
13
     *
14
     * @param Request|null $request
15
     * @param array $parameters
16
     * @param null $key
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $key is correct as it would always require null to be passed?
Loading history...
17
     * @return mixed|null
18
     */
19
    private static function getParam(Request $request = null, array $parameters = [], $key = null) {
20
        // Parameter is specified
21
        if (array_key_exists($key, $parameters)) {
22
            return $parameters[$key];
23
        }
24
25
        // Param is not specified but the $request has the $key
26
        elseif ($request && $request->has($key)) {
27
            return $request->input($key);
28
        }
29
30
        // Not parameter passed
31
        else {
32
            return null;
33
        }
34
    }
35
}
36