Skip to content

Commit a410c77

Browse files
committed
refactor: vendor/bin/rector
1 parent d48912a commit a410c77

File tree

6 files changed

+109
-106
lines changed

6 files changed

+109
-106
lines changed

system/Database/OCI8/Builder.php

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\Database\OCI8;
1313

14+
use CodeIgniter\Database\Exceptions\DatabaseException;
1415
use CodeIgniter\Database\BaseBuilder;
1516

1617
/**
@@ -73,24 +74,24 @@ class Builder extends BaseBuilder
7374
protected function _insertBatch(string $table, array $keys, array $values): string
7475
{
7576
$keys = implode(', ', $keys);
76-
$has_primary_key = in_array('PRIMARY', array_column($this->db->getIndexData($table), 'type'), true);
77+
$hasPrimaryKey = in_array('PRIMARY', array_column($this->db->getIndexData($table), 'type'), true);
7778

7879
// ORA-00001 measures
79-
if ($has_primary_key) {
80+
if ($hasPrimaryKey) {
8081
$sql = 'INSERT INTO ' . $table . ' (' . $keys . ") \n SELECT * FROM (\n";
81-
$select_query_values = [];
82+
$selectQueryValues = [];
8283

83-
for ($i = 0, $c = count($values); $i < $c; $i++) {
84-
$select_query_values[] = 'SELECT ' . substr(substr($values[$i], 1), 0, -1) . ' FROM DUAL';
84+
foreach ($values as $value) {
85+
$selectQueryValues[] = 'SELECT ' . substr(substr($value, 1), 0, -1) . ' FROM DUAL';
8586
}
8687

87-
return $sql . implode("\n UNION ALL \n", $select_query_values) . "\n)";
88+
return $sql . implode("\n UNION ALL \n", $selectQueryValues) . "\n)";
8889
}
8990

9091
$sql = "INSERT ALL\n";
9192

92-
for ($i = 0, $c = count($values); $i < $c; $i++) {
93-
$sql .= ' INTO ' . $table . ' (' . $keys . ') VALUES ' . $values[$i] . "\n";
93+
foreach ($values as $value) {
94+
$sql .= ' INTO ' . $table . ' (' . $keys . ') VALUES ' . $value . "\n";
9495
}
9596

9697
return $sql . 'SELECT * FROM dual';
@@ -107,18 +108,18 @@ protected function _insertBatch(string $table, array $keys, array $values): stri
107108
*/
108109
protected function _replace(string $table, array $keys, array $values): string
109110
{
110-
$field_names = array_map(static function ($column_name) {
111-
return trim($column_name, '"');
111+
$fieldNames = array_map(static function ($columnName) {
112+
return trim($columnName, '"');
112113
}, $keys);
113114

114-
$unique_indexes = array_filter($this->db->getIndexData($table), static function ($index) use ($field_names) {
115-
$has_all_fields = count(array_intersect($index->fields, $field_names)) === count($index->fields);
115+
$uniqueIndexes = array_filter($this->db->getIndexData($table), static function ($index) use ($fieldNames) {
116+
$hasAllFields = count(array_intersect($index->fields, $fieldNames)) === count($index->fields);
116117

117-
return ($index->type === 'PRIMARY') && $has_all_fields;
118+
return ($index->type === 'PRIMARY') && $hasAllFields;
118119
});
119-
$replaceable_fields = array_filter($keys, static function ($column_name) use ($unique_indexes) {
120-
foreach ($unique_indexes as $index) {
121-
if (in_array(trim($column_name, '"'), $index->fields, true)) {
120+
$replaceableFields = array_filter($keys, static function ($columnName) use ($uniqueIndexes) {
121+
foreach ($uniqueIndexes as $index) {
122+
if (in_array(trim($columnName, '"'), $index->fields, true)) {
122123
return false;
123124
}
124125
}
@@ -128,31 +129,31 @@ protected function _replace(string $table, array $keys, array $values): string
128129

129130
$sql = 'MERGE INTO ' . $table . "\n USING (SELECT ";
130131

131-
$sql .= implode(', ', array_map(static function ($column_name, $value) {
132-
return $value . ' ' . $column_name;
132+
$sql .= implode(', ', array_map(static function ($columnName, $value) {
133+
return $value . ' ' . $columnName;
133134
}, $keys, $values));
134135

135136
$sql .= ' FROM DUAL) "_replace" ON ( ';
136137

137-
$on_list = [];
138-
$on_list[] = '1 != 1';
138+
$onList = [];
139+
$onList[] = '1 != 1';
139140

140-
foreach ($unique_indexes as $index) {
141-
$on_list[] = '(' . implode(' AND ', array_map(static function ($column_name) use ($table) {
142-
return $table . '."' . $column_name . '" = "_replace"."' . $column_name . '"';
141+
foreach ($uniqueIndexes as $index) {
142+
$onList[] = '(' . implode(' AND ', array_map(static function ($columnName) use ($table) {
143+
return $table . '."' . $columnName . '" = "_replace"."' . $columnName . '"';
143144
}, $index->fields)) . ')';
144145
}
145146

146-
$sql .= implode(' OR ', $on_list) . ') WHEN MATCHED THEN UPDATE SET ';
147+
$sql .= implode(' OR ', $onList) . ') WHEN MATCHED THEN UPDATE SET ';
147148

148-
$sql .= implode(', ', array_map(static function ($column_name) {
149-
return $column_name . ' = "_replace".' . $column_name;
150-
}, $replaceable_fields));
149+
$sql .= implode(', ', array_map(static function ($columnName) {
150+
return $columnName . ' = "_replace".' . $columnName;
151+
}, $replaceableFields));
151152

152-
$sql .= ' WHEN NOT MATCHED THEN INSERT (' . implode(', ', $replaceable_fields) . ') VALUES ';
153-
$sql .= ' (' . implode(', ', array_map(static function ($column_name) {
154-
return '"_replace".' . $column_name;
155-
}, $replaceable_fields)) . ')';
153+
$sql .= ' WHEN NOT MATCHED THEN INSERT (' . implode(', ', $replaceableFields) . ') VALUES ';
154+
$sql .= ' (' . implode(', ', array_map(static function ($columnName) {
155+
return '"_replace".' . $columnName;
156+
}, $replaceableFields)) . ')';
156157

157158
return $sql;
158159
}
@@ -180,17 +181,17 @@ protected function _truncate(string $table): string
180181
* @param mixed $where The where clause
181182
* @param int $limit The limit clause
182183
*
183-
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
184+
* @throws DatabaseException
184185
*
185186
* @return mixed
186187
*/
187-
public function delete($where = '', ?int $limit = null, bool $reset_data = true)
188+
public function delete($where = '', ?int $limit = null, bool $resetData = true)
188189
{
189190
if (! empty($limit)) {
190191
$this->QBLimit = $limit;
191192
}
192193

193-
return parent::delete($where, null, $reset_data);
194+
return parent::delete($where, null, $resetData);
194195
}
195196

196197
/**

system/Database/OCI8/Connection.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
/**
2121
* Connection for Postgre
22+
*
23+
* @property string|null $latestInsertedTableName
24+
* @property int|null $rowId
2225
*/
2326
class Connection extends BaseConnection implements ConnectionInterface
2427
{
@@ -173,10 +176,10 @@ public function getVersion(): string
173176
return $this->dataCache['version'];
174177
}
175178

176-
if (! $this->connID || ($version_string = oci_server_version($this->connID)) === false) {
179+
if (! $this->connID || ($versionString = oci_server_version($this->connID)) === false) {
177180
return '';
178181
}
179-
if (preg_match('#Release\s(\d+(?:\.\d+)+)#', $version_string, $match)) {
182+
if (preg_match('#Release\s(\d+(?:\.\d+)+)#', $versionString, $match)) {
180183
return $this->dataCache['version'] = $match[1];
181184
}
182185

@@ -188,7 +191,7 @@ public function getVersion(): string
188191
*
189192
* @return bool|resource
190193
*/
191-
public function execute(string $sql)
194+
protected function execute(string $sql)
192195
{
193196
try {
194197
if ($this->resetStmtId === true) {
@@ -261,9 +264,9 @@ protected function _listColumns(string $table = ''): string
261264
*
262265
* @throws DatabaseException
263266
*
264-
* @return \stdClass[]
267+
* @return stdClass[]
265268
*/
266-
public function _fieldData(string $table): array
269+
protected function _fieldData(string $table): array
267270
{
268271
if (strpos($table, '.') !== false) {
269272
sscanf($table, '%[^.].%s', $owner, $table);
@@ -311,9 +314,9 @@ public function _fieldData(string $table): array
311314
*
312315
* @throws DatabaseException
313316
*
314-
* @return \stdClass[]
317+
* @return stdClass[]
315318
*/
316-
public function _indexData(string $table): array
319+
protected function _indexData(string $table): array
317320
{
318321
if (strpos($table, '.') !== false) {
319322
sscanf($table, '%[^.].%s', $owner, $table);
@@ -360,9 +363,9 @@ public function _indexData(string $table): array
360363
*
361364
* @throws DatabaseException
362365
*
363-
* @return \stdClass[]
366+
* @return stdClass[]
364367
*/
365-
public function _foreignKeyData(string $table): array
368+
protected function _foreignKeyData(string $table): array
366369
{
367370
$sql = 'SELECT
368371
acc.constraint_name,
@@ -488,21 +491,21 @@ public function storedProcedure(string $package, string $procedure, array $param
488491
// Build the query string
489492
$sql = 'BEGIN ' . $package . '.' . $procedure . '(';
490493

491-
$have_cursor = false;
494+
$haveCursor = false;
492495

493496
foreach ($params as $param) {
494497
$sql .= $param['name'] . ',';
495498

496499
if (isset($param['type']) && $param['type'] === OCI_B_CURSOR) {
497-
$have_cursor = true;
500+
$haveCursor = true;
498501
}
499502
}
500503
$sql = trim($sql, ',') . '); END;';
501504

502505
$this->resetStmtId = false;
503506
$this->stmtId = oci_parse($this->connID, $sql);
504507
$this->bindParams($params);
505-
$result = $this->query($sql, false, $have_cursor);
508+
$result = $this->query($sql, false, $haveCursor);
506509
$this->resetStmtId = true;
507510

508511
return $result;
@@ -572,34 +575,34 @@ public function insertID(): int
572575
}
573576

574577
$indexs = $this->getIndexData($this->latestInsertedTableName);
575-
$field_datas = $this->getFieldData($this->latestInsertedTableName);
578+
$fieldDatas = $this->getFieldData($this->latestInsertedTableName);
576579

577-
if (! $indexs || ! $field_datas) {
580+
if (! $indexs || ! $fieldDatas) {
578581
return 0;
579582
}
580583

581-
$column_type_list = array_column($field_datas, 'type', 'name');
582-
$primary_column_name = '';
584+
$columnTypeList = array_column($fieldDatas, 'type', 'name');
585+
$primaryColumnName = '';
583586

584587
foreach ($indexs as $index) {
585588
if ($index->type !== 'PRIMARY' || count($index->fields) !== 1) {
586589
continue;
587590
}
588591

589-
$primary_column_name = $this->protectIdentifiers($index->fields[0], false, false);
590-
$primary_column_type = $column_type_list[$primary_column_name];
592+
$primaryColumnName = $this->protectIdentifiers($index->fields[0], false, false);
593+
$primaryColumnType = $columnTypeList[$primaryColumnName];
591594

592-
if ($primary_column_type !== 'NUMBER') {
595+
if ($primaryColumnType !== 'NUMBER') {
593596
continue;
594597
}
595598
}
596599

597-
if (! $primary_column_name) {
600+
if (! $primaryColumnName) {
598601
return 0;
599602
}
600603

601604
$table = $this->protectIdentifiers($this->latestInsertedTableName, true);
602-
$query = $this->query('SELECT ' . $this->protectIdentifiers($primary_column_name, false) . ' SEQ FROM ' . $table . ' WHERE ROWID = ?', $this->rowId)->getRow();
605+
$query = $this->query('SELECT ' . $this->protectIdentifiers($primaryColumnName, false) . ' SEQ FROM ' . $table . ' WHERE ROWID = ?', $this->rowId)->getRow();
603606

604607
return (int) ($query->SEQ ?? 0);
605608
}

0 commit comments

Comments
 (0)