Completed
Push — master ( 1cf077...8206b4 )
by Povilas
01:34
created

ArrayExtension::ignoreArray()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.2
cc 4
eloc 5
nc 5
nop 1
1
<?php
2
3
namespace Povils\PHPMND\Extension;
4
5
use PhpParser\Node;
6
use PhpParser\Node\Expr\ArrayItem;
7
use PhpParser\Node\Scalar\String_;
8
9
class ArrayExtension extends Extension
10
{
11
    /**
12
     * @inheritdoc
13
     */
14
    public function getName()
15
    {
16
        return 'array';
17
    }
18
19
    /**
20
     * @inheritdoc
21
     */
22
    public function extend(Node $node)
23
    {
24
        $parent = $node->getAttribute('parent');
25
26
        return $parent instanceof ArrayItem && false === $this->ignoreArray($parent);
27
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32
    private function ignoreArray(ArrayItem $node)
33
    {
34
        $arrayKey = $node->key;
35
        
36
        return $this->option->allowArrayMapping() &&
37
        $arrayKey instanceof String_ &&
38
        false === ($this->option->includeNumericStrings() && is_numeric($arrayKey->value));
39
    }
40
}
41