| Total Complexity | 5 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class TypeBuilder |
||
| 11 | { |
||
| 12 | public const ENUM = 'ENUM'; |
||
| 13 | public const RANGE = 'RANGE'; |
||
| 14 | |||
| 15 | private DatabaseInterface $db; |
||
| 16 | private string $name; |
||
| 17 | private array $values; |
||
| 18 | private string $type; |
||
| 19 | |||
| 20 | public function __construct( |
||
| 28 | } |
||
| 29 | |||
| 30 | public function create(): void |
||
| 31 | { |
||
| 32 | if (empty($this->values)) { |
||
| 33 | throw new OperationException('Values can\'t be empty'); |
||
| 34 | } |
||
| 35 | |||
| 36 | $values = implode(',', array_map(static fn($v) => "'{$v}'", $this->values)); |
||
| 37 | |||
| 38 | $query = sprintf( |
||
| 39 | 'CREATE TYPE %s AS %s (%s);', |
||
| 40 | $this->name, |
||
| 41 | $this->type, |
||
| 42 | $values |
||
| 43 | ); |
||
| 44 | |||
| 45 | $this->db->execute($query); |
||
| 46 | $this->db->commit(); |
||
| 47 | } |
||
| 48 | |||
| 49 | public function drop(): void |
||
| 50 | { |
||
| 51 | $query = sprintf('DROP TYPE %s;', $this->name); |
||
| 52 | $this->db->execute($query); |
||
| 53 | $this->db->commit(); |
||
| 54 | |||
| 55 | } |
||
| 56 | |||
| 57 | public function addValues(array $values): self |
||
| 62 | } |
||
| 63 | } |
||
| 64 |