@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $this->config = $config; |
| 80 | 80 | $this->name = $name ?? 'anonymous'; |
| 81 | 81 | $this->observer = new NullObserver; |
| 82 | - register_shutdown_function(function () { |
|
| 82 | + register_shutdown_function(function() { |
|
| 83 | 83 | $this->onBeforeSystemShutdown(); |
| 84 | 84 | }); |
| 85 | 85 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | try { |
| 108 | 108 | $this->pdo = $this->createPDO(); |
| 109 | 109 | $this->id = static::$connectionCount; |
| 110 | - static::$connectionCount ++; |
|
| 110 | + static::$connectionCount++; |
|
| 111 | 111 | } catch (PDOException $e) { |
| 112 | 112 | throw new SQLException(sprintf( |
| 113 | 113 | "%s connect database error:%s", |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | public function beginTransaction() |
| 182 | 182 | { |
| 183 | - $this->transaction ++; |
|
| 183 | + $this->transaction++; |
|
| 184 | 184 | if ($this->transaction == 1) { |
| 185 | 185 | $this->pdo->beginTransaction(); |
| 186 | 186 | } |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | * @param string $query |
| 371 | 371 | * @return string |
| 372 | 372 | */ |
| 373 | - public function prefix( string $query):string |
|
| 373 | + public function prefix(string $query):string |
|
| 374 | 374 | { |
| 375 | 375 | // _:table 前缀控制 |
| 376 | 376 | $prefix = $this->getConfig('prefix', ''); |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | $password = $this->config['password'] ?? ''; |
| 46 | 46 | $pdo = new PDO($this->getDsn(), $user, $password); |
| 47 | 47 | $this->id = static::$connectionCount; |
| 48 | - static::$connectionCount ++; |
|
| 48 | + static::$connectionCount++; |
|
| 49 | 49 | return $pdo; |
| 50 | 50 | } catch (PDOException $e) { |
| 51 | 51 | throw new SQLException(sprintf( |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function switchDatabase(string $database) |
| 66 | 66 | { |
| 67 | - return $this->query(new QueryStatement('USE `' . $database.'`')); |
|
| 67 | + return $this->query(new QueryStatement('USE `'.$database.'`')); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | public function rawTableName(string $name) |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | try { |
| 41 | 41 | $pdo = new PDO($this->getDsn()); |
| 42 | 42 | $this->id = static::$connectionCount; |
| 43 | - static::$connectionCount ++; |
|
| 43 | + static::$connectionCount++; |
|
| 44 | 44 | return $pdo; |
| 45 | 45 | } catch (PDOException $e) { |
| 46 | 46 | throw new SQLException( |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function switchDatabase(string $database) |
| 64 | 64 | { |
| 65 | - return $this->query(new QueryStatement('USE `' . $database.'`')); |
|
| 65 | + return $this->query(new QueryStatement('USE `'.$database.'`')); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | $fields = $reads; |
| 26 | 26 | } else { |
| 27 | 27 | $field = []; |
| 28 | - $prefix = strlen($table) ?"`{$table}`." :''; |
|
| 28 | + $prefix = strlen($table) ? "`{$table}`." : ''; |
|
| 29 | 29 | foreach ($reads as $want) { |
| 30 | 30 | $field[] = $prefix."`$want`"; |
| 31 | 31 | } |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | $newWhereBinder = array_merge($newWhereBinder, $binders); |
| 82 | 82 | $name = ltrim($name, ':'); |
| 83 | 83 | $where = str_replace(':'.$name, $inSQL, $where); |
| 84 | - } elseif($value instanceof Binder) { |
|
| 84 | + } elseif ($value instanceof Binder) { |
|
| 85 | 85 | $newWhereBinder[] = $value; |
| 86 | - }else{ |
|
| 86 | + } else { |
|
| 87 | 87 | $newWhereBinder[] = new Binder($name, $value); |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | { |
| 104 | 104 | list($inSQL, $binders) = $this->prepareInParameter($values, $name); |
| 105 | 105 | $sql = $name.' IN ('.$inSQL.')'; |
| 106 | - return [$sql,$binders]; |
|
| 106 | + return [$sql, $binders]; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | protected function prepareQueryMark(string $sql, array $parameter) |
| 156 | 156 | { |
| 157 | 157 | $binders = []; |
| 158 | - $query = preg_replace_callback('/\?/', function ($match) use (&$binders, $parameter) { |
|
| 158 | + $query = preg_replace_callback('/\?/', function($match) use (&$binders, $parameter) { |
|
| 159 | 159 | $index = count($binders); |
| 160 | 160 | if (array_key_exists($index, $parameter)) { |
| 161 | 161 | $name = Binder::index($index); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | protected function whereStringArray(string $where, array $whereBinder) |
| 145 | 145 | { |
| 146 | 146 | list($where, $whereBinder) = $this->prepareWhereString($where, $whereBinder); |
| 147 | - $this->where = 'WHERE '. $where; |
|
| 147 | + $this->where = 'WHERE '.$where; |
|
| 148 | 148 | $this->binder = $this->mergeBinder($this->binder, $whereBinder); |
| 149 | 149 | } |
| 150 | 150 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | public function groupBy(string $what) |
| 158 | 158 | { |
| 159 | - $this->groupBy = 'GROUP BY '. $what; |
|
| 159 | + $this->groupBy = 'GROUP BY '.$what; |
|
| 160 | 160 | return $this; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | { |
| 201 | 201 | |
| 202 | 202 | list($having, $havingBinder) = $this->prepareWhereString($having, $havingBinder); |
| 203 | - $this->having = 'HAVING '. $having; |
|
| 203 | + $this->having = 'HAVING '.$having; |
|
| 204 | 204 | $this->binder = $this->mergeBinder($this->binder, $havingBinder); |
| 205 | 205 | } |
| 206 | 206 | |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | public function orderBy(string $what, string $order = 'ASC') |
| 215 | 215 | { |
| 216 | - $this->orderBy = 'ORDER BY '. $what.' '. $order; |
|
| 216 | + $this->orderBy = 'ORDER BY '.$what.' '.$order; |
|
| 217 | 217 | return $this; |
| 218 | 218 | } |
| 219 | 219 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | public function limit(int $start, int $length = null) |
| 228 | 228 | { |
| 229 | - $this->limit = 'LIMIT '. $start . ($length !== null ? ',' .$length :''); |
|
| 229 | + $this->limit = 'LIMIT '.$start.($length !== null ? ','.$length : ''); |
|
| 230 | 230 | return $this; |
| 231 | 231 | } |
| 232 | 232 | |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | */ |
| 254 | 254 | protected function prepareQuery():Query |
| 255 | 255 | { |
| 256 | - $where = [$this->where,$this->groupBy,$this->having,$this->orderBy,$this->limit]; |
|
| 256 | + $where = [$this->where, $this->groupBy, $this->having, $this->orderBy, $this->limit]; |
|
| 257 | 257 | $condition = implode(' ', array_filter(array_map('trim', $where), 'strlen')); |
| 258 | - $select = [$this->distinct,$this->select]; |
|
| 258 | + $select = [$this->distinct, $this->select]; |
|
| 259 | 259 | $selection = implode(' ', array_filter(array_map('trim', $select), 'strlen')); |
| 260 | 260 | $string = sprintf("SELECT %s FROM %s %s", $selection, $this->table, $condition); |
| 261 | 261 | return new Query($string, $this->binder); |
@@ -290,7 +290,7 @@ |
||
| 290 | 290 | protected static function createDefaultMiddleware(string $object, TableStruct $struct) |
| 291 | 291 | { |
| 292 | 292 | $reflectObject = new ReflectionClass($object); |
| 293 | - $classDoc = is_string($reflectObject->getDocComment())?$reflectObject->getDocComment():''; |
|
| 293 | + $classDoc = is_string($reflectObject->getDocComment()) ? $reflectObject->getDocComment() : ''; |
|
| 294 | 294 | if (preg_match('/@field-(serialize|json)\s+(\w+)/i', $classDoc, $matchs)) { |
| 295 | 295 | return new TableStructMiddleware($object, $struct); |
| 296 | 296 | } |
@@ -115,7 +115,7 @@ |
||
| 115 | 115 | * @return Connection |
| 116 | 116 | * @throws SQLException |
| 117 | 117 | */ |
| 118 | - public static function new(string $type, array $config, ?string $name = null): Connection |
|
| 118 | + public static function new(string $type, array $config, ?string $name = null) : Connection |
|
| 119 | 119 | { |
| 120 | 120 | if (array_key_exists($type, static::$type)) { |
| 121 | 121 | return new static::$type[$type]($config, $name); |
@@ -68,7 +68,7 @@ |
||
| 68 | 68 | */ |
| 69 | 69 | public static function getDataSourceFrom(ApplicationResource $resource, string $groupName) |
| 70 | 70 | { |
| 71 | - $group = $groupName === 'default' ? '': '-'. $groupName; |
|
| 71 | + $group = $groupName === 'default' ? '' : '-'.$groupName; |
|
| 72 | 72 | $dataSourceConfigPath = $resource->getConfigResourcePath('config/data-source'.$group); |
| 73 | 73 | $dataSource = new DataSource; |
| 74 | 74 | $observer = new DebugObserver(static::$application->debug()); |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | protected function prepare(Request $request, Response $response) |
| 66 | 66 | { |
| 67 | - $response->setHeader('x-powered-by', 'suda/' . SUDA_VERSION, true); |
|
| 67 | + $response->setHeader('x-powered-by', 'suda/'.SUDA_VERSION, true); |
|
| 68 | 68 | $response->getWrapper()->register(ExceptionContentWrapper::class, [Throwable::class]); |
| 69 | 69 | $response->getWrapper()->register(TemplateWrapper::class, [RawTemplate::class]); |
| 70 | 70 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | if (!$response->isSend()) { |
| 107 | 107 | $response->end(); |
| 108 | 108 | } |
| 109 | - $this->debug->info('responded with code ' . $response->getStatus()); |
|
| 109 | + $this->debug->info('responded with code '.$response->getStatus()); |
|
| 110 | 110 | $this->debug->timeEnd('sending response'); |
| 111 | 111 | } catch (Throwable $e) { |
| 112 | 112 | $this->debug->uncaughtException($e); |
@@ -131,13 +131,13 @@ discard block |
||
| 131 | 131 | $route = $attributes['config'] ?? []; |
| 132 | 132 | $runnable = null; |
| 133 | 133 | if (array_key_exists('class', $route)) { |
| 134 | - $runnable = $this->className($route['class']) . '->onRequest'; |
|
| 134 | + $runnable = $this->className($route['class']).'->onRequest'; |
|
| 135 | 135 | } elseif (array_key_exists('source', $route)) { |
| 136 | 136 | $attributes['source'] = $route['source']; |
| 137 | - $runnable = FileRequestProcessor::class . '->onRequest'; |
|
| 137 | + $runnable = FileRequestProcessor::class.'->onRequest'; |
|
| 138 | 138 | } elseif (array_key_exists('template', $route)) { |
| 139 | 139 | $attributes['template'] = $route['template']; |
| 140 | - $runnable = TemplateRequestProcessor::class . '->onRequest'; |
|
| 140 | + $runnable = TemplateRequestProcessor::class.'->onRequest'; |
|
| 141 | 141 | } elseif (array_key_exists('runnable', $route)) { |
| 142 | 142 | $runnable = $route['runnable']; |
| 143 | 143 | } else { |