Completed
Push — master ( 8f1dcc...21dbd4 )
by Daniel
03:46
created

InformatorDynamicFunctions   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A callDynamicFunctionToGetResults() 0 15 4
A evaluateParameterAgainstKnownFunctions() 0 14 2
1
<?php
2
3
/*
4
 * The MIT License
5
 *
6
 * Copyright 2016 Transformer-.
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
namespace danielgp\informator;
28
29
trait InformatorDynamicFunctions
30
{
31
32
    protected function callDynamicFunctionToGetResults(array $inLabelsArray)
33
    {
34
        switch (count($inLabelsArray)) {
35
            case 1:
36
                return call_user_func([$this, $inLabelsArray[0]]);
37
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
38
            case 2:
39
                if (is_array($inLabelsArray[1])) {
40
                    return call_user_func_array([$this, $inLabelsArray[0]], [$inLabelsArray[1]]);
41
                }
42
                $dynFnPrmtr = $this->evaluateParameterAgainstKnownFunctions($inLabelsArray[1]);
43
                return call_user_func([$this, $inLabelsArray[0]], $dynFnPrmtr);
44
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
45
        }
46
    }
47
48
    private function evaluateParameterAgainstKnownFunctions($inParameter)
49
    {
50
        $outParameter         = $inParameter;
51
        $standardPhpFunctions = [
52
            'get_loaded_extensions',
53
            'stream_get_filters',
54
            'stream_get_transports',
55
            'stream_get_wrappers',
56
        ];
57
        if (in_array($inParameter, $standardPhpFunctions)) {
58
            $outParameter = call_user_func($inParameter);
59
        }
60
        return $outParameter;
61
    }
62
}
63