|
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\NodeParserUtil; |
|
13
|
|
|
|
|
14
|
|
|
use PhpParser\Node\Stmt\GroupUse; |
|
15
|
|
|
use PhpParser\Node\Stmt\Use_; |
|
16
|
|
|
use PhpUnitGen\Model\ModelInterface\PhpFileModelInterface; |
|
17
|
|
|
use PhpUnitGen\Parser\NodeParser\GroupUseNodeParser; |
|
18
|
|
|
use PhpUnitGen\Parser\NodeParser\UseNodeParser; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Trait UsePreParseTrait. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Paul Thébaud <[email protected]>. |
|
24
|
|
|
* @copyright 2017-2018 Paul Thébaud <[email protected]>. |
|
25
|
|
|
* @license https://opensource.org/licenses/MIT The MIT license. |
|
26
|
|
|
* @link https://github.com/paul-thebaud/phpunit-generator |
|
27
|
|
|
* @since Class available since Release 2.0.0. |
|
28
|
|
|
*/ |
|
29
|
|
|
trait UsePreParseTrait |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @var UseNodeParser $useNodeParser The use node parser. |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $useNodeParser; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var GroupUseNodeParser $groupUseNodeParser The group use node parser. |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $groupUseNodeParser; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Pre parse uses in nodes. |
|
43
|
|
|
* |
|
44
|
|
|
* @param array $nodes The nodes to parse to find uses. |
|
45
|
|
|
* @param PhpFileModelInterface $parent The parent to update. |
|
46
|
|
|
*/ |
|
47
|
|
|
public function preParseUses(array $nodes, PhpFileModelInterface $parent): void |
|
48
|
|
|
{ |
|
49
|
|
|
foreach ($nodes as $node) { |
|
50
|
|
|
if ($node instanceof Use_) { |
|
51
|
|
|
$this->useNodeParser->invoke($node, $parent); |
|
52
|
|
|
} else { |
|
53
|
|
|
if ($node instanceof GroupUse) { |
|
54
|
|
|
$this->groupUseNodeParser->invoke($node, $parent); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|