@@ -24,7 +24,7 @@ |
||
| 24 | 24 | * @return string |
| 25 | 25 | */ |
| 26 | 26 | public function get(string $alias): string { |
| 27 | - if(!array_key_exists($alias, $this->aliases)) { |
|
| 27 | + if (!array_key_exists($alias, $this->aliases)) { |
|
| 28 | 28 | throw new RuntimeException("Alias not found: {$alias}"); |
| 29 | 29 | } |
| 30 | 30 | |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | [, $alias, $part] = $values; |
| 17 | 17 | $string = $this->aliasRegistry->get($alias); |
| 18 | 18 | |
| 19 | - return $string . $part; |
|
| 19 | + return $string.$part; |
|
| 20 | 20 | }; |
| 21 | 21 | |
| 22 | 22 | return (string) preg_replace_callback('{^(\\w+)#(\\w+.*)$}', $fn, $name); |
@@ -33,10 +33,10 @@ |
||
| 33 | 33 | * @return Select|null |
| 34 | 34 | */ |
| 35 | 35 | public function get($tableName): ?Select { |
| 36 | - if($this->has($tableName)) { |
|
| 36 | + if ($this->has($tableName)) { |
|
| 37 | 37 | $table = $this->virtualTables[(string) $tableName]; |
| 38 | - if($table instanceof Closure) { |
|
| 39 | - if($tableName instanceof VirtualTable) { |
|
| 38 | + if ($table instanceof Closure) { |
|
| 39 | + if ($tableName instanceof VirtualTable) { |
|
| 40 | 40 | $params = $tableName->getParams(); |
| 41 | 41 | |
| 42 | 42 | return $table($params); |
@@ -23,12 +23,12 @@ discard block |
||
| 23 | 23 | $timer = microtime(true); |
| 24 | 24 | try { |
| 25 | 25 | return $fn(); |
| 26 | - } catch(Throwable $e) { |
|
| 26 | + } catch (Throwable $e) { |
|
| 27 | 27 | $exception = $e; |
| 28 | 28 | throw $e; |
| 29 | 29 | } finally { |
| 30 | - $finalTimer = microtime(true) - $timer; |
|
| 31 | - if($exception === null) { |
|
| 30 | + $finalTimer = microtime(true)-$timer; |
|
| 31 | + if ($exception === null) { |
|
| 32 | 32 | $this->log($query, $finalTimer); |
| 33 | 33 | } else { |
| 34 | 34 | $this->logError($query, $exception, $finalTimer); |
@@ -41,10 +41,10 @@ discard block |
||
| 41 | 41 | * @param float $duration |
| 42 | 42 | */ |
| 43 | 43 | public function log(string $query, float $duration): void { |
| 44 | - foreach($this->queryLoggers as $queryLogger) { |
|
| 44 | + foreach ($this->queryLoggers as $queryLogger) { |
|
| 45 | 45 | try { |
| 46 | 46 | $queryLogger->log($query, $duration); |
| 47 | - } catch(Throwable) { |
|
| 47 | + } catch (Throwable) { |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | * @param float $duration |
| 56 | 56 | */ |
| 57 | 57 | public function logError(string $query, Throwable $exception, float $duration): void { |
| 58 | - foreach($this->queryLoggers as $queryLogger) { |
|
| 58 | + foreach ($this->queryLoggers as $queryLogger) { |
|
| 59 | 59 | try { |
| 60 | 60 | $queryLogger->logError($query, $exception, $duration); |
| 61 | - } catch(Throwable) { |
|
| 61 | + } catch (Throwable) { |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | * @return DBExprFilter |
| 35 | 35 | */ |
| 36 | 36 | public function __invoke(string $expression, $keyPath, $validator = null) { |
| 37 | - if(!RecursiveStructureAccess::recursiveHas($this->map, $keyPath)) { |
|
| 37 | + if (!RecursiveStructureAccess::recursiveHas($this->map, $keyPath)) { |
|
| 38 | 38 | throw new RequiredValueNotFoundException(sprintf("Required value %s not found", json_encode($keyPath, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE))); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -27,18 +27,18 @@ discard block |
||
| 27 | 27 | public function __construct( |
| 28 | 28 | private string $expression, |
| 29 | 29 | array $data, |
| 30 | - string|array $keyPath, |
|
| 30 | + string | array $keyPath, |
|
| 31 | 31 | $validator = null, |
| 32 | 32 | $validationResultHandler = null, |
| 33 | 33 | ) { |
| 34 | 34 | $this->keyPath = $this->buildKey($keyPath); |
| 35 | 35 | $this->value = RecursiveStructureAccess::recursiveGet($data, $this->keyPath, null); |
| 36 | 36 | $this->hasValue = is_scalar($this->value) ? trim((string) $this->value) !== '' : !empty($this->value); |
| 37 | - if($validator === null) { |
|
| 37 | + if ($validator === null) { |
|
| 38 | 38 | $validator = static fn() => true; |
| 39 | 39 | } |
| 40 | 40 | $this->validator = $validator; |
| 41 | - if($validationResultHandler === null) { |
|
| 41 | + if ($validationResultHandler === null) { |
|
| 42 | 42 | $validationResultHandler = static function() {}; |
| 43 | 43 | } |
| 44 | 44 | $this->validationResultHandler = $validationResultHandler; |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | * @return bool |
| 56 | 56 | */ |
| 57 | 57 | public function isValid(): bool { |
| 58 | - if(!$this->hasValue) { |
|
| 58 | + if (!$this->hasValue) { |
|
| 59 | 59 | return false; |
| 60 | 60 | } |
| 61 | - if($this->validator !== null) { |
|
| 61 | + if ($this->validator !== null) { |
|
| 62 | 62 | $result = call_user_func($this->validator, $this->value); |
| 63 | 63 | call_user_func($this->validationResultHandler, $result, [ |
| 64 | 64 | 'value' => $this->value, |
@@ -83,10 +83,10 @@ discard block |
||
| 83 | 83 | * @return string[] |
| 84 | 84 | */ |
| 85 | 85 | private function buildKey($keyPath): array { |
| 86 | - if(is_string($keyPath)) { |
|
| 86 | + if (is_string($keyPath)) { |
|
| 87 | 87 | $keyPath = explode('.', $keyPath); |
| 88 | 88 | } |
| 89 | - if(!is_array($keyPath)) { |
|
| 89 | + if (!is_array($keyPath)) { |
|
| 90 | 90 | throw new RuntimeException('Invalid key'); |
| 91 | 91 | } |
| 92 | 92 | |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | * @return string[] |
| 36 | 36 | */ |
| 37 | 37 | protected function buildFieldList(array $fields, array $query = []): array { |
| 38 | - foreach($fields as $fieldName => $fieldValue) { |
|
| 39 | - if($fieldValue instanceof DefaultValue) { |
|
| 38 | + foreach ($fields as $fieldName => $fieldValue) { |
|
| 39 | + if ($fieldValue instanceof DefaultValue) { |
|
| 40 | 40 | $fieldValue = 'DEFAULT'; |
| 41 | 41 | } |
| 42 | - if(is_array($this->mask) && !in_array($fieldName, $this->mask, true)) { |
|
| 42 | + if (is_array($this->mask) && !in_array($fieldName, $this->mask, true)) { |
|
| 43 | 43 | continue; |
| 44 | 44 | } |
| 45 | - if(is_int($fieldName)) { |
|
| 46 | - if(is_array($fieldValue)) { |
|
| 45 | + if (is_int($fieldName)) { |
|
| 46 | + if (is_array($fieldValue)) { |
|
| 47 | 47 | // @phpstan-ignore-next-line |
| 48 | 48 | $fieldValue = $this->db()->quoteExpression($fieldValue[0], array_slice($fieldValue, 1)); |
| 49 | 49 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $query[] = "\t{$fieldValue}"; |
| 52 | 52 | } else { |
| 53 | 53 | $fieldName = $this->db()->quoteField($fieldName); |
| 54 | - if(is_array($fieldValue)) { |
|
| 54 | + if (is_array($fieldValue)) { |
|
| 55 | 55 | // @phpstan-ignore-next-line |
| 56 | 56 | $fieldValue = $this->db()->quoteExpression($fieldValue[0], array_slice($fieldValue, 1)); |
| 57 | 57 | } |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | * @return bool |
| 70 | 70 | */ |
| 71 | 71 | protected function isFieldAccessible(string $fieldName, array $tableFields): bool { |
| 72 | - if(!in_array($fieldName, $tableFields)) { |
|
| 72 | + if (!in_array($fieldName, $tableFields)) { |
|
| 73 | 73 | return false; |
| 74 | 74 | } |
| 75 | - if(!is_array($this->mask)) { |
|
| 75 | + if (!is_array($this->mask)) { |
|
| 76 | 76 | return true; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -54,16 +54,16 @@ |
||
| 54 | 54 | */ |
| 55 | 55 | protected function buildJoins(string $query): string { |
| 56 | 56 | $arr = []; |
| 57 | - foreach($this->joinTables as $table) { |
|
| 58 | - $join = $table['type'] . " JOIN\n"; |
|
| 59 | - $join .= "\t" . $this->buildTableName($table['alias'], $table['name']); |
|
| 60 | - if($table['expression']) { |
|
| 61 | - $join .= " ON " . $this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
| 57 | + foreach ($this->joinTables as $table) { |
|
| 58 | + $join = $table['type']." JOIN\n"; |
|
| 59 | + $join .= "\t".$this->buildTableName($table['alias'], $table['name']); |
|
| 60 | + if ($table['expression']) { |
|
| 61 | + $join .= " ON ".$this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
| 62 | 62 | } |
| 63 | 63 | $arr[] = $join; |
| 64 | 64 | } |
| 65 | - if(count($arr)) { |
|
| 66 | - $query .= implode("\n", $arr) . "\n"; |
|
| 65 | + if (count($arr)) { |
|
| 66 | + $query .= implode("\n", $arr)."\n"; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | return $query; |
@@ -6,15 +6,15 @@ discard block |
||
| 6 | 6 | use Kir\MySQL\Builder\Value\OptionalValue; |
| 7 | 7 | |
| 8 | 8 | trait LimitBuilder { |
| 9 | - private null|int|OptionalValue $limit = null; |
|
| 9 | + private null | int | OptionalValue $limit = null; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * @return null|int |
| 13 | 13 | */ |
| 14 | 14 | protected function getLimit(): ?int { |
| 15 | - if($this->limit instanceof OptionalValue) { |
|
| 15 | + if ($this->limit instanceof OptionalValue) { |
|
| 16 | 16 | $value = $this->limit->getValue(); |
| 17 | - if(is_numeric($value)) { |
|
| 17 | + if (is_numeric($value)) { |
|
| 18 | 18 | return (int) $value; |
| 19 | 19 | } |
| 20 | 20 | |
@@ -41,23 +41,23 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | protected function buildLimit(string $query, ?int $offset = null) { |
| 43 | 43 | $limit = $this->getLimit(); |
| 44 | - if($limit === null && $offset !== null) { |
|
| 44 | + if ($limit === null && $offset !== null) { |
|
| 45 | 45 | $limit = '18446744073709551615'; |
| 46 | 46 | } |
| 47 | - if($this->limit instanceof OptionalValue) { |
|
| 48 | - if($this->limit->isValid()) { |
|
| 47 | + if ($this->limit instanceof OptionalValue) { |
|
| 48 | + if ($this->limit->isValid()) { |
|
| 49 | 49 | $value = $this->limit->getValue(); |
| 50 | - if($value === null || is_scalar($value)) { |
|
| 50 | + if ($value === null || is_scalar($value)) { |
|
| 51 | 51 | $value = (string) $value; |
| 52 | 52 | } else { |
| 53 | 53 | throw new InvalidValueException('Value for OFFSET has to be a number'); |
| 54 | 54 | } |
| 55 | - if(!preg_match('{^\\d+$}', $value)) { |
|
| 55 | + if (!preg_match('{^\\d+$}', $value)) { |
|
| 56 | 56 | throw new InvalidValueException('Value for OFFSET has to be a number'); |
| 57 | 57 | } |
| 58 | 58 | $query .= "LIMIT\n\t{$value}\n"; |
| 59 | 59 | } |
| 60 | - } elseif($limit !== null) { |
|
| 60 | + } elseif ($limit !== null) { |
|
| 61 | 61 | $query .= "LIMIT\n\t{$limit}\n"; |
| 62 | 62 | } |
| 63 | 63 | |