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

ArgumentUnpacking   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 37
ccs 18
cts 18
cp 1
rs 10
wmc 6
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
B pass() 0 21 5
A getMetadata() 0 7 1
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