<commit_before><?php

namespace Del\Phi;

class Fraction
{
    /** @var int $whole */
    private $whole;

    /** @var int $numerator */
    private $numerator;

    /** @var int $denominator */
    private $denominator;

    /** @var bool $negative */
    private $negative;

    public function __construct($whole = 0, $numerator = 0, $denominator = 1)
    {
        $this->whole = $whole;
        $this->numerator = $numerator;
        $this->denominator = $denominator;
        $this->negative = false;
    }

    /**
     * @return int
     */
    public function getWhole()
    {
        return $this->whole;
    }

    /**
     * @param int $whole
     * @return Fraction
     */
    public function setWhole($whole)
    {
        $this->whole = $whole;
        return $this;
    }

    /**
     * @return int
     */
    public function getNumerator()
    {
        return $this->numerator;
    }

    /**
     * @param int $numerator
     * @return Fraction
     */
    public function setNumerator($numerator)
    {
        $this->numerator = $numerator;
        return $this;
    }

    /**
     * @return int
     */
    public function getDenominator()
    {
        return $this->denominator;
    }

    /**
     * @param int $denominator
     * @return Fraction
     */
    public function setDenominator($denominator)
    {
        $this->denominator = $denominator;
        return $this;
    }

    private function refactor()
    {
        // 9/8 would become 1 1/8 for instance
        if ($this->numerator >= $this->denominator) {
            $this->refactorWhole();
        }
        if ($this->numerator > 0) {
            $this->refactorFraction();
        }
    }

    private function refactorWhole()
    {
        // decrement $x and the numerator by the denominator each loop, and add to the whole
        for ($x = $this->numerator; $x >= $this->denominator; $x = $x - $this->denominator) {
            $this->whole ++;
            $this->numerator -= $this->denominator;
        }
    }

    /**
     * a/b × c/d = ac/bd
     */
    private function refactorFraction()
    {
        $gcd = $this->getGreatestCommonDenominator($this->numerator, $this->denominator);
        $this->numerator = $this->numerator / $gcd;
        $this->denominator = $this->denominator / $gcd;
    }

    /**
     * @param int $x
     * @param int $y<commit_msg>if statement around refactoring fraction to stop divisions by zero<commit_after><?php

namespace Del\Phi;

class Fraction
{
    /** @var int $whole */
    private $whole;

    /** @var int $numerator */
    private $numerator;

    /** @var int $denominator */
    private $denominator;

    /** @var bool $negative */
    private $negative;

    public function __construct($whole = 0, $numerator = 0, $denominator = 1)
    {
        $this->whole = $whole;
        $this->numerator = $numerator;
        $this->denominator = $denominator;
        $this->negative = false;
    }

    /**
     * @return int
     */
    public function getWhole()
    {
        return $this->whole;
    }

    /**
     * @param int $whole
     * @return Fraction
     */
    public function setWhole($whole)
    {
        $this->whole = $whole;
        return $this;
    }

    /**
     * @return int
     */
    public function getNumerator()
    {
        return $this->numerator;
    }

    /**
     * @param int $numerator
     * @return Fraction
     */
    public function setNumerator($numerator)
    {
        $this->numerator = $numerator;
        return $this;
    }

    /**
     * @return int
     */
    public function getDenominator()
    {
        return $this->denominator;
    }

    /**
     * @param int $denominator
     * @return Fraction
     */
    public function setDenominator($denominator)
    {
        $this->denominator = $denominator;
        return $this;
    }

    private function refactor()
    {
        // 9/8 would become 1 1/8 for instance
        if ($this->numerator >= $this->denominator) {
            $this->refactorWhole();
        }
        if ($this->numerator > 0) {
            $this->refactorFraction();
        }
    }

    private function refactorWhole()
    {
        // decrement $x and the numerator by the denominator each loop, and add to the whole
        for ($x = $this->numerator; $x >= $this->denominator; $x = $x - $this->denominator) {
            $this->whole ++;
            $this->numerator -= $this->denominator;
        }
    }

    private function refactorFraction()
    {
        if ($this->numerator > 0 && $this->denominator > 0 ) {
            $gcd = $this->getGreatestCommonDenominator($this->numerator, $this->denominator);
            $this->numerator = $this->numerator / $gcd;
            $this->denominator = $this->denominator / $gcd;
        }
    }

    /**
     * @param int $x
     * @param int $y
{'fraction_non_alphanumeric': 0.1407315561066336, 'fraction_numerical': 0.0041330853482124405, 'mean_word_length': 1.7944572748267897, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, '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': '5476390', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1497, 'n_words': 343}