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

ArrayExtension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A extend() 0 6 2
A ignoreArray() 0 8 4
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