Skip to content

Commit 22be17e

Browse files
authored
Refactor JoinHelperTrait for better table handling
1 parent 5b3ab3c commit 22be17e

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/Generators/Traits/JoinHelperTrait.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ public static function __callStatic(string \$name, array \$args): string
4242
\$e = constant("self::\$name");
4343
[\$fA, \$tA] = \$args + [null, null];
4444
if (!\$fA && !\$tA) return \$e;
45-
[\$f, \$t] = explode('__', substr(\$name, 4), 2);
46-
return str_replace([\$f . '.', \$t . '.'], [\$fA ? \$fA . '.' : \$f . '.', \$tA ? \$tA . '.' : \$t . '.'], \$e);
45+
[\$left, \$right] = explode('=', \$e, 2);
46+
[\$fromTable, \$fromCol] = array_map('trim', explode('.', \$left, 2));
47+
[\$toTable, \$toCol] = array_map('trim', explode('.', \$right, 2));
48+
\$fromTable = \$fA ?? \$fromTable;
49+
\$toTable = \$tA ?? \$toTable;
50+
return "{\$fromTable}.{\$fromCol} = {\$toTable}.{\$toCol}";
4751
}
48-
if (defined("self::" . strtoupper(\$name))) {
52+
53+
if (defined("self::" . \$name)) {
4954
return (\$a = \$args[0] ?? null) ? "\$name AS \$a" : \$name;
5055
}
51-
throw new \\BadMethodCallException("Undefined Tbl helper: \$name");
56+
throw new \BadMethodCallException("Undefined Tbl helper: \$name");
5257
}
5358
5459
PHP;

0 commit comments

Comments
 (0)