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