@Edent Consider using queryBuilder->createPositionalParameter()
instead. It handles incrementing the positional value for you so you don't have to track that when passing around a query builder or making a condition optional.
But yes, safely handling parameterized queries is one of the things I dislike about doctrine that I think they should have made better by default.