Skip to content

Commit de122ad

Browse files
committed
Check platform + better error messages
1 parent e24fea2 commit de122ad

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Doctrine/MySql/UseIndexSqlWalker.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ShipMonk\Doctrine\MySql;
44

5+
use Doctrine\DBAL\Platforms\MySqlPlatform;
56
use Doctrine\ORM\Query\AST\FromClause;
67
use Doctrine\ORM\Query\AST\SelectStatement;
78
use Doctrine\ORM\Query\SqlWalker;
@@ -23,15 +24,22 @@ class UseIndexSqlWalker extends SqlWalker
2324
*/
2425
public function walkFromClause($fromClause): string
2526
{
27+
$selfClass = get_class($this);
2628
$query = $this->getQuery();
29+
$platform = $query->getEntityManager()->getConnection()->getDatabasePlatform();
30+
2731
$sql = parent::walkFromClause($fromClause);
2832

33+
if (!$platform instanceof MySqlPlatform) {
34+
throw new LogicException("Only MySQL platform is supported, {$platform->getName()} given");
35+
}
36+
2937
if (!$query->hasHint(self::class)) {
30-
throw new LogicException('UseIndexSqlWalker was used, but no index hint was added. Add ->setHint(UseIndexSqlWalker::class, [IndexHint::use(\'index_name\', \'table_name\')])');
38+
throw new LogicException("{$selfClass} was used, but no index hint was added. Add ->setHint({$selfClass}::class, [IndexHint::use('index_name', 'table_name')])");
3139
}
3240

3341
if (!$query->getAST() instanceof SelectStatement) {
34-
throw new LogicException('Only SELECT query type is currently supported');
42+
throw new LogicException("Only SELECT queries are currently supported by {$selfClass}");
3543
}
3644

3745
$hints = $query->getHint(self::class);
@@ -53,7 +61,7 @@ public function walkFromClause($fromClause): string
5361
$tableName = $hint->getTableName();
5462
$tableAlias = $hint->getDqlAlias() !== null
5563
? $this->getSQLTableAlias($hint->getTableName(), $hint->getDqlAlias())
56-
: '\S+';
64+
: '\S+'; // doctrine always adds some alias
5765
$tableWithAliasRegex = "~{$tableName}\s+{$tableAlias}~i";
5866

5967
if (Strings::match($sql, $tableWithAliasRegex) === null) {

0 commit comments

Comments
 (0)