Skip to content

Commit

Permalink
Silence AssertionError coming from doctrine/orm DQL parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 6, 2023
1 parent 4967ebb commit be3808f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Rules/Doctrine/ORM/DqlRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Rules\Doctrine\ORM;

use AssertionError;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\QueryException;
use PhpParser\Node;
Expand Down Expand Up @@ -76,6 +77,8 @@ public function processNode(Node $node, Scope $scope): array
$query->getAST();
} catch (QueryException $e) {
$messages[] = sprintf('DQL: %s', $e->getMessage());
} catch (AssertionError $e) {
continue;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Rules/Doctrine/ORM/QueryBuilderDqlRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Rules\Doctrine\ORM;

use AssertionError;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\QueryException;
use PhpParser\Node;
Expand Down Expand Up @@ -107,6 +108,8 @@ public function processNode(Node $node, Scope $scope): array
}

$messages[] = $message;
} catch (AssertionError $e) {
continue;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Type/Doctrine/CreateQueryDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Type\Doctrine;

use AssertionError;
use Doctrine\Common\CommonException;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Exception as NewDBALException;
Expand Down Expand Up @@ -88,6 +89,8 @@ public function getTypeFromMethodCall(
QueryResultTypeWalker::walk($query, $typeBuilder, $this->descriptorRegistry);
} catch (ORMException | DBALException | NewDBALException | CommonException $e) {
return new QueryType($queryString, null, null);
} catch (AssertionError $e) {
return new QueryType($queryString, null, null);
}

return new QueryType($queryString, $typeBuilder->getIndexType(), $typeBuilder->getResultType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Type\Doctrine\QueryBuilder;

use AssertionError;
use Doctrine\Common\CommonException;
use Doctrine\DBAL\DBALException;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -163,6 +164,8 @@ private function getQueryType(string $dql): Type
QueryResultTypeWalker::walk($query, $typeBuilder, $this->descriptorRegistry);
} catch (ORMException | DBALException | CommonException $e) {
return new QueryType($dql, null);
} catch (AssertionError $e) {
return new QueryType($dql, null);
}

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

0 comments on commit be3808f

Please sign in to comment.