RootRetrieverHelper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 18
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRoot() 0 9 3
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 PhpUnitGen\Model\ModelInterface\PhpFileModelInterface;
15
use PhpUnitGen\Model\PropertyInterface\NodeInterface;
16
17
/**
18
 * Class RootRetrieverHelper.
19
 *
20
 * @author     Paul Thébaud <[email protected]>.
21
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
22
 * @license    https://opensource.org/licenses/MIT The MIT license.
23
 * @link       https://github.com/paul-thebaud/phpunit-generator
24
 * @since      Class available since Release 2.0.0.
25
 */
26
class RootRetrieverHelper
27
{
28
    /**
29
     * Get the root of the node.
30
     *
31
     * @param NodeInterface $parent The node to search in.
32
     *
33
     * @return PhpFileModelInterface|null The root if it is found, else null.
34
     */
35
    public static function getRoot(NodeInterface $parent): ?PhpFileModelInterface
36
    {
37
        while ($parent !== null) {
38
            if ($parent instanceof PhpFileModelInterface) {
39
                return $parent;
40
            }
41
            $parent = $parent->getParentNode();
42
        }
43
        return null;
44
    }
45
}
46