Laravel.io
    protected function getMinimumStayCustomPriceForGap(DateTime $date, $gap) {

        /** @var $a Doctrine_Collection */
        $a = $this->getPrice()->filter(function(Price $p) use ($date, $gap) {

            if ($p->amount > 0 && $p->type == Price::TYPE_CUSTOM && strtotime($p->start_date) <= $date->getTimestamp() && strtotime($p->end_date) > $date->getTimestamp()) {

                return true;
            }
            else {
                return false;
            }
        });

        $result = $a->getData();
        usort($result, function(Price $a, Price $b) use($date) {

            if($a == $b) {
                return 0;
            }
            else if($a->priority == $b->priority) {

                if($a->min_stay == $b->min_stay) {
                    return 0;
                }
                else if($a->min_stay != null && $b->min_stay == null) {
                    return -1;
                }
                else if($a->min_stay == null && $b->min_stay != null) {
                    return 1;
                }
                else if($a->min_stay < $b->min_stay) {
                    return -1;
                }
                else if($a->min_stay > $b->min_stay) {
                    return 1;
                }
                else {
                    return 0;
                }
            }
            else if($a->priority > $b->priority) {
                return -1;
            }
            else {
                return 1;
            }
        });

        $result = reset($result);
        $result = $result?$result:null;

        return $result;
    }

Please note that all pasted data is publicly available.