<commit_before><?php

namespace Brumann\Polyfill;

final class Unserialize
{
    /**
     * @see https://secure.php.net/manual/en/function.unserialize.php
     *
     * @param string $serialized Serialized data
     * @param array $options Associative array containing options
     *
     * @return mixed
     */
    public static function unserialize($serialized, array $options = array())
    {
        if (PHP_VERSION_ID >= 70000) {
            return \unserialize($serialized, $options);
        }
        if (!array_key_exists('allowed_classes', $options)) {
            $options['allowed_classes'] = true;
        }
        $allowedClasses = $options['allowed_classes'];
        if (true === $allowedClasses) {
            return \unserialize($serialized);
        }
        if (false === $allowedClasses) {
            $allowedClasses = array();
        }
        if (!is_array($allowedClasses)) {
            trigger_error(
                'unserialize(): allowed_classes option should be array or boolean',
                E_USER_WARNING
            );
            $allowedClasses = array();
        }
        $sanitizedSerialized = preg_replace_callback(
            '/\bO:\d+:"([^"]*)":(\d+):{/',
            function ($matches) use ($allowedClasses) {
                if (in_array($matches[1], $allowedClasses)) {
                    return $matches[0];
                } else {
                    return sprintf(
                        'O:22:"__PHP_Incomplete_Class":%d:{s:27:"__PHP_Incomplete_Class_Name";%s',
                        $matches[2] + 1, // size of object + 1 for added string
                        \serialize($matches[1]) // original class name
                    );
                }
            },
            $serialized
        );

        return \unserialize($sanitizedSerialized);
    }
}<commit_msg>Make matches explicit by assigning them to variables<commit_after><?php

namespace Brumann\Polyfill;

final class Unserialize
{
    /**
     * @see https://secure.php.net/manual/en/function.unserialize.php
     *
     * @param string $serialized Serialized data
     * @param array $options Associative array containing options
     *
     * @return mixed
     */
    public static function unserialize($serialized, array $options = array())
    {
        if (PHP_VERSION_ID >= 70000) {
            return \unserialize($serialized, $options);
        }
        if (!array_key_exists('allowed_classes', $options)) {
            $options['allowed_classes'] = true;
        }
        $allowedClasses = $options['allowed_classes'];
        if (true === $allowedClasses) {
            return \unserialize($serialized);
        }
        if (false === $allowedClasses) {
            $allowedClasses = array();
        }
        if (!is_array($allowedClasses)) {
            trigger_error(
                'unserialize(): allowed_classes option should be array or boolean',
                E_USER_WARNING
            );
            $allowedClasses = array();
        }

        $sanitizedSerialized = preg_replace_callback(
            '/\bO:\d+:"([^"]*)":(\d+):{/',
            function ($match) use ($allowedClasses) {
                list($completeMatch, $matchedClassName, $matchedObjectSize) = $match;
                if (in_array($matchedClassName, $allowedClasses)) {
                    return $completeMatch;
                } else {
                    return sprintf(
                        'O:22:"__PHP_Incomplete_Class":%d:{s:27:"__PHP_Incomplete_Class_Name";%s',
                        $matchedObjectSize + 1, // size of object + 1 for added string
                        \serialize($matchedClassName)
                    );
                }
            },
            $serialized
        );

        return \unserialize($sanitizedSerialized);
    }
}
{'fraction_non_alphanumeric': 0.12207313864772429, 'fraction_numerical': 0.0068403051828466194, 'mean_word_length': 1.7630813953488371, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1314135', 'n_tokens_mistral': 1017, 'n_tokens_neox': 972, 'n_words': 204}