| Conditions | 4 |
| Paths | 5 |
| Total Lines | 18 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 31 | public function getRandomNode() { |
||
| 32 | if (empty($this->nodes)) throw new ClusterException('Node list is empty.'); |
||
| 33 | $nodeKey = array_rand($this->nodes); |
||
| 34 | $node = $this->nodes[$nodeKey]; |
||
| 35 | try { |
||
| 36 | if ((array)$node === $node) { |
||
| 37 | $node = new Node($nodeKey, $node); |
||
| 38 | unset($this->nodes[$nodeKey]); |
||
| 39 | } else { |
||
| 40 | $node = new Node($node); |
||
| 41 | unset($this->nodes[$nodeKey]); |
||
| 42 | } |
||
| 43 | } catch (\InvalidArgumentException $e) { |
||
| 44 | trigger_error($e->getMessage()); |
||
| 45 | } |
||
| 46 | |||
| 47 | return $node; |
||
| 48 | } |
||
| 49 | } |