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

ParamGetter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A getParam() 0 14 4
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