Skip to content

Commit 0bbb26b

Browse files
committed
SqlPreprocessor: refactoring
1 parent 2e1a97b commit 0bbb26b

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/Database/SqlPreprocessor.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ class SqlPreprocessor
2222
/** @var array */
2323
private const MODE_LIST = ['and', 'or', 'set', 'values', 'order'];
2424

25+
private const ARRAY_MODES = [
26+
'INSERT' => 'values',
27+
'REPLACE' => 'values',
28+
'KEY UPDATE' => 'set',
29+
'SET' => 'set',
30+
'WHERE' => 'and',
31+
'HAVING' => 'and',
32+
'ORDER BY' => 'order',
33+
'GROUP BY' => 'order',
34+
];
35+
2536
/** @var Connection */
2637
private $connection;
2738

@@ -98,17 +109,8 @@ public function callback(array $m): string
98109
return $m;
99110

100111
} else { // command
101-
static $modes = [
102-
'INSERT' => 'values',
103-
'REPLACE' => 'values',
104-
'KEY UPDATE' => 'set',
105-
'SET' => 'set',
106-
'WHERE' => 'and',
107-
'HAVING' => 'and',
108-
'ORDER BY' => 'order',
109-
'GROUP BY' => 'order',
110-
];
111-
$this->arrayMode = $modes[ltrim(strtoupper($m))];
112+
$cmd = ltrim(strtoupper($m));
113+
$this->arrayMode = self::ARRAY_MODES[$cmd];
112114
return $m;
113115
}
114116
}

0 commit comments

Comments
 (0)