PhpFileNodeParser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 2
b 0
f 0
nc 1
nop 7
dl 0
loc 17
rs 10
1
<?php
2
3
/**
4
 * This file is part of PhpUnitGen.
5
 *
6
 * (c) 2017-2018 Paul Thébaud <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhpUnitGen\Parser\NodeParser;
13
14
use PhpParser\Node;
15
use PhpUnitGen\Exception\Exception;
16
use PhpUnitGen\Model\PropertyInterface\NodeInterface;
17
use PhpUnitGen\Parser\NodeParserUtil\UsePreParseTrait;
18
19
/**
20
 * Class PhpFileNodeParser.
21
 *
22
 * @author     Paul Thébaud <[email protected]>.
23
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
24
 * @license    https://opensource.org/licenses/MIT The MIT license.
25
 * @link       https://github.com/paul-thebaud/phpunit-generator
26
 * @since      Class available since Release 2.0.0.
27
 */
28
class PhpFileNodeParser extends AbstractNodeParser
29
{
30
    use UsePreParseTrait;
31
32
    /**
33
     * PhpFileNodeParser constructor.
34
     *
35
     * @param NamespaceNodeParser $namespaceNodeParser The namespace node parser to use.
36
     * @param UseNodeParser       $useNodeParser       The use node parser to use.
37
     * @param GroupUseNodeParser  $groupUseNodeParser  The group use node parser to use.
38
     * @param FunctionNodeParser  $functionNodeParser  The function node parser to use.
39
     * @param ClassNodeParser     $classNodeParser     The class node parser to use.
40
     * @param TraitNodeParser     $traitNodeParser     The trait node parser to use.
41
     * @param InterfaceNodeParser $interfaceNodeParser The interface node parser to use.
42
     */
43
    public function __construct(
44
        NamespaceNodeParser $namespaceNodeParser,
45
        UseNodeParser $useNodeParser,
46
        GroupUseNodeParser $groupUseNodeParser,
47
        FunctionNodeParser $functionNodeParser,
48
        ClassNodeParser $classNodeParser,
49
        TraitNodeParser $traitNodeParser,
50
        InterfaceNodeParser $interfaceNodeParser
51
    ) {
52
        $this->nodeParsers[Node\Stmt\Namespace_::class] = $namespaceNodeParser;
53
        $this->nodeParsers[Node\Stmt\Function_::class]  = $functionNodeParser;
54
        $this->nodeParsers[Node\Stmt\Class_::class]     = $classNodeParser;
55
        $this->nodeParsers[Node\Stmt\Trait_::class]     = $traitNodeParser;
56
        $this->nodeParsers[Node\Stmt\Interface_::class] = $interfaceNodeParser;
57
58
        $this->useNodeParser      = $useNodeParser;
59
        $this->groupUseNodeParser = $groupUseNodeParser;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function invoke($node, NodeInterface $parent): void
66
    {
67
        throw new Exception('A PhpFile is the root of parsing, so only sub-statements can be parsed.');
68
    }
69
}
70