src/Parsed/Doctrine/ParsedRuleGroup.php
public function copyWithReplacedString(string $search, string $replace, string $appendToEndIfNotFound): AbstractParsedRuleGroup
    {
        $count = 0;
        $newDql = str_replace($search, $replace, $this->getQueryString(), $count);

        if (0 === $count) {
            $newDql = $this->getQueryString().$appendToEndIfNotFound;
        }

        return new self($newDql, $this->parameters, $this->className);
    }
public function copyWithReplacedString(string $search, string $replace, string $appendToEndIfNotFound): AbstractParsedRuleGroup
    {
        $count = 0;
        $newDql = str_replace($search, $replace, $this->getQueryString(), $count);

        if (0 === $count) {
            $newDql = $this->getQueryString().$appendToEndIfNotFound;
        }

        return new self($newDql, $this->parameters, $this->className);
    }
For example, $parsedRuleGroup->copyWithReplacedString('ORDER BY', 'GROUP BY object.id ORDER BY', 'GROUP BY object.id').

"SELECT object FROM App\Entity\Class object ORDER BY object.id" would change to
"SELECT object FROM App\Entity\Class object GROUP BY object.id ORDER BY object.id".

"SELECT object FROM App\Entity\Class object" would change to
"SELECT object FROM App\Entity\Class object GROUP BY object.id"

{@inheritdoc}