FOF30\Model\DataModel\Collection::min PHP Метод

min() публичный Метод

Get the min value of a given key.
public min ( string $key ) : mixed
$key string
Результат mixed
    public function min($key)
    {
        return $this->reduce(function ($result, $item) use($key) {
            return is_null($result) || $item->{$key} < $result ? $item->{$key} : $result;
        });
    }

Usage Example

Пример #1
0
 /**
  * @group           DataModel
  * @group           CollectionMin
  * @covers          FOF30\Model\DataModel\Collection::min
  */
 public function testMin()
 {
     $items = $this->buildCollection();
     $collection = new Collection($items);
     $result = $collection->min('foftest_bare_id');
     // Let's get the maximum value directly from the db
     $db = \JFactory::getDbo();
     $query = $db->getQuery(true)->select('MIN(foftest_bare_id)')->from('#__foftest_bares');
     $min = $db->setQuery($query)->loadResult();
     $this->assertEquals($min, $result, 'Collection::min Failed to return lowest value');
 }