Skip to content

Commit b11412d

Browse files
committed
refactor: simplify conditions in BaseConnection using Rector
1 parent a3df98f commit b11412d

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

system/Database/BaseConnection.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,10 +1280,8 @@ public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $pro
12801280
//
12811281
// Added exception for single quotes as well, we don't want to alter
12821282
// literal strings.
1283-
if (strcspn($item, "()'") !== strlen($item)) {
1284-
if ($this->isIdentifierEscapeExempt($item)) {
1285-
return $item;
1286-
}
1283+
if (strcspn($item, "()'") !== strlen($item) && $this->isIdentifierEscapeExempt($item)) {
1284+
return $item;
12871285
}
12881286

12891287
// Do not protect identifiers and do not prefix, no swap prefix, there is nothing to do
@@ -1456,14 +1454,8 @@ private function isIdentifierEscapeExempt(string $item): bool
14561454
}
14571455

14581456
// SQL functions or subqueries (e.g. MAX(id), (SELECT ...)) with an optional alias
1459-
if (str_contains($item, '(')) {
1460-
// Regex matching balanced parentheses (from start to end or with a safe alias)
1461-
if (preg_match('/^(?:[a-zA-Z0-9_.]+\s*)?(?P<parens>\((?:[^()]+|(?&parens))*\))(?:\s+AS\s+(?:[a-zA-Z0-9_.]+|"[^"]*"|\'[^\']*\'|`[^`]*`))?$/is', $item)) {
1462-
return true;
1463-
}
1464-
}
1465-
1466-
return false;
1457+
// Regex matching balanced parentheses (from start to end or with a safe alias)
1458+
return str_contains($item, '(') && preg_match('/^(?:[a-zA-Z0-9_.]+\s*)?(?P<parens>\((?:[^()]+|(?&parens))*\))(?:\s+AS\s+(?:[a-zA-Z0-9_.]+|"[^"]*"|\'[^\']*\'|`[^`]*`))?$/is', $item);
14671459
}
14681460

14691461
/**

0 commit comments

Comments
 (0)