@@ -5,8 +5,7 @@ discard block |
||
| 5 | 5 | /** |
| 6 | 6 | * Table class |
| 7 | 7 | */ |
| 8 | -trait Formatter |
|
| 9 | -{ |
|
| 8 | +trait Formatter { |
|
| 10 | 9 | |
| 11 | 10 | /** |
| 12 | 11 | * @var array column enclosing literal |
@@ -41,15 +40,13 @@ discard block |
||
| 41 | 40 | * @author Tarun Mukherjee (https://github.com/tmukherjee13) |
| 42 | 41 | */ |
| 43 | 42 | |
| 44 | - public function getTableName($table) |
|
| 45 | - { |
|
| 43 | + public function getTableName($table) { |
|
| 46 | 44 | return '{{%' . str_replace($this->db->tablePrefix, '', $table->name) . '}}'; |
| 47 | 45 | } |
| 48 | 46 | |
| 49 | 47 | |
| 50 | 48 | |
| 51 | - public function prepareInsert($rows, $columns) |
|
| 52 | - { |
|
| 49 | + public function prepareInsert($rows, $columns) { |
|
| 53 | 50 | |
| 54 | 51 | |
| 55 | 52 | return '$this->batchInsert("{{%test}}", ' . $rows . ', ' . $columns . ');'; |
@@ -60,8 +57,7 @@ discard block |
||
| 60 | 57 | * @param string $data the column string|$trim the literal to trim |
| 61 | 58 | * @return string |
| 62 | 59 | */ |
| 63 | - public function prepareColumns($data, $trim = ',') |
|
| 64 | - { |
|
| 60 | + public function prepareColumns($data, $trim = ',') { |
|
| 65 | 61 | return self::columnFormat($data, $trim); |
| 66 | 62 | } |
| 67 | 63 | |
@@ -70,8 +66,7 @@ discard block |
||
| 70 | 66 | * @param array $data the data array |
| 71 | 67 | * @return string |
| 72 | 68 | */ |
| 73 | - public function prepareData($data = []) |
|
| 74 | - { |
|
| 69 | + public function prepareData($data = []) { |
|
| 75 | 70 | self::$rows = ''; |
| 76 | 71 | foreach ($data as $row) { |
| 77 | 72 | $rows = ''; |
@@ -91,8 +86,7 @@ discard block |
||
| 91 | 86 | * @param string $data the column string|$trim the literal to trim |
| 92 | 87 | * @return string |
| 93 | 88 | */ |
| 94 | - public function dataFormat($data, $trim = ',') |
|
| 95 | - { |
|
| 89 | + public function dataFormat($data, $trim = ',') { |
|
| 96 | 90 | if (null !== $trim) { |
| 97 | 91 | $data = rtrim($data, $trim); |
| 98 | 92 | } |
@@ -104,8 +98,7 @@ discard block |
||
| 104 | 98 | * @param string $data the column string|$trim the literal to trim |
| 105 | 99 | * @return string |
| 106 | 100 | */ |
| 107 | - public function columnFormat($data, $trim = ',') |
|
| 108 | - { |
|
| 101 | + public function columnFormat($data, $trim = ',') { |
|
| 109 | 102 | if (null !== $trim) { |
| 110 | 103 | $data = rtrim($data, $trim); |
| 111 | 104 | } |
@@ -122,8 +115,7 @@ discard block |
||
| 122 | 115 | * @author Tarun Mukherjee (https://github.com/tmukherjee13) |
| 123 | 116 | */ |
| 124 | 117 | |
| 125 | - public function getColType($col) |
|
| 126 | - { |
|
| 118 | + public function getColType($col) { |
|
| 127 | 119 | |
| 128 | 120 | if ($col->isPrimaryKey && $col->autoIncrement) { |
| 129 | 121 | return 'pk'; |
@@ -135,11 +127,14 @@ discard block |
||
| 135 | 127 | } |
| 136 | 128 | if ($col->defaultValue != null && 'timestamp' != $col->dbType) { |
| 137 | 129 | $result .= " DEFAULT '{$col->defaultValue}'"; |
| 138 | - } elseif ($col->defaultValue == 'CURRENT_TIMESTAMP' && 'timestamp' == $col->dbType) { |
|
| 130 | + } |
|
| 131 | + elseif ($col->defaultValue == 'CURRENT_TIMESTAMP' && 'timestamp' == $col->dbType) { |
|
| 139 | 132 | $result .= " DEFAULT {$col->defaultValue}"; |
| 140 | - } elseif ($col->defaultValue != null && 'timestamp' == $col->dbType) { |
|
| 133 | + } |
|
| 134 | + elseif ($col->defaultValue != null && 'timestamp' == $col->dbType) { |
|
| 141 | 135 | $result .= " DEFAULT '{$col->defaultValue}'"; |
| 142 | - } elseif ($col->allowNull) { |
|
| 136 | + } |
|
| 137 | + elseif ($col->allowNull) { |
|
| 143 | 138 | $result .= ' DEFAULT NULL'; |
| 144 | 139 | } |
| 145 | 140 | return $result; |
@@ -167,19 +162,22 @@ discard block |
||
| 167 | 162 | * @author Tarun Mukherjee (https://github.com/tmukherjee13) |
| 168 | 163 | */ |
| 169 | 164 | |
| 170 | - public function formatCol($col) |
|
| 171 | - { |
|
| 165 | + public function formatCol($col) { |
|
| 172 | 166 | $decorator = []; |
| 173 | 167 | if ($col->isPrimaryKey && $col->autoIncrement) { |
| 174 | 168 | $decorator[] = 'primaryKey'; |
| 175 | - } elseif (in_array($col->type, self::$colTypes)) { |
|
| 169 | + } |
|
| 170 | + elseif (in_array($col->type, self::$colTypes)) { |
|
| 176 | 171 | $decorator[] = "{$this->modifyColType($col->dbType)}"; |
| 177 | - } elseif ($col->type == 'decimal') { |
|
| 172 | + } |
|
| 173 | + elseif ($col->type == 'decimal') { |
|
| 178 | 174 | $decorator[] = "{$col->dbType}"; |
| 179 | - } else { |
|
| 175 | + } |
|
| 176 | + else { |
|
| 180 | 177 | if (!empty($col->size) && $col->size == 1 && $col->type != 'char') { |
| 181 | 178 | $column = "boolean"; |
| 182 | - } else { |
|
| 179 | + } |
|
| 180 | + else { |
|
| 183 | 181 | $column = "{$col->type}"; |
| 184 | 182 | if (!empty($col->size)) { |
| 185 | 183 | $column .= "({$col->size})"; |