<commit_before><?php

namespace CalendR\Period;

/**
 * Represents a minute
 *
 * @author <NAME> <<EMAIL>>
 */
class Minute extends PeriodAbstract
{
    /**
     * @param \DateTime        $begin
     * @param FactoryInterface $factory
     *
     * @throws Exception\NotAMinute
     */
    public function __construct(\DateTime $begin, $factory = null)
    {
        if (!self::isValid($begin)) {
            throw new Exception\NotAMinute;
        }

        $this->begin = clone $begin;
        $this->end = clone $begin;
        $this->end->add($this->getDateInterval());

        parent::__construct($factory);
    }

    /**
     * Returns the period as a DatePeriod
     *
     * @return \DatePeriod
     */
    public function getDatePeriod()
    {
        return new \DatePeriod($this->begin, new \DateInterval('PT1S'), $this->end);
    }

    /**
     * @param \DateTime $start
     *
     * @return bool
     */
    public static function isValid(\DateTime $start)
    {
        return $start->format('s') == '00';
    }

    /**
     * Returns the minute
     *
     * @return string
     */
    public function __toString()
    {
        return $this->format('i');
    }

    /**
     * Returns a \DateInterval equivalent to the period
     *
     * @return \DateInterval<commit_msg>Enable Minute Iteration<commit_after><?php

namespace CalendR\Period;

/**
 * Represents a minute
 *
 * @author <NAME> <<EMAIL>>
 */
class Minute extends PeriodAbstract implements \Iterator
{
    /**
     * @var PeriodInterface
     */
    private $current;

    /**
     * @param \DateTime        $begin
     * @param FactoryInterface $factory
     *
     * @throws Exception\NotAMinute
     */
    public function __construct(\DateTime $begin, $factory = null)
    {
        if (!self::isValid($begin)) {
            throw new Exception\NotAMinute;
        }

        $this->begin = clone $begin;
        $this->end = clone $begin;
        $this->end->add($this->getDateInterval());

        parent::__construct($factory);
    }

    /**
     * Returns the period as a DatePeriod
     *
     * @return \DatePeriod
     */
    public function getDatePeriod()
    {
        return new \DatePeriod($this->begin, new \DateInterval('PT1S'), $this->end);
    }

    /**
     * @param \DateTime $start
     *
     * @return bool
     */
    public static function isValid(\DateTime $start)
    {
        return $start->format('s') == '00';
    }

    /**
     * {@inheritDoc}
     */
    public function current()
    {
        return $this->current;
    }

    /**
     * {@inheritDoc}
     */
    public function next()
    {
        if (null === $this->current) {
            $this->current = $this->getFactory()->createSecond($this->begin);
        } else {
            $this->current = $this->current->getNext();
            if (!$this->contains($this->current->getBegin())) {
                $this->current = null;
            }
        }
    }

    /**
     * {@inheritDoc}
     */
    public function key()
    {
        return (int) $this->current->getBegin()->format('i');
    }

    /**
     * {@inheritDoc}
     */
    public function valid()
    {
        return null !== $this->current;
    }

    /**
     * {@inheritDoc}
     */
    public function rewind()
    {
        $this->current = null;
        $this->next();
    }

    /**
     * Returns the minute
     *
     * @return string
     */
    public function __toString()
    {
        return $this->format('i');
    }

    /**
     * Returns a \DateInterval equivalent to the period
     *
     * @return \DateInterval
{'fraction_non_alphanumeric': 0.1507537688442211, 'fraction_numerical': 0.0016750418760469012, 'mean_word_length': 1.8035993740219092, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 46, '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': '6861779', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1044, 'n_words': 228}