Skip to content

Commit

Permalink
Not using self to instantiate collections in the trait
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Dec 26, 2013
1 parent 69b981d commit 21f2edb
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Cake/Utility/CollectionTrait.php
Expand Up @@ -14,6 +14,7 @@
*/
namespace Cake\Utility;

use Cake\Utility\Collection;
use Cake\Utility\Iterator\ExtractIterator;
use Cake\Utility\Iterator\FilterIterator;
use Cake\Utility\Iterator\ReplaceIterator;
Expand All @@ -22,6 +23,9 @@
use LimitIterator;


/**
* Offers a handful of method to manipulate iterators
*/
trait CollectionTrait {

/**
Expand Down Expand Up @@ -352,7 +356,7 @@ public function min($callback, $type = SORT_NUMERIC) {
* @return \Cake\Utility\Collection
*/
public function sortBy($callback, $dir = SORT_DESC, $type = SORT_NUMERIC) {
return new self(new SortIterator($this, $callback, $dir, $type));
return new Collection(new SortIterator($this, $callback, $dir, $type));
}

/**
Expand Down Expand Up @@ -402,7 +406,7 @@ public function groupBy($callback) {
foreach ($this as $value) {
$group[$callback($value)][] = $value;
}
return new self($group);
return new Collection($group);
}

/**
Expand Down Expand Up @@ -448,7 +452,7 @@ public function indexBy($callback) {
foreach ($this as $value) {
$group[$callback($value)] = $value;
}
return new self($group);
return new Collection($group);
}

/**
Expand Down Expand Up @@ -497,7 +501,7 @@ public function countBy($callback) {
$reducer = function ($key, $values, $mr) {
$mr->emit(count($values), $key);
};
return new self(new MapReduce($this, $mapper, $reducer));
return new Collection(new MapReduce($this, $mapper, $reducer));
}

/**
Expand All @@ -509,7 +513,7 @@ public function countBy($callback) {
public function shuffle() {
$elements = iterator_to_array($this);
shuffle($elements);
return new self($elements);
return new Collection($elements);
}

/**
Expand All @@ -521,7 +525,7 @@ public function shuffle() {
* @return \Cake\Utility\Collection
*/
public function sample($size = 10) {
return new self(new LimitIterator($this, 0, $size));
return new Collection(new LimitIterator($this, 0, $size));
}

/**
Expand Down Expand Up @@ -565,4 +569,3 @@ protected function _extract($data, $path) {
}

}

0 comments on commit 21f2edb

Please sign in to comment.