| Total Complexity | 7 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 5 | class Joins extends Clause |
||
| 6 | { |
||
| 7 | protected array $joins = []; |
||
| 8 | protected array $joined_tables = []; |
||
| 9 | |||
| 10 | public function __construct(array $joins = []) |
||
| 11 | { |
||
| 12 | foreach ($joins as $join) { |
||
| 13 | $this->add($join); |
||
| 14 | } |
||
| 15 | } |
||
| 16 | |||
| 17 | public function add(Join $join): self |
||
| 18 | { |
||
| 19 | if (isset($this->joined_tables[$join->alias()]) && $this->joined_tables[$join->alias()] !== $join->table()) { |
||
| 20 | $res = sprintf('JOIN %s WITH ALIAS %s ALREADY ALLOCATED FOR TABLE %s', $join->table(), $join->alias(), $this->joined_tables[$join->alias()]); |
||
| 21 | throw new \Exception($res); |
||
| 22 | } |
||
| 23 | |||
| 24 | $this->joined_tables[$join->alias()] = $join->table(); |
||
| 25 | $this->joins[$join->alias()] = $join; |
||
| 26 | |||
| 27 | return $this; |
||
| 28 | } |
||
| 29 | |||
| 30 | public function __toString(): string |
||
| 31 | { |
||
| 32 | return implode(PHP_EOL, $this->joins); |
||
| 33 | } |
||
| 34 | |||
| 35 | public function name(): string |
||
| 38 | } |
||
| 39 | |||
| 40 | } |