Skip to content

Commit

Permalink
Fixing style errors and removing superfluous $keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierumbelow committed Mar 5, 2019
1 parent 7b8e123 commit 34c2400
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1899,14 +1899,14 @@ public function count()
public function countBy($predicate = null)
{
if (is_null($predicate)) {
$predicate = function ($val, $key) {
$predicate = function ($val) {
return $val;
};
}

return new static(
$this->groupBy($predicate)
->map(function ($val, $key) {
->map(function ($val) {
return $val->count();
})
);
Expand Down
20 changes: 10 additions & 10 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,25 +309,25 @@ public function testCountable()

public function testCountableByWithoutPredicate()
{
$c = new Collection([ 'foo', 'foo', 'foo', 'bar', 'bar', 'foobar' ]);
$this->assertEquals([ 'foo' => 3, 'bar' => 2, 'foobar' => 1 ], $c->countBy()->all());
$c = new Collection(['foo', 'foo', 'foo', 'bar', 'bar', 'foobar']);
$this->assertEquals(['foo' => 3, 'bar' => 2, 'foobar' => 1], $c->countBy()->all());

$c = new Collection([ true, true, false, false, false ]);
$this->assertEquals([ true => 2, false => 3, ], $c->countBy()->all());
$c = new Collection([true, true, false, false, false]);
$this->assertEquals([true => 2, false => 3,], $c->countBy()->all());

$c = new Collection([ 1, 5, 1, 5, 5, 1 ]);
$this->assertEquals([ 1 => 3, 5 => 3, ], $c->countBy()->all());
$c = new Collection([1, 5, 1, 5, 5, 1]);
$this->assertEquals([1 => 3, 5 => 3,], $c->countBy()->all());
}

public function testCountableByWithPredicate()
{
$c = new Collection([ 'alice', 'aaron', 'bob', 'carla' ]);
$this->assertEquals([ 'a' => 2, 'b' => 1, 'c' => 1 ], $c->countBy(function ($name) {
$c = new Collection(['alice', 'aaron', 'bob', 'carla']);
$this->assertEquals(['a' => 2, 'b' => 1, 'c' => 1], $c->countBy(function ($name) {
return substr($name, 0, 1);
})->all());

$c = new Collection([ 1, 2, 3, 4, 5 ]);
$this->assertEquals([ true => 2, false => 3 ], $c->countBy(function ($i) {
$c = new Collection([1, 2, 3, 4, 5]);
$this->assertEquals([true => 2, false => 3], $c->countBy(function ($i) {
return $i % 2 === 0;
})->all());
}
Expand Down

0 comments on commit 34c2400

Please sign in to comment.