Conditions | 3 |
Paths | 3 |
Total Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 5 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
55 | 5 | public function addChild( NodeInterface $child ) { |
|
56 | |||
57 | 5 | foreach ( $this->getAncestorsAndSelf() as $ancestor ) { |
|
58 | 5 | if ( $ancestor->getHash() === $child->getHash() ) { |
|
59 | 5 | throw new Exception( 'srf-tree-circledetected' ); |
|
60 | } |
||
61 | } |
||
62 | |||
63 | 5 | return parent::addChild( $child ); |
|
64 | } |
||
65 | |||
68 |
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.