| Total Complexity | 7 |
| Total Lines | 35 |
| 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 = []) |
||
| 14 | } |
||
| 15 | } |
||
| 16 | |||
| 17 | // add a Join object to the list of joins |
||
| 18 | public function add(...$join): self |
||
| 19 | { |
||
| 20 | $join = array_pop($join); |
||
| 21 | if (isset($this->joined_tables[$join->alias()]) && $this->joined_tables[$join->alias()] !== $join->table()) { |
||
| 22 | $res = sprintf('JOIN %s WITH ALIAS %s ALREADY ALLOCATED FOR TABLE %s', $join->table(), $join->alias(), $this->joined_tables[$join->alias()]); |
||
| 23 | throw new \Exception($res); |
||
| 24 | } |
||
| 25 | |||
| 26 | $this->joined_tables[$join->alias()] = $join->table(); |
||
| 27 | $this->joins[$join->alias()] = $join; |
||
| 28 | |||
| 29 | return $this; |
||
| 30 | } |
||
| 31 | |||
| 32 | public function __toString(): string |
||
| 33 | { |
||
| 34 | return implode(' ', $this->joins); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function name(): string |
||
| 40 | } |
||
| 41 | |||
| 42 | } |