@@ -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 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | { |
| 90 | 90 | list($inSQL, $binders) = $this->prepareInParameter($values, $name); |
| 91 | 91 | $sql = $name.' IN ('.$inSQL.')'; |
| 92 | - return [$sql,$binders]; |
|
| 92 | + return [$sql, $binders]; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | protected function prepareInParameter($values, string $name) |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | protected function prepareQueryMark(string $sql, array $parameter) |
| 136 | 136 | { |
| 137 | 137 | $binders = []; |
| 138 | - $query = preg_replace_callback('/\?/', function ($match) use (&$binders, $parameter) { |
|
| 138 | + $query = preg_replace_callback('/\?/', function($match) use (&$binders, $parameter) { |
|
| 139 | 139 | $index = count($binders); |
| 140 | 140 | if (array_key_exists($index, $parameter)) { |
| 141 | 141 | $name = Binder::index($index); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function field(string $name, string $type, $length = null) |
| 57 | 57 | { |
| 58 | - return $this->fields[$name] ?? $this->fields[$name] = ($length?new Field($this->name, $name, $type, $length):new Field($this->name, $name, $type)); |
|
| 58 | + return $this->fields[$name] ?? $this->fields[$name] = ($length ? new Field($this->name, $name, $type, $length) : new Field($this->name, $name, $type)); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function newField(string $name, string $type, $length = null) |
| 68 | 68 | { |
| 69 | - return $this->fields[$name] ?? $this->fields[$name] = ($length?new Field($this->name, $name, $type, $length):new Field($this->name, $name, $type)); |
|
| 69 | + return $this->fields[$name] ?? $this->fields[$name] = ($length ? new Field($this->name, $name, $type, $length) : new Field($this->name, $name, $type)); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | public function __construct(string $object) |
| 41 | 41 | { |
| 42 | 42 | parent::__construct($object); |
| 43 | - $this->classDoc = is_string($this->reflectObject->getDocComment())?$this->reflectObject->getDocComment():''; |
|
| 43 | + $this->classDoc = is_string($this->reflectObject->getDocComment()) ? $this->reflectObject->getDocComment() : ''; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -63,10 +63,10 @@ discard block |
||
| 63 | 63 | * @param string $classDoc |
| 64 | 64 | * @return array|null |
| 65 | 65 | */ |
| 66 | - public static function readClassDocField(string $classDoc):?array |
|
| 66 | + public static function readClassDocField(string $classDoc): ?array |
|
| 67 | 67 | { |
| 68 | 68 | if (preg_match_all('/^.+\s+\@field(?:\-(?:serialize|json))?\s+(\w+)\s+(\w+)(?:\((.+?)\))?(.*?)$/im', $classDoc, $match) > 0) { |
| 69 | - return is_array($match)?$match:null; |
|
| 69 | + return is_array($match) ? $match : null; |
|
| 70 | 70 | } |
| 71 | 71 | return null; |
| 72 | 72 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function parse(string $modifier) |
| 51 | 51 | { |
| 52 | - $this->tokens = token_get_all('<?php '. $modifier); |
|
| 52 | + $this->tokens = token_get_all('<?php '.$modifier); |
|
| 53 | 53 | $this->length = count($this->tokens); |
| 54 | 54 | $this->pos = 1; |
| 55 | 55 | $this->modifier = []; |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | protected function skipWhiteComment() |
| 111 | 111 | { |
| 112 | - for ($i = $this->pos + 1; $i < $this->length ; $i++) { |
|
| 112 | + for ($i = $this->pos + 1; $i < $this->length; $i++) { |
|
| 113 | 113 | if (is_array($this->tokens[$i])) { |
| 114 | 114 | if (in_array($this->tokens[$i][0], [T_COMMENT, T_DOC_COMMENT, T_WHITESPACE])) { |
| 115 | 115 | $this->pos++; |
@@ -132,7 +132,7 @@ |
||
| 132 | 132 | */ |
| 133 | 133 | public function charset(string $charset) |
| 134 | 134 | { |
| 135 | - $this->charset = 'CHARACTER SET ' . $charset; |
|
| 135 | + $this->charset = 'CHARACTER SET '.$charset; |
|
| 136 | 136 | return $this; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | $table = $this->connection->rawTableName($this->name); |
| 72 | 72 | $sql = "CREATE TABLE IF NOT EXISTS `{$table}` (\r\n\t"; |
| 73 | 73 | $sql .= implode(",\r\n\t", array_filter($content, 'strlen')); |
| 74 | - $auto = null === $this->auto?'':'AUTO_INCREMENT='.$this->auto; |
|
| 75 | - $collate = null === $this->collate?'':'COLLATE '.$this->collate; |
|
| 74 | + $auto = null === $this->auto ? '' : 'AUTO_INCREMENT='.$this->auto; |
|
| 75 | + $collate = null === $this->collate ? '' : 'COLLATE '.$this->collate; |
|
| 76 | 76 | $sql .= "\r\n) ENGINE={$this->engine} {$collate} {$auto} DEFAULT CHARSET={$this->charset};"; |
| 77 | 77 | return $sql; |
| 78 | 78 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | if (count($primary)) { |
| 90 | - return 'PRIMARY KEY ('. implode(',', $primary).')'; |
|
| 90 | + return 'PRIMARY KEY ('.implode(',', $primary).')'; |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
@@ -136,11 +136,11 @@ discard block |
||
| 136 | 136 | |
| 137 | 137 | protected function createField(Field $field) |
| 138 | 138 | { |
| 139 | - $type = $field->getLength()? strtoupper($field->getValueType()).'('.$field->getLength().')':strtoupper($field->getValueType()); |
|
| 140 | - $auto = $field->getAuto() ?'AUTO_INCREMENT':''; |
|
| 141 | - $null = $field->isNullable() ?'NULL':'NOT NULL'; |
|
| 142 | - $attr = $field->getAttribute() ?strtoupper($field->getAttribute()):''; |
|
| 143 | - $comment = $field->getComment() ?('COMMENT \''.addcslashes($field->getComment(), '\'').'\''):''; |
|
| 139 | + $type = $field->getLength() ? strtoupper($field->getValueType()).'('.$field->getLength().')' : strtoupper($field->getValueType()); |
|
| 140 | + $auto = $field->getAuto() ? 'AUTO_INCREMENT' : ''; |
|
| 141 | + $null = $field->isNullable() ? 'NULL' : 'NOT NULL'; |
|
| 142 | + $attr = $field->getAttribute() ?strtoupper($field->getAttribute()) : ''; |
|
| 143 | + $comment = $field->getComment() ? ('COMMENT \''.addcslashes($field->getComment(), '\'').'\'') : ''; |
|
| 144 | 144 | // default设置 |
| 145 | 145 | if ($field->hasDefault()) { |
| 146 | 146 | if (null === $field->getDefault()) { |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | $this->config = $config; |
| 58 | 58 | $this->name = $name ?? 'anonymous'; |
| 59 | 59 | $this->observer = new NullObserver; |
| 60 | - register_shutdown_function(function () { |
|
| 60 | + register_shutdown_function(function() { |
|
| 61 | 61 | $this->onBeforeSystemShutdown(); |
| 62 | 62 | }); |
| 63 | 63 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | try { |
| 79 | 79 | $this->pdo = $this->createPDO(); |
| 80 | 80 | $this->id = static::$_id; |
| 81 | - static::$_id ++; |
|
| 81 | + static::$_id++; |
|
| 82 | 82 | } catch (PDOException $e) { |
| 83 | 83 | throw new SQLException($this->getName().'connect database error:'.$e->getMessage(), $e->getCode(), E_ERROR, __FILE__, __LINE__, $e); |
| 84 | 84 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public function beginTransaction() |
| 144 | 144 | { |
| 145 | - $this->transaction ++; |
|
| 145 | + $this->transaction++; |
|
| 146 | 146 | if ($this->transaction == 1) { |
| 147 | 147 | $this->pdo->beginTransaction(); |
| 148 | 148 | } |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | protected function onBeforeSystemShutdown() |
| 195 | 195 | { |
| 196 | 196 | if ($this->pdo && ($this->transaction > 0 || $this->pdo->inTransaction())) { |
| 197 | - throw new SQLException('SQL transaction is open (' . $this->transaction.') in connection '.$this->__toString(), SQLException::ERR_TRANSACTION); |
|
| 197 | + throw new SQLException('SQL transaction is open ('.$this->transaction.') in connection '.$this->__toString(), SQLException::ERR_TRANSACTION); |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
@@ -57,10 +57,10 @@ discard block |
||
| 57 | 57 | public function input(string $name, $data) |
| 58 | 58 | { |
| 59 | 59 | if (array_key_exists($name, $this->processor)) { |
| 60 | - if ($this->processor[$name] === ObjectMiddleware::SERIALIZE){ |
|
| 61 | - return $data === null? $data : serialize($data); |
|
| 60 | + if ($this->processor[$name] === ObjectMiddleware::SERIALIZE) { |
|
| 61 | + return $data === null ? $data : serialize($data); |
|
| 62 | 62 | } |
| 63 | - if ($this->processor[$name] === ObjectMiddleware::JSON){ |
|
| 63 | + if ($this->processor[$name] === ObjectMiddleware::JSON) { |
|
| 64 | 64 | return json_encode($data); |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | public function output(string $name, $data) |
| 78 | 78 | { |
| 79 | 79 | if (array_key_exists($name, $this->processor)) { |
| 80 | - if ($this->processor[$name] === ObjectMiddleware::SERIALIZE){ |
|
| 80 | + if ($this->processor[$name] === ObjectMiddleware::SERIALIZE) { |
|
| 81 | 81 | return unserialize($data) ?: null; |
| 82 | 82 | } |
| 83 | - if ($this->processor[$name] === ObjectMiddleware::JSON){ |
|
| 83 | + if ($this->processor[$name] === ObjectMiddleware::JSON) { |
|
| 84 | 84 | return json_decode($data); |
| 85 | 85 | } |
| 86 | 86 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | if ($doc = $property->getDocComment()) { |
| 114 | 114 | if (is_string($doc) && preg_match('/@var\s+(\w+)/i', $doc, $match)) { |
| 115 | 115 | $type = strtolower($match[1]); |
| 116 | - if (in_array($type, ['boolean', 'bool', 'integer', 'int' , 'float' , 'double', 'string'])) { |
|
| 116 | + if (in_array($type, ['boolean', 'bool', 'integer', 'int', 'float', 'double', 'string'])) { |
|
| 117 | 117 | return ObjectMiddleware::RAW; |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | private function inputSerialize($data) |
| 197 | 197 | { |
| 198 | - return $data === null? $data : serialize($data); |
|
| 198 | + return $data === null ? $data : serialize($data); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | */ |
| 218 | 218 | private function inputJson($data) |
| 219 | 219 | { |
| 220 | - return $data === null? $data : json_encode($data); |
|
| 220 | + return $data === null ? $data : json_encode($data); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |