Passed
Push — 4.x ( 651f39...1d49e7 )
by Doug
02:50
created

AddNewDataVisitor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 20
rs 10
1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord\EPSG\Import;
10
11
use PhpParser\BuilderFactory;
12
use PhpParser\Node;
13
use PhpParser\Node\Stmt\ClassLike;
14
use PhpParser\NodeTraverser;
15
use PhpParser\NodeVisitorAbstract;
16
17
class AddNewDataVisitor extends NodeVisitorAbstract
18
{
19
    private array $data;
20
21
    public function __construct(array $data)
22
    {
23
        $this->data = $data;
24
    }
25
26
    public function enterNode(Node $node)
27
    {
28
        $factory = new BuilderFactory();
29
        if ($node instanceof ClassLike) {
30
            $property = $factory->property('sridData')->makeProtected()->makeStatic()->setType('array')->setDefault($this->data)->setDocComment('');
31
            array_unshift($node->stmts, $property->getNode());
32
33
            return NodeTraverser::STOP_TRAVERSAL;
34
        }
35
36
        return null;
37
    }
38
}
39