public function flush($severity = null)
    {
        if ($severity === null) {
            $this->messages = [];
        } else {
            foreach ($this->messages as $index => $message) {
                if ($message->getSeverity() === $severity) {
                    unset($this->messages[$index]);
                }
            }
        }
    }