예제 #1
0
 /**
  * @dataProvider getTestCollectionData
  */
 public function testSetValueOnNullKey($item)
 {
     $collection = new Collection($item);
     /** @var $collection Collection */
     $this->assertEquals(2, $collection->count());
     $collection[] = 'foo';
     $this->assertEquals(3, $collection->count());
     // test finding next free numeric key
     $collection[] = 'foo';
     $this->assertEquals(4, $collection->count());
 }
예제 #2
0
 /**
  * Gets all but the last element or last n elements of collection.
  *
  * Returns mixed[]
  *
  * @param Collection $collection
  * @param int        $count
  * @return Collection
  */
 public function __invoke($collection, $count = 1)
 {
     $values = array_slice($collection->toArray(), 0, -$count);
     return $this->copyCollectionWith($collection, $values);
 }
예제 #3
0
 /**
  * Returns the smallest value in the collection.
  *
  * @param Collection $collection
  * @return mixed
  */
 public function __invoke(Collection $collection)
 {
     return min($collection->toArray());
 }
예제 #4
0
 /**
  * Shuffles the values of a collection while preserving the keys.
  *
  * @param Collection $collection
  * @return Collection
  */
 public function __invoke($collection)
 {
     $values = $this->shuffleAssoc($collection->toArray());
     return $this->copyCollectionWith($collection, $values);
 }
예제 #5
0
 /**
  * Allows applying some operator to entire collection at once and returning it's result
  *
  * @param Collection $collection
  * @param callable   $iterator
  * @return Collection
  */
 public function __invoke($collection, $iterator)
 {
     $values = call_user_func($iterator, $collection->toArray());
     return $this->copyCollectionWith($collection, $values);
 }
예제 #6
0
 /**
  * Returns the key of the given value, in the last possible position.
  *
  * @param Collection $collection
  * @return mixed
  */
 public function __invoke(Collection $collection, $value)
 {
     $values = array_reverse($collection->toArray(), true);
     return array_search($value, $values, true);
 }
예제 #7
0
 /**
  * Gets the size of the collection by returning length for arrays or number of enumerable properties for objects.
  *
  * @param Collection $collection
  * @return int
  */
 public function __invoke(Collection $collection)
 {
     return $collection->count();
 }
예제 #8
0
 /**
  * Creates an collection composed of the enumerable property values of object.
  *
  * @param Collection $collection
  * @return Collection
  */
 public function __invoke($collection)
 {
     $values = array_values($collection->toArray());
     return $this->copyCollectionWith($collection, $values);
 }
예제 #9
0
 /**
  * Invokes $callback with the wrapped value of collection as the first argument
  * and then wraps it back.
  *
  * The purpose of this Mutator
  * is to "tap into" a Mutator
  * chain in order to
  * perform operations on intermediate results within the chain.
  *
  * @param Collection $collection
  * @param callable   $iterator
  * @return Collection
  */
 public function __invoke($collection, $iterator)
 {
     call_user_func($iterator, $collection->toArray());
     return $collection;
 }
예제 #10
0
 /**
  * Determine if the given key exists in the collection.
  *
  * @param Collection $collection
  * @param string     $key
  * @return mixed
  */
 public function __invoke(Collection $collection, $key)
 {
     return $collection->offsetExists($key);
 }
예제 #11
0
 /**
  * Returns wrapped object
  *
  * @param Collection $collection
  * @return mixed
  */
 public function __invoke(Collection $collection)
 {
     return $collection->value();
 }