| Total Complexity | 7 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 4 | abstract class BasicKey extends DatabaseItem implements Commitable, Changeable, Initializable |
||
| 5 | { |
||
| 6 | protected $columns; |
||
| 7 | protected $table; |
||
| 8 | protected $name; |
||
| 9 | |||
| 10 | public function __construct($columns, $table) |
||
| 11 | { |
||
| 12 | $this->columns = $columns; |
||
| 13 | $this->table = $table; |
||
| 14 | } |
||
| 15 | |||
| 16 | #[\Override] |
||
| 17 | public function initialize(): void |
||
| 18 | { |
||
| 19 | $keyName = $this->doesKeyExist(array( |
||
| 20 | 'table' => $this->table->getName(), |
||
| 21 | 'schema' => $this->table->getSchema()->getName(), |
||
| 22 | 'columns' => $this->columns) |
||
| 23 | ); |
||
| 24 | if($keyName === false) |
||
| 25 | { |
||
| 26 | $this->new = true; |
||
| 27 | $this->name = $this->table->getName() . '_' . implode('_', $this->columns) . '_' . $this->getNamePostfix(); |
||
| 28 | } |
||
| 29 | else |
||
| 30 | { |
||
| 31 | $this->name = $keyName; |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | abstract protected function doesKeyExist($constraint); |
||
| 36 | abstract protected function addKey($constraint); |
||
| 37 | abstract protected function dropKey($constraint); |
||
| 38 | abstract protected function getNamePostfix(); |
||
| 39 | |||
| 40 | #[\Override] |
||
| 41 | public function buildDescription() |
||
| 42 | { |
||
| 43 | return array( |
||
| 44 | 'table' => $this->table->getName(), |
||
| 45 | 'schema' => $this->table->getSchema()->getName(), |
||
| 46 | 'columns' => $this->columns, |
||
| 47 | 'name' => $this->name |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | |||
| 51 | #[\Override] |
||
| 52 | public function commitNew() |
||
| 53 | { |
||
| 54 | $this->addKey($this->buildDescription()); |
||
| 55 | } |
||
| 56 | |||
| 57 | public function drop() |
||
| 58 | { |
||
| 59 | $this->dropKey($this->getKeyDescription()); |
||
|
|
|||
| 60 | return $this; |
||
| 61 | } |
||
| 62 | |||
| 63 | public function name($name) |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 |