public static function readline(StreamInterface $stream, int $maxLength = null): string
    {
        $buffer = '';
        $size   = 0;

        while (! $stream->eof()) {
            $byte = $stream->read(1);
            // Using a loose equality here to match on '' and false.
            if ($byte === '' || $byte === false || $byte === null) {
                return $buffer;
            }

            $buffer .= $byte;

            // Break when a new line is found or the max length - 1 is reached
            if ($byte === "\n" || ++$size === $maxLength - 1) {
                break;
            }
        }

        return $buffer;
    }