Aggregate Execute max|min

@param callable $cb
@param string   $type

@return number
554044
private function aggregate($type, $cb = null)
    {
        $data = [];

        $this->recursive(
            $this->storage,
            function ($value) use (& $data) {
                if (is_numeric($value)) {
                    $data[] = $value;
                }
            }
        );

        $r = call_user_func_array($type, $data);

        if (is_callable($cb)) {
            call_user_func_array($cb, [$r]);
        }

        return $r;
    }
1278182
public function average($callback = null)
    {
        if ($count = $this->count()) {
            return $this->sum($callback) / $count;
        }
    }
741234
protected function countJobsByType($type)
    {
        $minutes = $type === 'failed_jobs' ? $this->failedJobExpires : $this->recentJobExpires;

        return $this->connection()->zcount(
            $type, '-inf', Chronos::now()->subMinutes($minutes)->getTimestamp() * -1
        );
    }
681383
public function request($type, $data = null, $cb = null)
    {
        $packet = "\xFF\xFF\xFF\xFF";
        if ($type === 'ping') {
            $packet .= Pool::A2A_PING;
        } elseif ($type === 'challenge') {
            //$packet .= ValveClient::A2S_SERVERQUERY_GETCHALLENGE;
            $packet .= Pool::A2S_PLAYER . "\xFF\xFF\xFF\xFF";
        } elseif ($type === 'info') {
            $packet .= Pool::A2S_INFO . "Source Engine Query\x00";
            //"\xFF\xFF\xFF\xFFdetails\x00"
        } elseif ($type === 'players') {
            if ($data === null) {
                $data = "\xFF\xFF\xFF\xFF";
            }
            $packet .= Pool::A2S_PLAYER . $data;
        } else {
            return null;
        }
        $this->onResponse->push($cb);
        $this->setFree(false);
        //Daemon::log('packet: '.Debug::exportBytes($packet, true));
        $this->write($packet);
    }
868616
public function max($column, $alias)
    {
        return $this->addSelectColumn(new Func\Max(new Expr\Column($column)), $alias);
    }
981716
public static function limit($number, $min, $max): int
    {
        return self::max(self::min($number, $min), $max);
    }
1065763
public function min($column)
    {
        $this->compileWheres();
        $result = $this->query->min($column)
            ->getField($column)->rDefault(null)
            ->run();

        return $result;
    }
206873
public function fetchAll($type = parent::FETCH_TYPE_NUM)
    {
        return array_map($this->_callback, $this->_statement->fetchAll($type));
    }
577059
public static function instance($type)
    {
        if (!is_int($type)) {
            throw new \InvalidArgumentException(sprintf('Record type id must be an integer, %s given', gettype($type)));
        }

        // @codeCoverageIgnoreStart
        if (!self::$instances) {
            self::$instances = [
                self::BEGIN_REQUEST     => new self(self::BEGIN_REQUEST),
                self::ABORT_REQUEST     => new self(self::ABORT_REQUEST),
                self::END_REQUEST       => new self(self::END_REQUEST),
                self::PARAMS            => new self(self::PARAMS),
                self::STDIN             => new self(self::STDIN),
                self::STDOUT            => new self(self::STDOUT),
                self::STDERR            => new self(self::STDERR),
                self::DATA              => new self(self::DATA),
                self::GET_VALUES        => new self(self::GET_VALUES),
                self::GET_VALUES_RESULT => new self(self::GET_VALUES_RESULT),
                self::UNKNOWN_TYPE      => new self(self::UNKNOWN_TYPE),
            ];
        }
        // @codeCoverageIgnoreEnd

        if ($type >= self::MAXTYPE || $type <= 0) {
            $type = self::UNKNOWN_TYPE;
        }

        return self::$instances[$type];
    }
1024613
protected function getFirstGroup($type, $minLevel)
    {
        $i = $this->groupLevel;
        while ($i--) {
            $group = $this->groups[$i];

            if ($group->type === $type && $i >= $minLevel) {
                return $group;
            }
        }

        return null;
    }
927921
public function fetchAll($type = self::FETCH_TYPE_NUM)
    {
        if ($this->_allFetched) {
            return $this->buffer;
        }
        $results = $this->statement->fetchAll($type);
        if ($results !== false) {
            $this->buffer = array_merge($this->buffer, $results);
        }
        $this->_allFetched = true;
        $this->statement->closeCursor();

        return $this->buffer;
    }
720458
protected function readAllGenHandler($cb, $size, &$offset, &$pri, &$buf)
    {
        return function ($file, $data) use ($cb, $size, &$offset, &$pri, &$buf) {
            $buf .= $data;
            $offset += mb_orig_strlen($data);
            $len = min($file->chunkSize, $size - $offset);
            if ($offset >= $size) {
                if ($cb) {
                    $cb($file, $buf);
                }
                return;
            }
            eio_read($file->fd, $len, $offset, $pri, $this->readAllGenHandler($cb, $size, $offset, $pri, $buf), $this);
        };
    }
168797
public function max($attr)
    {
        $builder = $this->_makeBuilderForAggregations(" max($attr) ");
        return $this->_executeAndReturnFirst($builder, $this->_vals);
    }
839505
public function getMaxUnit($type, $qty, $fromUnit) {
        $units = $this->getUnitsByType($type);
        $fromUnitNdx = $this->findUnit($type, $fromUnit);
        $toUnitNdx = count($units);
        $currentUnit = $fromUnit;
        
        /* Convert up */
        for ($i = $fromUnitNdx; $i < $toUnitNdx - 1; $i++) {
            $tmp = $qty / $units[$i + 1]['ratio'];
            
            if (!is_int($tmp) && !is_float($tmp)){
                break;
            }
            $qty = $tmp;
            $currentUnit = $i + 1;
        }
        return array($qty, $units[$currentUnit]['aliases'][0]);
    }
833894
public function &getFirst($type) {

        foreach ($this->args as $key => &$d) {
            if ($this->_isType($d, $type)) {
                return $d;
            }
        }

        $args = func_get_args();
        if (count($args) > 1) {
            return $args[1];
        }

        $return = false;
        return $return;
    }
391524
public function min($alias, $field = null, $script = null)
    {
        $aggregation = new MinAggregation($alias, $field, $script);

        $this->append($aggregation);
    }
1369573
public function max($alias, $field = null, $script = null)
    {
        $aggregation = new MaxAggregation($alias, $field, $script);

        $this->append($aggregation);
    }