private static function makeChainedSortFunction($fn1, $fn2)
    {
        if (!is_callable($fn2)) {
            return $fn1;
        }

        return function ($a, $b) use ($fn1, $fn2) {
            $comp = $fn1($a, $b);
            if ($comp !== 0) {
                return $comp;
            }
            return $fn2($a, $b);
        };
    }