Skip to content

Commit 4ac6ca5

Browse files
committed
refactor: rename variable names
Variables with the same meaning have the same variable name. Variables with different meanings are given different names.
1 parent add3e07 commit 4ac6ca5

File tree

6 files changed

+82
-81
lines changed

6 files changed

+82
-81
lines changed

system/Database/Forge.php

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -572,30 +572,30 @@ public function createTable(string $table, bool $ifNotExists = false, array $att
572572
*/
573573
protected function _createTable(string $table, bool $ifNotExists, array $attributes)
574574
{
575-
$columns = $this->_processFields(true);
575+
$processedFields = $this->_processFields(true);
576576

577-
for ($i = 0, $c = count($columns); $i < $c; $i++) {
578-
$columns[$i] = ($columns[$i]['_literal'] !== false) ? "\n\t" . $columns[$i]['_literal']
579-
: "\n\t" . $this->_processColumn($columns[$i]);
577+
for ($i = 0, $c = count($processedFields); $i < $c; $i++) {
578+
$processedFields[$i] = ($processedFields[$i]['_literal'] !== false) ? "\n\t" . $processedFields[$i]['_literal']
579+
: "\n\t" . $this->_processColumn($processedFields[$i]);
580580
}
581581

582-
$columns = implode(',', $columns);
582+
$processedFields = implode(',', $processedFields);
583583

584-
$columns .= $this->_processPrimaryKeys($table);
585-
$columns .= current($this->_processForeignKeys($table));
584+
$processedFields .= $this->_processPrimaryKeys($table);
585+
$processedFields .= current($this->_processForeignKeys($table));
586586

587587
if ($this->createTableKeys === true) {
588588
$indexes = current($this->_processIndexes($table));
589589
if (is_string($indexes)) {
590-
$columns .= $indexes;
590+
$processedFields .= $indexes;
591591
}
592592
}
593593

594594
return sprintf(
595595
$this->createTableStr . '%s',
596596
'CREATE TABLE',
597597
$this->db->escapeIdentifiers($table),
598-
$columns,
598+
$processedFields,
599599
$this->_createTableAttributes($attributes)
600600
);
601601
}
@@ -817,30 +817,31 @@ public function modifyColumn(string $table, $field): bool
817817
}
818818

819819
/**
820-
* @param array|string $fields
820+
* @param 'ADD'|'CHANGE'|'DROP' $alterType
821+
* @param array|string $processedFields Processed column definitions
821822
*
822823
* @return false|string|string[]
823824
*/
824-
protected function _alterTable(string $alterType, string $table, $fields)
825+
protected function _alterTable(string $alterType, string $table, $processedFields)
825826
{
826827
$sql = 'ALTER TABLE ' . $this->db->escapeIdentifiers($table) . ' ';
827828

828829
// DROP has everything it needs now.
829830
if ($alterType === 'DROP') {
830-
if (is_string($fields)) {
831-
$fields = explode(',', $fields);
831+
if (is_string($processedFields)) {
832+
$processedFields = explode(',', $processedFields);
832833
}
833834

834-
$fields = array_map(fn ($field) => 'DROP COLUMN ' . $this->db->escapeIdentifiers(trim($field)), $fields);
835+
$processedFields = array_map(fn ($field) => 'DROP COLUMN ' . $this->db->escapeIdentifiers(trim($field)), $processedFields);
835836

836-
return $sql . implode(', ', $fields);
837+
return $sql . implode(', ', $processedFields);
837838
}
838839

839840
$sql .= ($alterType === 'ADD') ? 'ADD ' : $alterType . ' COLUMN ';
840841

841842
$sqls = [];
842843

843-
foreach ($fields as $data) {
844+
foreach ($processedFields as $data) {
844845
$sqls[] = $sql . ($data['_literal'] !== false
845846
? $data['_literal']
846847
: $this->_processColumn($data));
@@ -850,15 +851,15 @@ protected function _alterTable(string $alterType, string $table, $fields)
850851
}
851852

852853
/**
853-
* Process fields
854+
* Returns $processedFields array from $this->fields data.
854855
*/
855856
protected function _processFields(bool $createTable = false): array
856857
{
857-
$fields = [];
858+
$processedFields = [];
858859

859860
foreach ($this->fields as $name => $attributes) {
860861
if (! is_array($attributes)) {
861-
$fields[] = ['_literal' => $attributes];
862+
$processedFields[] = ['_literal' => $attributes];
862863

863864
continue;
864865
}
@@ -932,24 +933,24 @@ protected function _processFields(bool $createTable = false): array
932933
$field['length'] = '(' . $attributes['CONSTRAINT'] . ')';
933934
}
934935

935-
$fields[] = $field;
936+
$processedFields[] = $field;
936937
}
937938

938-
return $fields;
939+
return $processedFields;
939940
}
940941

941942
/**
942-
* Process column
943+
* Converts $processedField array to field definition string.
943944
*/
944-
protected function _processColumn(array $field): string
945+
protected function _processColumn(array $processedField): string
945946
{
946-
return $this->db->escapeIdentifiers($field['name'])
947-
. ' ' . $field['type'] . $field['length']
948-
. $field['unsigned']
949-
. $field['default']
950-
. $field['null']
951-
. $field['auto_increment']
952-
. $field['unique'];
947+
return $this->db->escapeIdentifiers($processedField['name'])
948+
. ' ' . $processedField['type'] . $processedField['length']
949+
. $processedField['unsigned']
950+
. $processedField['default']
951+
. $processedField['null']
952+
. $processedField['auto_increment']
953+
. $processedField['unique'];
953954
}
954955

955956
/**

system/Database/MySQLi/Forge.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,23 @@ protected function _alterTable(string $alterType, string $table, $field)
162162
/**
163163
* Process column
164164
*/
165-
protected function _processColumn(array $field): string
165+
protected function _processColumn(array $processedField): string
166166
{
167-
$extraClause = isset($field['after']) ? ' AFTER ' . $this->db->escapeIdentifiers($field['after']) : '';
167+
$extraClause = isset($processedField['after']) ? ' AFTER ' . $this->db->escapeIdentifiers($processedField['after']) : '';
168168

169-
if (empty($extraClause) && isset($field['first']) && $field['first'] === true) {
169+
if (empty($extraClause) && isset($processedField['first']) && $processedField['first'] === true) {
170170
$extraClause = ' FIRST';
171171
}
172172

173-
return $this->db->escapeIdentifiers($field['name'])
174-
. (empty($field['new_name']) ? '' : ' ' . $this->db->escapeIdentifiers($field['new_name']))
175-
. ' ' . $field['type'] . $field['length']
176-
. $field['unsigned']
177-
. $field['null']
178-
. $field['default']
179-
. $field['auto_increment']
180-
. $field['unique']
181-
. (empty($field['comment']) ? '' : ' COMMENT ' . $field['comment'])
173+
return $this->db->escapeIdentifiers($processedField['name'])
174+
. (empty($processedField['new_name']) ? '' : ' ' . $this->db->escapeIdentifiers($processedField['new_name']))
175+
. ' ' . $processedField['type'] . $processedField['length']
176+
. $processedField['unsigned']
177+
. $processedField['null']
178+
. $processedField['default']
179+
. $processedField['auto_increment']
180+
. $processedField['unique']
181+
. (empty($processedField['comment']) ? '' : ' COMMENT ' . $processedField['comment'])
182182
. $extraClause;
183183
}
184184

system/Database/OCI8/Forge.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,26 +184,26 @@ protected function _attributeAutoIncrement(array &$attributes, array &$field)
184184
/**
185185
* Process column
186186
*/
187-
protected function _processColumn(array $field): string
187+
protected function _processColumn(array $processedField): string
188188
{
189189
$constraint = '';
190190
// @todo: can't cover multi pattern when set type.
191-
if ($field['type'] === 'VARCHAR2' && strpos($field['length'], "('") === 0) {
192-
$constraint = ' CHECK(' . $this->db->escapeIdentifiers($field['name'])
193-
. ' IN ' . $field['length'] . ')';
191+
if ($processedField['type'] === 'VARCHAR2' && strpos($processedField['length'], "('") === 0) {
192+
$constraint = ' CHECK(' . $this->db->escapeIdentifiers($processedField['name'])
193+
. ' IN ' . $processedField['length'] . ')';
194194

195-
$field['length'] = '(' . max(array_map('mb_strlen', explode("','", mb_substr($field['length'], 2, -2)))) . ')' . $constraint;
196-
} elseif (isset($this->primaryKeys['fields']) && count($this->primaryKeys['fields']) === 1 && $field['name'] === $this->primaryKeys['fields'][0]) {
197-
$field['unique'] = '';
195+
$processedField['length'] = '(' . max(array_map('mb_strlen', explode("','", mb_substr($processedField['length'], 2, -2)))) . ')' . $constraint;
196+
} elseif (isset($this->primaryKeys['fields']) && count($this->primaryKeys['fields']) === 1 && $processedField['name'] === $this->primaryKeys['fields'][0]) {
197+
$processedField['unique'] = '';
198198
}
199199

200-
return $this->db->escapeIdentifiers($field['name'])
201-
. ' ' . $field['type'] . $field['length']
202-
. $field['unsigned']
203-
. $field['default']
204-
. $field['auto_increment']
205-
. $field['null']
206-
. $field['unique'];
200+
return $this->db->escapeIdentifiers($processedField['name'])
201+
. ' ' . $processedField['type'] . $processedField['length']
202+
. $processedField['unsigned']
203+
. $processedField['default']
204+
. $processedField['auto_increment']
205+
. $processedField['null']
206+
. $processedField['unique'];
207207
}
208208

209209
/**

system/Database/Postgre/Forge.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ protected function _alterTable(string $alterType, string $table, $field)
134134
/**
135135
* Process column
136136
*/
137-
protected function _processColumn(array $field): string
137+
protected function _processColumn(array $processedField): string
138138
{
139-
return $this->db->escapeIdentifiers($field['name'])
140-
. ' ' . $field['type'] . ($field['type'] === 'text' ? '' : $field['length'])
141-
. $field['default']
142-
. $field['null']
143-
. $field['auto_increment']
144-
. $field['unique'];
139+
return $this->db->escapeIdentifiers($processedField['name'])
140+
. ' ' . $processedField['type'] . ($processedField['type'] === 'text' ? '' : $processedField['length'])
141+
. $processedField['default']
142+
. $processedField['null']
143+
. $processedField['auto_increment']
144+
. $processedField['unique'];
145145
}
146146

147147
/**

system/Database/SQLSRV/Forge.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,16 @@ protected function _processIndexes(string $table, bool $asQuery = false): array
287287
/**
288288
* Process column
289289
*/
290-
protected function _processColumn(array $field): string
290+
protected function _processColumn(array $processedField): string
291291
{
292-
return $this->db->escapeIdentifiers($field['name'])
293-
. (empty($field['new_name']) ? '' : ' ' . $this->db->escapeIdentifiers($field['new_name']))
294-
. ' ' . $field['type'] . ($field['type'] === 'text' ? '' : $field['length'])
295-
. $field['default']
296-
. $field['null']
297-
. $field['auto_increment']
292+
return $this->db->escapeIdentifiers($processedField['name'])
293+
. (empty($processedField['new_name']) ? '' : ' ' . $this->db->escapeIdentifiers($processedField['new_name']))
294+
. ' ' . $processedField['type'] . ($processedField['type'] === 'text' ? '' : $processedField['length'])
295+
. $processedField['default']
296+
. $processedField['null']
297+
. $processedField['auto_increment']
298298
. ''
299-
. $field['unique'];
299+
. $processedField['unique'];
300300
}
301301

302302
/**

system/Database/SQLite3/Forge.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,19 @@ protected function _alterTable(string $alterType, string $table, $field)
141141
/**
142142
* Process column
143143
*/
144-
protected function _processColumn(array $field): string
144+
protected function _processColumn(array $processedField): string
145145
{
146-
if ($field['type'] === 'TEXT' && strpos($field['length'], "('") === 0) {
147-
$field['type'] .= ' CHECK(' . $this->db->escapeIdentifiers($field['name'])
148-
. ' IN ' . $field['length'] . ')';
146+
if ($processedField['type'] === 'TEXT' && strpos($processedField['length'], "('") === 0) {
147+
$processedField['type'] .= ' CHECK(' . $this->db->escapeIdentifiers($processedField['name'])
148+
. ' IN ' . $processedField['length'] . ')';
149149
}
150150

151-
return $this->db->escapeIdentifiers($field['name'])
152-
. ' ' . $field['type']
153-
. $field['auto_increment']
154-
. $field['null']
155-
. $field['unique']
156-
. $field['default'];
151+
return $this->db->escapeIdentifiers($processedField['name'])
152+
. ' ' . $processedField['type']
153+
. $processedField['auto_increment']
154+
. $processedField['null']
155+
. $processedField['unique']
156+
. $processedField['default'];
157157
}
158158

159159
/**

0 commit comments

Comments
 (0)