These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace SRF\Formats\Tree; |
||
4 | |||
5 | use Cdb\Exception; |
||
6 | use Tree\Node\Node; |
||
7 | use Tree\Node\NodeInterface; |
||
8 | use Tree\Node\NodeTrait; |
||
9 | |||
10 | class TreeNode extends Node { |
||
11 | |||
12 | /** |
||
13 | * SRFTreeElement constructor. |
||
14 | * @param \SMWResultArray[] | null $row |
||
15 | */ |
||
16 | 5 | public function __construct( $row = null ) { |
|
17 | 5 | parent::__construct( $row ); |
|
18 | 5 | } |
|
19 | |||
20 | /** |
||
21 | * @return string |
||
22 | */ |
||
23 | 5 | public function getHash() { |
|
24 | |||
25 | 5 | $resultSubject = $this->getResultSubject(); |
|
26 | |||
27 | 5 | if ( $resultSubject !== null ) { |
|
28 | 5 | return $resultSubject->getSerialization(); |
|
29 | } |
||
30 | |||
31 | 5 | return ''; |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * @return null|\SMWDIWikiPage |
||
36 | */ |
||
37 | 5 | public function getResultSubject() { |
|
38 | /** @var \SMWResultArray[] | null $row */ |
||
39 | 5 | $row = $this->getValue(); |
|
40 | |||
41 | 5 | if ( $row !== null ) { |
|
42 | 5 | return $row[ 0 ]->getResultSubject(); |
|
43 | } |
||
44 | |||
45 | 5 | return null; |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param NodeInterface $child |
||
50 | * @return NodeTrait |
||
0 ignored issues
–
show
|
|||
51 | * @throws Exception |
||
52 | */ |
||
53 | 5 | public function addChild( NodeInterface $child ) { |
|
54 | |||
55 | 5 | foreach ( $this->getAncestorsAndSelf() as $ancestor ) { |
|
56 | 5 | if ( $ancestor->getHash() === $child->getHash() ) { |
|
57 | 5 | throw new Exception( 'srf-tree-circledetected' ); |
|
58 | } |
||
59 | } |
||
60 | |||
61 | 5 | return parent::addChild( $child ); |
|
62 | } |
||
63 | |||
64 | |||
65 | } |
||
66 | |||
67 |
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.