public function dequeue($platform = null)
    {
        if (null === $platform) {
            return array_shift($this->queue);
        }

        // The array pointer does not reset between method calls. So we need to reset it manually.
        reset($this->queue);

        do {
            $index = key($this->queue);
            $method = current($this->queue);
            next($this->queue);
        } while ($method instanceof MethodInterface && !$method->supports($platform));

        if (null !== $index) {
            unset($this->queue[$index]);
        }
        if (false === $method) {
            $method = null;
        }

        return $method;
    }