<commit_before><?php

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014-2015 Spomky-Labs
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

namespace OTPHP;

class HOTP extends OTP implements HOTPInterface
{
    public function __construct()
    {
        parent::__construct();
        $this->setCounter(0);
    }

    /**
     * {@inheritdoc}
     */
    public function setCounter($counter)
    {
        if (!is_int($counter) || $counter < 0) {
            throw new \InvalidArgumentException('Counter must be at least 0.');
        }

        $this->setParameter('counter', $counter);

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getCounter()
    {
        return $this->getParameter('counter');
    }

    /**
     * @param int $counter
     *
     * @return $this
     */
    private function updateCounter($counter)
    {
        $this->setCounter($counter);

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getProvisioningUri($google_compatible = true)
    {
        return $this->generateURI('hotp', ['counter' => $this->getCounter()], $google_compatible);
    }

    /**
     * {@inheritdoc}
     */
    public function verify($otp, $counter, $window = null)
    {
        if ($counter < $this->getCounter()) {
            return false;
        }

        if (!is_int($window)) {
            $window = 0;
        }
        $window = abs($window);

        for ($i = $counter; $i <= $counter + $window; ++$i) {
            if (hash_equals($this->at($i), $otp)) {
                $this->updateCounter($i + 1);

                return true;
            }
        }

        return false;
    }
}<commit_msg>Update HOTP.php<commit_after><?php

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014-2015 Spomky-Labs
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

namespace OTPHP;

class HOTP extends OTP implements HOTPInterface
{
    public function __construct()
    {
        parent::__construct();
        $this->setCounter(0);
    }

    /**
     * {@inheritdoc}
     */
    public function setCounter($counter)
    {
        if (!is_int($counter) || $counter < 0) {
            throw new \InvalidArgumentException('Counter must be at least 0.');
        }

        $this->setParameter('counter', $counter);

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getCounter()
    {
        return $this->getParameter('counter');
    }

    /**
     * @param int $counter
     *
     * @return $this
     */
    private function updateCounter($counter)
    {
        $this->setCounter($counter);

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getProvisioningUri($google_compatible = true)
    {
        return $this->generateURI('hotp', ['counter' => $this->getCounter()], $google_compatible);
    }

    /**
     * {@inheritdoc}
     */
    public function verify($otp, $counter, $window = null)
    {
        if ($counter < $this->getCounter()) {
            return false;
        }

        if (!is_int($window)) {
            $window = 0;
        }
        $window = abs($window);

        for ($i = $counter; $i <= $counter + $window; ++$i) {
            if ($this->compareOTP($this->at($i), $otp)) {
                $this->updateCounter($i + 1);

                return true;
            }
        }

        return false;
    }
}
{'fraction_non_alphanumeric': 0.14702581369248036, 'fraction_numerical': 0.007295173961840628, 'mean_word_length': 1.86115569823435, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 24, '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': '3653032', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1042, 'n_words': 247}