Passed
Push — master ( 62af2e...d65fca )
by Théo
07:27 queued 04:04
created

TraverserFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 11

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 23 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the humbug/php-scoper package.
7
 *
8
 * Copyright (c) 2017 Théo FIDRY <[email protected]>,
9
 *                    Pádraic Brady <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Humbug\PhpScoper\PhpParser;
16
17
use Humbug\PhpScoper\PhpParser\NodeVisitor\Collection\NamespaceStmtCollection;
18
use Humbug\PhpScoper\PhpParser\NodeVisitor\Collection\UseStmtCollection;
19
use Humbug\PhpScoper\PhpParser\NodeVisitor\Resolver\FullyQualifiedNameResolver;
20
use Humbug\PhpScoper\Reflector;
21
use PhpParser\NodeTraverserInterface;
22
23
/**
24
 * @private
25
 */
26
class TraverserFactory
27
{
28
    private $reflector;
29
30 377
    public function __construct(Reflector $reflector)
31
    {
32 377
        $this->reflector = $reflector;
33
    }
34
35 372
    public function create(string $prefix, array $whitelist): NodeTraverserInterface
36
    {
37 372
        $traverser = new NodeTraverser($prefix);
38
39 372
        $namespaceStatements = new NamespaceStmtCollection();
40 372
        $useStatements = new UseStmtCollection();
41
42 372
        $nameResolver = new FullyQualifiedNameResolver($namespaceStatements, $useStatements);
43
44 372
        $traverser->addVisitor(new NodeVisitor\AppendParentNode());
45
46 372
        $traverser->addVisitor(new NodeVisitor\NamespaceStmtPrefixer($prefix, $namespaceStatements));
47
48 372
        $traverser->addVisitor(new NodeVisitor\UseStmt\UseStmtCollector($namespaceStatements, $useStatements));
49 372
        $traverser->addVisitor(new NodeVisitor\UseStmt\UseStmtPrefixer($prefix, $this->reflector));
50
51 372
        $traverser->addVisitor(new NodeVisitor\NameStmtPrefixer($prefix, $nameResolver, $this->reflector));
52 372
        $traverser->addVisitor(new NodeVisitor\StringScalarPrefixer($prefix, $this->reflector));
53
54 372
        $traverser->addVisitor(new NodeVisitor\WhitelistedClassAppender($whitelist));
55
56 372
        return $traverser;
57
    }
58
}
59