Completed
Pull Request — master (#139)
by Kévin
03:44
created

ArrayShortDefinition   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 49
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRegister() 0 6 1
A getMetadata() 0 7 1
A pass() 0 14 2
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Analyzer\Pass\Expression;
7
8
use PhpParser\Node\Expr;
9
use PHPSA\Analyzer\Helper\DefaultMetadataPassTrait;
10
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
11
use PHPSA\Context;
12
13
class ArrayShortDefinition implements AnalyzerPassInterface
14
{
15
    use DefaultMetadataPassTrait {
16
        DefaultMetadataPassTrait::getMetadata as defaultMetadata;
17
    }
18
19
    const DESCRIPTION = 'Short syntax can be used in array literals.';
20
21
    /**
22
     * @param Expr\Array_ $expr
23
     * @param Context $context
24
     * @return bool
25
     */
26 28
    public function pass(Expr\Array_ $expr, Context $context)
27
    {
28 28
        if ($expr->getAttribute('kind') == Expr\Array_::KIND_LONG) {
29 2
            $context->notice(
30 2
                'array.short-syntax',
31 2
                'Please use [] (short syntax) for array definition.',
32
                $expr
33 2
            );
34
35 2
            return true;
36
        }
37
38 27
        return false;
39
    }
40
41
    /**
42
     * @return array
43
     */
44 1
    public function getRegister()
45
    {
46
        return [
47
            Expr\Array_::class
48 1
        ];
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public static function getMetadata()
55
    {
56 1
        $metadata = self::defaultMetadata();
57 1
        $metadata->setRequiredPhpVersion('5.4');
58
59 1
        return $metadata;
60
    }
61
}
62