Passed
Push — develop ( fb709e...b69568 )
by Paul
03:14
created

UsePreParseTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A preParseUses() 0 8 3
1
<?php
2
3
namespace PhpUnitGen\Parser\NodeParserUtil;
4
5
use PhpParser\Node\Stmt\Use_;
6
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface;
7
use PhpUnitGen\Parser\NodeParser\NodeParserInterface\UseNodeParserInterface;
8
use Respect\Validation\Validator;
9
10
/**
11
 * Trait UsePreParseTrait.
12
 *
13
 * @author     Paul Thébaud <[email protected]>.
14
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
15
 * @license    https://opensource.org/licenses/MIT The MIT license.
16
 * @link       https://github.com/paul-thebaud/phpunit-generator
17
 * @since      Class available since Release 2.0.0.
18
 */
19
trait UsePreParseTrait
20
{
21
    /**
22
     * @var UseNodeParserInterface $useNodeParser The use node parser.
23
     */
24
    protected $useNodeParser;
25
26
    /**
27
     * Pre parse uses in nodes.
28
     *
29
     * @param array                 $nodes  The nodes to parse to find uses.
30
     * @param PhpFileModelInterface $parent The parent to update.
31
     *
32
     * @return PhpFileModelInterface The updated parent.
33
     */
34
    public function preParseUses(array $nodes, PhpFileModelInterface $parent): PhpFileModelInterface
35
    {
36
        foreach ($nodes as $node) {
37
            if (Validator::instance(Use_::class)->validate($node)) {
38
                $parent = $this->useNodeParser->invoke($node, $parent);
39
            }
40
        }
41
        return $parent;
42
    }
43
}
44