<commit_before><?php
/**
 * @author <NAME> <<EMAIL>> 2016
 * @since 2016-06-06 12:59
 * @version 1.0
 */

namespace Tormit\Helper;

/**
 * Wrapper for PHP sleep functions.
 *
 * Class Sleeper
 * @package Tormit\Helper
 */
class Sleeper
{
    protected $microseconds = 1000;
    protected $retries = 1;
    protected $escalateFactor = 1.0;

    public function seconds($seconds)
    {
        $this->microseconds = $seconds * 1000 * 1000;

        return $this;
    }

    public function milliseconds($milliseconds)
    {
        $this->microseconds = $milliseconds * 1000;

        return $this;
    }

    public function times($times)
    {
        $this->retries = $times;

        return $this;
    }

    /**
     * Wait time is cumulatively multiplied by this factor.
     * Example: For sleep time 2s and 1.5x escalate, you get sleep times: 2.00 3.00 4.50 6.75 10.13 etc.
     *
     * @param $escalateFactor
     * @return $this
     */
    public function escalate($escalateFactor)
    {
        $this->escalateFactor = $escalateFactor;

        return $this;
    }

    /**
     * Waits for gives time x times until condition is true.
     *
     * @param callable $condition
     * @return bool
     */
    public function whileTrue(callable $condition)
    {
        while ($this->retries > 0) {
            if (!$condition()) {
                usleep($this->microseconds);
            } else {
                return true;
            }

            $this->retries--;
            $this->microseconds *= $this->escalateFactor;
        }

        return false;
    }

    public static function wait()
    {
        return new self;
    }
}<commit_msg>Sleeper: Callback's attempt counter parameter<commit_after><?php
/**
 * @author <NAME> <<EMAIL>> 2016
 * @since 2016-06-06 12:59
 * @version 1.0
 */

namespace Tormit\Helper;

/**
 * Wrapper for PHP sleep functions.
 *
 * Class Sleeper
 * @package Tormit\Helper
 */
class Sleeper
{
    protected $microseconds = 1000;
    protected $retries = 1;
    protected $escalateFactor = 1.0;

    public function seconds($seconds)
    {
        $this->microseconds = $seconds * 1000 * 1000;

        return $this;
    }

    public function milliseconds($milliseconds)
    {
        $this->microseconds = $milliseconds * 1000;

        return $this;
    }

    public function times($times)
    {
        $this->retries = $times;

        return $this;
    }

    /**
     * Wait time is cumulatively multiplied by this factor.
     * Example: For sleep time 2s and 1.5x escalate, you get sleep times: 2.00 3.00 4.50 6.75 10.13 etc.
     *
     * @param $escalateFactor
     * @return $this
     */
    public function escalate($escalateFactor)
    {
        $this->escalateFactor = $escalateFactor;

        return $this;
    }

    /**
     * Waits for gives time x times until condition is true.
     *
     * @param callable $condition Callback params (int $attemptNumber)
     * @return bool
     */
    public function whileTrue(callable $condition)
    {
        $attempt = 1;
        while ($this->retries > 0) {
            if (!$condition($attempt)) {
                usleep($this->microseconds);
            } else {
                return true;
            }

            $this->retries--;
            $this->microseconds *= $this->escalateFactor;
            $attempt++;
        }

        return false;
    }

    public static function wait()
    {
        return new self;
    }
}
{'fraction_non_alphanumeric': 0.11735728774268328, 'fraction_numerical': 0.03332367429730513, 'mean_word_length': 1.8887029288702928, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, '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': '3462891', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1025, 'n_words': 277}