Skip to content

Commit 6f828ee

Browse files
committed
Move count() outside of the loop
Signed-off-by: Michal Čihař <michal@cihar.com>
1 parent 2effa37 commit 6f828ee

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/Components/CaseExpression.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,17 @@ public static function build($component, array $options = array())
211211
if (isset($component->value)) {
212212
// Syntax type 0
213213
$ret .= $component->value . ' ';
214-
for (
215-
$i = 0;
216-
$i < count($component->compare_values) && $i < count($component->results);
217-
++$i
218-
) {
214+
$val_cnt = count($component->compare_values);
215+
$res_cnt = count($component->results);
216+
for ($i = 0; $i < $val_cnt && $i < $res_cnt; ++$i) {
219217
$ret .= 'WHEN ' . $component->compare_values[$i] . ' ';
220218
$ret .= 'THEN ' . $component->results[$i] . ' ';
221219
}
222220
} else {
223221
// Syntax type 1
224-
for (
225-
$i = 0;
226-
$i < count($component->conditions) && $i < count($component->results);
227-
++$i
228-
) {
222+
$val_cnt = count($component->conditions);
223+
$res_cnt = count($component->results);
224+
for ($i = 0; $i < $val_cnt && $i < $res_cnt; ++$i) {
229225
$ret .= 'WHEN ' . Condition::build($component->conditions[$i]) . ' ';
230226
$ret .= 'THEN ' . $component->results[$i] . ' ';
231227
}

0 commit comments

Comments
 (0)