@@ -19,22 +19,22 @@ discard block |
||
| 19 | 19 | * @return string |
| 20 | 20 | */ |
| 21 | 21 | protected function buildTableName(?string $alias, $name): string { |
| 22 | - if($name instanceof SpecialTable) { |
|
| 22 | + if ($name instanceof SpecialTable) { |
|
| 23 | 23 | $name = $name->asString($this->db()); |
| 24 | - } elseif(is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
| 24 | + } elseif (is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
| 25 | 25 | $name = (string) $name; |
| 26 | 26 | $lines = explode("\n", $name); |
| 27 | 27 | $lines = array_map(static fn(string $line) => "\t{$line}", $lines); |
| 28 | 28 | $name = implode("\n", $lines); |
| 29 | - $name = '(' . trim(rtrim(trim($name), ';')) . ')'; |
|
| 30 | - } elseif(is_array($name)) { |
|
| 29 | + $name = '('.trim(rtrim(trim($name), ';')).')'; |
|
| 30 | + } elseif (is_array($name)) { |
|
| 31 | 31 | $parts = []; |
| 32 | - foreach($name as /*$index => */$bucket) { |
|
| 33 | - if(is_scalar($bucket)/* && ctype_digit((string) $index)*/) { |
|
| 32 | + foreach ($name as /*$index => */$bucket) { |
|
| 33 | + if (is_scalar($bucket)/* && ctype_digit((string) $index)*/) { |
|
| 34 | 34 | $parts[] = "SELECT {$this->db()->quote($bucket)} AS {$this->db()->quoteField('value')}"; |
| 35 | - } elseif(is_iterable($bucket)) { |
|
| 35 | + } elseif (is_iterable($bucket)) { |
|
| 36 | 36 | $values = []; |
| 37 | - foreach($bucket as $field => $value) { |
|
| 37 | + foreach ($bucket as $field => $value) { |
|
| 38 | 38 | $values[] = sprintf('%s AS %s', $this->db()->quote($value), $this->db()->quoteField($field)); |
| 39 | 39 | } |
| 40 | 40 | $parts[] = sprintf("SELECT %s", implode(', ', $values)); |
@@ -42,14 +42,14 @@ discard block |
||
| 42 | 42 | throw new InvalidArgumentException('Only scalar values and iterables are supported as table data'); |
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | - $name = '(' . implode("\n\tUNION ALL\n\t", $parts) . ')'; |
|
| 45 | + $name = '('.implode("\n\tUNION ALL\n\t", $parts).')'; |
|
| 46 | 46 | } |
| 47 | - if((is_string($name) || $name instanceof VirtualTable) && $this->db()->getVirtualTables()->has($name)) { |
|
| 47 | + if ((is_string($name) || $name instanceof VirtualTable) && $this->db()->getVirtualTables()->has($name)) { |
|
| 48 | 48 | $select = (string) $this->db()->getVirtualTables()->get($name); |
| 49 | 49 | $name = sprintf('(%s)', implode("\n\t", explode("\n", trim($select)))); |
| 50 | 50 | } |
| 51 | 51 | $name = $this->aliasReplacer()->replace((string) $name); |
| 52 | - if($alias !== null) { |
|
| 52 | + if ($alias !== null) { |
|
| 53 | 53 | return sprintf("%s %s", $name, $alias); |
| 54 | 54 | } |
| 55 | 55 | return $name; |
@@ -5,15 +5,15 @@ discard block |
||
| 5 | 5 | use Kir\MySQL\Builder\Value\OptionalValue; |
| 6 | 6 | |
| 7 | 7 | trait LimitBuilder { |
| 8 | - private null|int|OptionalValue $limit = null; |
|
| 8 | + private null | int | OptionalValue $limit = null; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * @return null|int |
| 12 | 12 | */ |
| 13 | 13 | protected function getLimit(): ?int { |
| 14 | - if($this->limit instanceof OptionalValue) { |
|
| 14 | + if ($this->limit instanceof OptionalValue) { |
|
| 15 | 15 | $value = $this->limit->getValue(); |
| 16 | - if(is_numeric($value)) { |
|
| 16 | + if (is_numeric($value)) { |
|
| 17 | 17 | return (int) $value; |
| 18 | 18 | } |
| 19 | 19 | return null; |
@@ -37,23 +37,23 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | protected function buildLimit(string $query, ?int $offset = null) { |
| 39 | 39 | $limit = $this->getLimit(); |
| 40 | - if($limit === null && $offset !== null) { |
|
| 40 | + if ($limit === null && $offset !== null) { |
|
| 41 | 41 | $limit = '18446744073709551615'; |
| 42 | 42 | } |
| 43 | - if($this->limit instanceof OptionalValue) { |
|
| 44 | - if($this->limit->isValid()) { |
|
| 43 | + if ($this->limit instanceof OptionalValue) { |
|
| 44 | + if ($this->limit->isValid()) { |
|
| 45 | 45 | $value = $this->limit->getValue(); |
| 46 | - if($value === null || is_scalar($value)) { |
|
| 46 | + if ($value === null || is_scalar($value)) { |
|
| 47 | 47 | $value = (string) $value; |
| 48 | 48 | } else { |
| 49 | 49 | throw new InvalidValueException('Value for OFFSET has to be a number'); |
| 50 | 50 | } |
| 51 | - if(!preg_match('{^\\d+$}', $value)) { |
|
| 51 | + if (!preg_match('{^\\d+$}', $value)) { |
|
| 52 | 52 | throw new InvalidValueException('Value for OFFSET has to be a number'); |
| 53 | 53 | } |
| 54 | 54 | $query .= "LIMIT\n\t{$value}\n"; |
| 55 | 55 | } |
| 56 | - } elseif($limit !== null) { |
|
| 56 | + } elseif ($limit !== null) { |
|
| 57 | 57 | $query .= "LIMIT\n\t{$limit}\n"; |
| 58 | 58 | } |
| 59 | 59 | return $query; |
@@ -5,15 +5,15 @@ discard block |
||
| 5 | 5 | use Kir\MySQL\Builder\Value\OptionalValue; |
| 6 | 6 | |
| 7 | 7 | trait OffsetBuilder { |
| 8 | - private null|int|OptionalValue $offset = null; |
|
| 8 | + private null | int | OptionalValue $offset = null; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * @return null|int |
| 12 | 12 | */ |
| 13 | 13 | protected function getOffset(): ?int { |
| 14 | - if($this->offset instanceof OptionalValue) { |
|
| 14 | + if ($this->offset instanceof OptionalValue) { |
|
| 15 | 15 | $value = $this->offset->getValue(); |
| 16 | - if(is_numeric($value)) { |
|
| 16 | + if (is_numeric($value)) { |
|
| 17 | 17 | return (int) $value; |
| 18 | 18 | } |
| 19 | 19 | return null; |
@@ -36,20 +36,20 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | protected function buildOffset(string $query): string { |
| 38 | 38 | $offset = $this->getOffset(); |
| 39 | - if($this->offset instanceof OptionalValue) { |
|
| 40 | - if($this->offset->isValid()) { |
|
| 39 | + if ($this->offset instanceof OptionalValue) { |
|
| 40 | + if ($this->offset->isValid()) { |
|
| 41 | 41 | $value = $this->offset->getValue(); |
| 42 | - if($value === null || is_scalar($value)) { |
|
| 42 | + if ($value === null || is_scalar($value)) { |
|
| 43 | 43 | $value = (string) $value; |
| 44 | 44 | } else { |
| 45 | 45 | throw new InvalidValueException('Value for OFFSET has to be a number'); |
| 46 | 46 | } |
| 47 | - if(!preg_match('{^\\d+$}', $value)) { |
|
| 47 | + if (!preg_match('{^\\d+$}', $value)) { |
|
| 48 | 48 | throw new InvalidValueException('Value for OFFSET has to be a number'); |
| 49 | 49 | } |
| 50 | 50 | $query .= "OFFSET\n\t{$value}\n"; |
| 51 | 51 | } |
| 52 | - } elseif($offset !== null) { |
|
| 52 | + } elseif ($offset !== null) { |
|
| 53 | 53 | $query .= "OFFSET\n\t{$this->offset}\n"; |
| 54 | 54 | } |
| 55 | 55 | return $query; |