Skip to content

Commit be3808f

Browse files
committed
Silence AssertionError coming from doctrine/orm DQL parser
1 parent 4967ebb commit be3808f

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

src/Rules/Doctrine/ORM/DqlRule.php

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

33
namespace PHPStan\Rules\Doctrine\ORM;
44

5+
use AssertionError;
56
use Doctrine\ORM\EntityManagerInterface;
67
use Doctrine\ORM\Query\QueryException;
78
use PhpParser\Node;
@@ -76,6 +77,8 @@ public function processNode(Node $node, Scope $scope): array
7677
$query->getAST();
7778
} catch (QueryException $e) {
7879
$messages[] = sprintf('DQL: %s', $e->getMessage());
80+
} catch (AssertionError $e) {
81+
continue;
7982
}
8083
}
8184

src/Rules/Doctrine/ORM/QueryBuilderDqlRule.php

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

33
namespace PHPStan\Rules\Doctrine\ORM;
44

5+
use AssertionError;
56
use Doctrine\ORM\EntityManagerInterface;
67
use Doctrine\ORM\Query\QueryException;
78
use PhpParser\Node;
@@ -107,6 +108,8 @@ public function processNode(Node $node, Scope $scope): array
107108
}
108109

109110
$messages[] = $message;
111+
} catch (AssertionError $e) {
112+
continue;
110113
}
111114
}
112115

src/Type/Doctrine/CreateQueryDynamicReturnTypeExtension.php

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

33
namespace PHPStan\Type\Doctrine;
44

5+
use AssertionError;
56
use Doctrine\Common\CommonException;
67
use Doctrine\DBAL\DBALException;
78
use Doctrine\DBAL\Exception as NewDBALException;
@@ -88,6 +89,8 @@ public function getTypeFromMethodCall(
8889
QueryResultTypeWalker::walk($query, $typeBuilder, $this->descriptorRegistry);
8990
} catch (ORMException | DBALException | NewDBALException | CommonException $e) {
9091
return new QueryType($queryString, null, null);
92+
} catch (AssertionError $e) {
93+
return new QueryType($queryString, null, null);
9194
}
9295

9396
return new QueryType($queryString, $typeBuilder->getIndexType(), $typeBuilder->getResultType());

src/Type/Doctrine/QueryBuilder/QueryBuilderGetQueryDynamicReturnTypeExtension.php

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

33
namespace PHPStan\Type\Doctrine\QueryBuilder;
44

5+
use AssertionError;
56
use Doctrine\Common\CommonException;
67
use Doctrine\DBAL\DBALException;
78
use Doctrine\ORM\EntityManagerInterface;
@@ -163,6 +164,8 @@ private function getQueryType(string $dql): Type
163164
QueryResultTypeWalker::walk($query, $typeBuilder, $this->descriptorRegistry);
164165
} catch (ORMException | DBALException | CommonException $e) {
165166
return new QueryType($dql, null);
167+
} catch (AssertionError $e) {
168+
return new QueryType($dql, null);
166169
}
167170

168171
return new QueryType($dql, $typeBuilder->getIndexType(), $typeBuilder->getResultType());

0 commit comments

Comments
 (0)