Passed
Push — master ( 12b03a...508f3d )
by Seth
08:34
created

ParameterManager::getParameterValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 4
dl 0
loc 6
ccs 0
cts 6
cp 0
crap 6
rs 9.4285
c 1
b 1
f 0
1
<?php
2
3
namespace Battis\SharedLogs\Database;
4
5
class ParameterManager
6
{
7
    /** Canonical name for field in additional request parameters containing the list of additional sub-objects */
8
    const SCOPE_INCLUDE = 'include';
9
10
    protected static function parameterExists($params, $scope, $key)
11
    {
12
        return !empty($params[$scope][$key]);
13
    }
14
15
    protected static function parameterValueExists($params, $scope, $value)
16
    {
17
        return !empty($params[$scope]) && is_array($params[$scope]) && in_array($value, $params[$scope]);
18
    }
19
20
    protected static function getParameterValue($params, $scope, $key, $defaultValue = null) {
21
        if (self::parameterExists($params, $scope, $key)) {
22
            return $params[$scope][$key];
23
        }
24
        return $defaultValue;
25
    }
26
27
    protected static function consumeParameterValue($params, $scope, $value)
28
    {
29
        if (self::parameterValueExists($params, $scope, $value)) {
30
            unset($params[$scope][array_search($value, $params[$scope])]);
31
        }
32
        return $params; // for chaining
33
    }
34
35
    protected static function scopeExists($params, $scope)
36
    {
37
        return !empty($params[$scope]);
38
    }
39
40
    protected static function getScope($params, $scope, $defaultValue = null)
41
    {
42
        if (self::scopeExists($params, $scope)) {
43
            return $params[$scope];
44
        }
45
        return $defaultValue;
46
    }
47
}