| Total Complexity | 7 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class PairSet |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var array |
||
| 13 | */ |
||
| 14 | protected $data = []; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param string $a |
||
| 18 | * @param string $b |
||
| 19 | * @param bool $areMutuallyExclusive |
||
| 20 | * @return bool |
||
| 21 | */ |
||
| 22 | public function has(string $a, string $b, bool $areMutuallyExclusive): bool |
||
| 23 | { |
||
| 24 | $first = $this->data[$a] ?? null; |
||
| 25 | $result = null !== $first && ($first[$b] ?? null); |
||
| 26 | |||
| 27 | if (null === $result) { |
||
|
|
|||
| 28 | return false; |
||
| 29 | } |
||
| 30 | |||
| 31 | // areMutuallyExclusive being false is a superset of being true, |
||
| 32 | // hence if we want to know if this PairSet "has" these two with no |
||
| 33 | // exclusivity, we have to ensure it was added as such. |
||
| 34 | if ($areMutuallyExclusive === false) { |
||
| 35 | return $result === false; |
||
| 36 | } |
||
| 37 | |||
| 38 | return true; |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param string $a |
||
| 43 | * @param string $b |
||
| 44 | * @param bool $areMutuallyExclusive |
||
| 45 | */ |
||
| 46 | public function add(string $a, string $b, bool $areMutuallyExclusive): void |
||
| 47 | { |
||
| 48 | $this->addToData($a, $b, $areMutuallyExclusive); |
||
| 49 | $this->addToData($b, $a, $areMutuallyExclusive); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param string $a |
||
| 54 | * @param string $b |
||
| 55 | * @param bool $areMutuallyExclusive |
||
| 56 | */ |
||
| 57 | protected function addToData(string $a, string $b, bool $areMutuallyExclusive): void |
||
| 67 | } |
||
| 68 | } |
||
| 69 |