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