Completed
Pull Request — master (#240)
by Дмитрий
04:23
created

ArgumentUnpacking::pass()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 4
nop 2
dl 0
loc 21
ccs 14
cts 14
cp 1
crap 5
rs 8.7624
c 0
b 0
f 0
1
<?php
2
3
namespace PHPSA\Analyzer\Pass\Expression\FunctionCall;
4
5
use PhpParser\Node\Expr\FuncCall;
6
use PHPSA\Context;
7
use PHPSA\Definition\ClassMethod;
8
use PHPSA\Definition\FunctionDefinition;
9
10
class ArgumentUnpacking extends AbstractFunctionCallAnalyzer
11
{
12
    const DESCRIPTION = 'Checks for use of `func_get_args()` and suggests the use of argument unpacking. (... operator)';
13
14 10
    public function pass(FuncCall $funcCall, Context $context)
15
    {
16 10
        $functionName = $this->resolveFunctionName($funcCall, $context);
17
18 10
        if ($functionName !== 'func_get_args') {
19 9
            return;
20
        }
21
22 1
        $scopePointer = $context->scopePointer->getObject();
23
24 1
        if ($scopePointer instanceof ClassMethod || $scopePointer instanceof FunctionDefinition) {
25 1
            if (count($scopePointer->getParams()) === 0) {
26 1
                $context->notice(
27 1
                    'fcall.argumentunpacking',
28 1
                    sprintf('Please use argument unpacking (...) instead of func_get_args().'),
29
                    $funcCall
30 1
                );
31 1
                return;
32
            }
33 1
        }
34 1
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 1
    public static function getMetadata()
40
    {
41 1
        $metaData = parent::getMetadata();
42 1
        $metaData->setRequiredPhpVersion('5.6');
43
44 1
        return $metaData;
45
    }
46
}
47