public static function convertUnmappedToPHPValue($value)
    {
        $type  = key($value);
        $value = current($value);

        switch ($type) {
            case 'S':
            case 'B':
            case 'BOOL':
                return $value;
            case 'NULL':
                return null;
            case 'N':
                // Use type coercion to unmarshal numbers to int/float.
                return $value + 0;
            case 'M':
            case 'L':
                foreach ($value as $k => $v) {
                    $value[$k] = self::convertUnmappedToPHPValue($v);
                }

                return $value;
            case 'BS':
            case 'NS':
            case 'SS':
                $childType = substr($type, 0, 1);

                return array_map(
                    function ($childValue) use ($childType) {
                        return self::convertUnmappedToPHPValue([$childType => $childValue]);
                    },
                    $value
                );
        }

        throw new \UnexpectedValueException("Unexpected type: $type.");
    }