<commit_before><?php
/**
 * @codingStandardsIgnoreStart
 *
 * @author       <NAME> <<EMAIL>>
 * @copyright    <NAME> 2017
 * @license      https://opensource.org/licenses/MIT
 *
 * @codingStandardsIgnoreEnd
 */

namespace Shrikeh\GuzzleMiddleware\TimerLogger\Timer;

use DateTimeImmutable;
use Litipk\BigNumbers\Decimal;

/**
 * Class Stopwatch.
 */
class Stopwatch implements TimerInterface
{
    /**
     * @var float
     */
    private $start;

    /**
     * @var float
     */
    private $end;

    /**
     * @return self
     */
    public static function startStopWatch()
    {
        $t = \microtime(true);

        return new self($t);
    }

    /**
     * Stopwatch constructor.
     *
     * @param float|null $start The start time
     */
    public function __construct($start = null)
    {
        $this->start = $start;
    }

    /**
     * {@inheritdoc}
     */
    public function start()
    {
        $t = \microtime(true);
        if (!$this->start) {
            $this->start = $t;
        }

        return $this->dateTime($this->start);
    }

    /**
     * {@inheritdoc}
     */
    public function stop()
    {
        $t = \microtime(true);
        if (!$this->end) {
            $this->end = $t;
        }

        return $this->dateTime($this->end);
    }

    /**
     * {@inheritdoc}
     */
    public function duration($precision = 0)
    {
        $this->stop();

        $start = $this->decimal($this->start);
        $end = $this->decimal($this->end);

        return Decimal::fromDecimal($end->sub($start)
            ->mul(Decimal::fromInteger(1000)), $precision)->asFloat();
    }

    /**
     * @param Decimal $time The time to format to a DateTimeImmutable
     *
     * @return \DateTimeImmutable
     */
    private function dateTime($time)
    {
        $time = $this->decimal($time);
        $micro = sprintf('%06d', $this->mantissa($time)->asInteger());

        return new DateTimeImmutable(
            \date('Y-m-d H:i:s.'.$micro, $time->asFloat())
        );
    }

    /**
     * @param Decimal $time The time to get the mantissa from
     *
     * @return Decimal
     */
    private function mantissa(Decimal $time)
    {
        $mantissa = ($time->sub($time->floor()));

        return $mantissa->mul(Decimal::fromInteger(1000000));
    }
<commit_msg>Force float to aid type hinting<commit_after><?php
/**
 * @codingStandardsIgnoreStart
 *
 * @author       <NAME> <<EMAIL>>
 * @copyright    <NAME> 2017
 * @license      https://opensource.org/licenses/MIT
 *
 * @codingStandardsIgnoreEnd
 */

namespace Shrikeh\GuzzleMiddleware\TimerLogger\Timer;

use DateTimeImmutable;
use Litipk\BigNumbers\Decimal;

/**
 * Class Stopwatch.
 */
class Stopwatch implements TimerInterface
{
    /**
     * @var float
     */
    private $start;

    /**
     * @var float
     */
    private $end;

    /**
     * @return self
     */
    public static function startStopWatch()
    {
        $t = (float) \microtime(true);

        return new self($t);
    }

    /**
     * Stopwatch constructor.
     *
     * @param float|null $start The start time
     */
    public function __construct($start = null)
    {
        $this->start = $start;
    }

    /**
     * {@inheritdoc}
     */
    public function start()
    {
        $t = (float) \microtime(true);
        if (!$this->start) {
            $this->start = $t;
        }

        return $this->dateTime($this->start);
    }

    /**
     * {@inheritdoc}
     */
    public function stop()
    {
        $t = \microtime(true);
        if (!$this->end) {
            $this->end = $t;
        }

        return $this->dateTime($this->end);
    }

    /**
     * {@inheritdoc}
     */
    public function duration($precision = 0)
    {
        $this->stop();

        $start = $this->decimal($this->start);
        $end = $this->decimal($this->end);

        return Decimal::fromDecimal($end->sub($start)
            ->mul(Decimal::fromInteger(1000)), $precision)->asFloat();
    }

    /**
     * @param float $time The time to format to a DateTimeImmutable
     *
     * @return \DateTimeImmutable
     */
    private function dateTime($time)
    {
        $time = $this->decimal($time);
        $micro = sprintf('%06d', $this->mantissa($time)->asInteger());

        return new DateTimeImmutable(
            \date('Y-m-d H:i:s.'.$micro, $time->asFloat())
        );
    }

    /**
     * @param Decimal $time The time to get the mantissa from
     *
     * @return Decimal
     */
    private function mantissa(Decimal $time)
    {
        $mantissa = ($time->sub($time->floor()));

        return $mantissa->mul(Decimal::fromInteger(1000000));
    }

{'fraction_non_alphanumeric': 0.16144267926148562, 'fraction_numerical': 0.007728638900815801, 'mean_word_length': 1.930188679245283, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 59, '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': '5074892', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1435, 'n_words': 287}