public static function streamGetContents($data): string
    {
        // check if it's actually a resource, we can directly convert
        // string without any issue.
        if (! \is_resource($data)) {
            return $data;
        }

        // Get the content from stream.
        $hex = \stream_get_contents($data);

        // For some reason hex would always start with 'x' and if we
        // don't filter out this char, it would mess up hex to string
        // conversion.
        if (\preg_match('/^x(.*)$/', $hex, $matches)) {
            $hex = $matches[1];
        }

        // Check if it's actually a hex string before trying to convert.
        if (! \ctype_xdigit($hex)) {
            return $hex;
        }

        return static::fromHex($hex);
    }