| Total Complexity | 10 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Coverage | 68.18% |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | trait Linkable |
||
| 17 | { |
||
| 18 | private $_link = []; |
||
| 19 | |||
| 20 | public function __clone () |
||
| 23 | } |
||
| 24 | |||
| 25 | 73 | public function haveLink (Election $election) : bool |
|
| 26 | { |
||
| 27 | 73 | return in_array($election, $this->_link, true); |
|
| 28 | } |
||
| 29 | |||
| 30 | 79 | public function countLinks () : int |
|
| 31 | { |
||
| 32 | 79 | return count($this->_link); |
|
| 33 | } |
||
| 34 | |||
| 35 | 80 | public function getLinks () : ?array |
|
| 36 | { |
||
| 37 | 80 | return (!empty($this->_link)) ? $this->_link : null; |
|
| 38 | } |
||
| 39 | |||
| 40 | // Internal |
||
| 41 | # Dot not Overloading ! Do not Use ! |
||
| 42 | |||
| 43 | 84 | public function registerLink (Election $election) : void |
|
| 44 | { |
||
| 45 | 84 | if (array_search($election, $this->_link, true) === false) |
|
| 46 | 84 | { $this->_link[] = $election; } |
|
| 47 | else |
||
| 48 | { throw new CondorcetException; } |
||
| 49 | 84 | } |
|
| 50 | |||
| 51 | 9 | public function destroyLink (Election $election) : bool |
|
| 52 | { |
||
| 53 | 9 | $destroyKey = array_search($election, $this->_link, true); |
|
| 54 | |||
| 55 | 9 | if ($destroyKey !== false) : |
|
| 56 | 9 | unset($this->_link[$destroyKey]); |
|
| 57 | 9 | return true; |
|
| 58 | else : |
||
| 59 | throw new CondorcetException; |
||
| 60 | endif; |
||
| 61 | } |
||
| 62 | |||
| 63 | protected function destroyAllLink () : void |
||
| 66 | } |
||
| 67 | } |
||
| 68 |