first() public method

Returns the first element from the array
public first ( ) : mixed
return mixed
 /**
  * @test Collection::first()
  */
 public function testFirst()
 {
     $this->buildEnvironment();
     $result = $this->collection->first();
     $expect = $this->source['a1'];
     $this->assertEquals($expect, $result);
 }
Example #2
0
 public static function _dumpCollection(Collection $collection)
 {
     if (is_object($collection->first()) and $collection->first() instanceof Model) {
         $output = "<span><strong>Collection of " . get_class($collection->first()) . " Models</strong></span>\n";
     } else {
         $output = "<span><strong>Collection object:</strong></span>\n";
     }
     foreach ($collection as $key => $value) {
         $output .= "  " . \Automatorm\Orm\Dump::format($key, $value);
     }
     return $output;
 }
 public function testPopPushPutShiftUnshiftInject()
 {
     // pop
     $_3 = $this->collection->pop();
     $this->assertEquals($this->_3, $_3);
     $this->assertEquals($this->_2, $this->collection->last());
     $this->assertEquals(3, $this->collection->count());
     // push
     $this->collection->push($_3);
     $this->assertEquals($this->_3, $this->collection->last());
     // put
     $this->collection->put(2, 'test');
     $this->assertEquals('test', $this->collection->get(2));
     // shift
     $_0 = $this->collection->shift();
     $this->assertEquals($this->_0, $_0);
     $this->assertEquals($this->_1, $this->collection->first());
     $this->assertEquals(3, $this->collection->count());
     // unshift
     $this->collection->unshift($_0);
     $this->assertEquals($this->_0, $this->collection->first());
     // inject
     $this->collection->inject(2, 'test2');
     $this->assertEquals('test2', $this->collection->get(2));
     $this->assertEquals(5, $this->collection->count());
 }
Example #4
0
 public function tags()
 {
     $collection = Collection::first();
     // Get all tags
     $tags = $collection->getTags();
     // Find how many are in the specified decks
     foreach ($tags as $tag) {
         $q = DB::table('cards')->select(DB::raw('count() as cards_count'), DB::raw('avg(ivl) as average_interval'))->join('notes', 'cards.nid', '=', 'notes.id')->where('tags', 'like', '%' . $tag . '%')->whereIn('did', $this->myDecks())->first();
         if ((int) $q->cards_count === 0) {
             continue;
         }
         $results[$tag] = ['tag' => $tag, 'count' => (int) $q->cards_count, 'value' => round($q->average_interval, 1)];
     }
     return Response::json($results);
 }
 /** {@inheritdoc} */
 public function first()
 {
     $this->initialize();
     return $this->coll->first();
 }
Example #6
0
 /**
  * Returns the first file of the Gist.
  *
  * @return GistFile
  */
 public function firstFile()
 {
     return $this->files->first();
 }
Example #7
0
 public function testFirst()
 {
     $el = $this->collection->first();
     $this->assertEquals($this->_0, $el);
 }
Example #8
0
 /**
  * Same as visibilityInfo, but for visibility collections
  */
 public static function visibilitiesColInfo(Collection $visibilities)
 {
     if ($visibilities->count() == 0) {
         return array('green', "Tout le monde");
     } elseif ($visibilities->count() == 1) {
         return self::visibilityInfo($visibilities->first());
     }
     $textes = array();
     foreach ($visibilities as $v) {
         list($color, $text) = self::visibilityInfo($v);
         $textes[] = $text;
     }
     return array('grey', implode(', ', $textes));
 }
 public function testFirst()
 {
     $collection = new Collection(['a' => 'c', 'b' => 'd']);
     $this->assertSame('c', $collection->first());
 }