src/Maths/Arithmetic/Helper.php
public static function GCD($a, $b)
    {
        if ($a<0 || $b<0) {
            throw new \InvalidArgumentException('GCD calculation of negative numbers is not allowed!');
        }
        if ($b===0) {
            return $a;
        }
        try {
            list(, $r) = self::EuclideanDivision($a, $b);
            return self::GCD($b, $r);
        } catch (\InvalidArgumentException $e) {
            throw $e;
        }
    }
public static function GCD($a, $b)
    {
        if ($a<0 || $b<0) {
            throw new \InvalidArgumentException('GCD calculation of negative numbers is not allowed!');
        }
        if ($b===0) {
            return $a;
        }
        try {
            list(, $r) = self::EuclideanDivision($a, $b);
            return self::GCD($b, $r);
        } catch (\InvalidArgumentException $e) {
            throw $e;
        }
    }
Find the "GCD" (greatest common divisor) using the Euclide's algorithm

@param $a
@param $b
@return int
@throws \InvalidArgumentException if $a or $b is negative