Completed
Pull Request — master (#240)
by Дмитрий
11:13 queued 07:10
created

ArgumentUnpacking::getMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
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