Passed
Push — develop ( f3d119...d95d5b )
by Paul
02:17
created

RootRetrieverHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

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

1 Method

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