You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: remove unnecessary reflection from ExternalReferenceProcessingTrait
- Replace reflection with direct property access using property_exists
- Protected properties are accessible in trait scope when used in classes
- Simplify tests by creating ExternalReferenceProcessingTraitTestHelper class
- Add comprehensive SqlFormatter tests for MySQL, MariaDB, and MSSQL
- Fix dialect-specific quoteIdentifier and quoteTable test assertions
// Extract table name/alias from JOIN clause (e.g., "INNER JOIN [tenants] AS t" or "LEFT JOIN users u")
56
-
// Handle quoted identifiers: [tenants] AS t, "tenants" AS "t", tenants AS t, tenants t
57
-
// Pattern: JOIN [table] AS [alias] or JOIN "table" AS "alias" or JOIN table AS alias or JOIN table alias
58
-
// Match groups: [1]=[table], [2]="table", [3]=table, [4]=[alias], [5]="alias", [6]=alias
59
-
if (preg_match('/JOIN\s+(?:\[([^\]]+)\]|"([^"]+)"|([a-zA-Z_][a-zA-Z0-9_]*))\s+(?:AS\s+)?(?:\[([^\]]+)\]|"([^"]+)"|([a-zA-Z_][a-zA-Z0-9_]*))/i', $join, $matches)) {
60
-
// Check all possible alias positions (matches[4] for [alias], matches[5] for "alias", matches[6] for alias)
61
-
// Filter out empty strings - check in order: [5] (double quotes), [4] (square brackets), [6] (unquoted)
62
-
$alias = null;
63
-
foreach ([5, 4, 6] as$i) {
64
-
if (isset($matches[$i]) && $matches[$i] !== '') {
65
-
$alias = $matches[$i];
66
-
break;
67
-
}
68
-
}
69
-
if ($alias && $alias === $tableName) {
70
-
returntrue;
71
-
}
45
+
// Since we're in the same class scope (trait is used in class), protected properties are accessible directly
46
+
if (property_exists($this, 'joinBuilder') && isset($this->joinBuilder)) {
47
+
$joins = $this->joinBuilder->getJoins();
48
+
foreach ($joinsas$join) {
49
+
// Extract table name/alias from JOIN clause (e.g., "INNER JOIN [tenants] AS t" or "LEFT JOIN users u")
50
+
// Handle quoted identifiers: [tenants] AS t, "tenants" AS "t", tenants AS t, tenants t
51
+
// Pattern: JOIN [table] AS [alias] or JOIN "table" AS "alias" or JOIN table AS alias or JOIN table alias
52
+
// Match groups: [1]=[table], [2]="table", [3]=table, [4]=[alias], [5]="alias", [6]=alias
53
+
// The pattern must stop before "ON" keyword to avoid capturing it as alias
54
+
// Allow any characters before JOIN (e.g., "= JOIN" or "INNER JOIN")
55
+
// Use non-greedy match to stop at first "ON"
56
+
if (preg_match('/JOIN\s+(?:\[([^\]]+)\]|"([^"]+)"|([a-zA-Z_][a-zA-Z0-9_]*))(?:\s+AS\s+(?:\[([^\]]+)\]|"([^"]+)"|([a-zA-Z_][a-zA-Z0-9_]*)))?\s+ON/i', $join, $matches)) {
57
+
// First check table name (matches[1] for [table], matches[2] for "table", matches[3] for table)
58
+
$table = null;
59
+
foreach ([2, 1, 3] as$i) {
60
+
if (isset($matches[$i]) && $matches[$i] !== '') {
61
+
$table = $matches[$i];
62
+
break;
72
63
}
73
64
}
74
-
}
75
-
}
76
-
} catch (\ReflectionException$e) {
77
-
// If reflection fails, fall back to property_exists check
78
-
if (property_exists($this, 'joinBuilder') && isset($this->joinBuilder)) {
79
-
$joins = $this->joinBuilder->getJoins();
80
-
foreach ($joinsas$join) {
81
-
if (preg_match('/JOIN\s+(?:\[([^\]]+)\]|"([^"]+)"|([a-zA-Z_][a-zA-Z0-9_]*))\s+(?:AS\s+)?(?:\[([^\]]+)\]|"([^"]+)"|([a-zA-Z_][a-zA-Z0-9_]*))/i', $join, $matches)) {
82
-
$alias = null;
83
-
foreach ([5, 4, 6] as$i) {
84
-
if (isset($matches[$i]) && $matches[$i] !== '') {
85
-
$alias = $matches[$i];
86
-
break;
87
-
}
88
-
}
89
-
if ($alias && $alias === $tableName) {
90
-
returntrue;
65
+
if ($table && $table === $tableName) {
66
+
returntrue;
67
+
}
68
+
69
+
// Then check all possible alias positions (matches[4] for [alias], matches[5] for "alias", matches[6] for alias)
70
+
// Filter out empty strings - check in order: [5] (double quotes), [4] (square brackets), [6] (unquoted)
0 commit comments