<commit_before><?php
/**
 * This file is part of the LdapTools package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace LdapTools\Connection;

/**
 * Try to retrieve a more detailed error message based on the specific AD response code.
 *
 * @author <NAME> <<EMAIL>>
 */
class ADLastErrorStrategy extends LastErrorStrategy
{
    /**
     * {@inheritdoc}
     */
    public function getLastErrorMessage()
    {
        $extendedError = $this->getExtendedErrorNumber();

        if (array_key_exists($extendedError, ADResponseCodes::RESPONSE_MESSAGE)) {
            $message = ADResponseCodes::RESPONSE_MESSAGE[$extendedError];
        } else {
            $message = parent::getLastErrorMessage();
        }

        return $message;
    }

    /**
     * {@inheritdoc}
     */
    public function getExtendedErrorNumber()
    {
        ldap_get_option($this->connection, self::DIAGNOSTIC_MESSAGE_OPT, $extendedError);

        $errorNumber = 0;
        if (!empty($extendedError)) {
            $errorNumber = explode(',', $extendedError)[2];
            $errorNumber = explode(' ', $errorNumber)[2];
            $errorNumber = hexdec(intval($errorNumber));
        }

        return $errorNumber;
    }
}<commit_msg>Be more strict when parsing the extended error string.<commit_after><?php
/**
 * This file is part of the LdapTools package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace LdapTools\Connection;

/**
 * Try to retrieve a more detailed error message based on the specific AD response code.
 *
 * @author <NAME> <<EMAIL>>
 */
class ADLastErrorStrategy extends LastErrorStrategy
{
    /**
     * {@inheritdoc}
     */
    public function getLastErrorMessage()
    {
        $extendedError = $this->getExtendedErrorNumber();

        if (array_key_exists($extendedError, ADResponseCodes::RESPONSE_MESSAGE)) {
            $message = ADResponseCodes::RESPONSE_MESSAGE[$extendedError];
        } else {
            $message = parent::getLastErrorMessage();
        }

        return $message;
    }

    /**
     * {@inheritdoc}
     */
    public function getExtendedErrorNumber()
    {
        ldap_get_option($this->connection, self::DIAGNOSTIC_MESSAGE_OPT, $extendedError);

        $errorNumber = 0;
        if (!empty($extendedError)) {
            $errorNumber = explode(',', $extendedError);
            if (!isset($errorNumber[2])) {
                return 0;
            };
            $errorNumber = explode(' ', $errorNumber[2]);
            if (!isset($errorNumber[2])) {
                return 0;
            };
            $errorNumber = hexdec(intval($errorNumber[2]));
        }

        return $errorNumber;
    }
}
{'fraction_non_alphanumeric': 0.12279488066413007, 'fraction_numerical': 0.0034590107229332413, 'mean_word_length': 2.5703703703703704, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, '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': '1209044', 'n_tokens_mistral': 820, 'n_tokens_neox': 795, 'n_words': 200}