I write function which gets one array from 3 elements (integer, numerator and denominator). It calculate wrong fractions to normal (numerator>denominator).

How optimize this function? I understand that I make many verification, but function looks ugly.

```
function calculate_measurement(array $m): array
        {
            if (isset($m[NUMERATOR]) && isset($m[DENOMINATOR])) {
                while (intval($m[NUMERATOR]) >= intval($m[DENOMINATOR])) {
                    $m[NUMERATOR] -= $m[DENOMINATOR];
                    if (!isset($m[INTEGER])) {
                        $m[INTEGER] = 0;
                    }
                    ++$m[INTEGER];
                }

                if (0 === $m[NUMERATOR]) {
                    $m[NUMERATOR] = null;
                    $m[DENOMINATOR] = null;
                }
            }

            return $m;
        }

```