private function substituteVars($expression, $quote): string
    {
        return preg_replace_callback(
            '/\$(\w+)/',
            function (array $matches) use ($quote): string {
                if (isset($this->vars[$matches[1]]['id'])) {
                    if ($quote) {
                        return "'" . addcslashes($this->vars[$matches[1]]['id'], "'") . "'";
                    }

                    return $this->vars[$matches[1]]['id'];
                }

                Log::addErrorLog(sprintf('Undefined variable $%s in report', $matches[1]));

                return '$' . $matches[1];
            },
            $expression
        );
    }