Skip to content

Commit deeefdf

Browse files
Resolves #2.
1 parent 9a7e5f4 commit deeefdf

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

src/Common/AbstractAggregate.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Guillermoandrae\Common;
44

55
use ArrayIterator;
6-
use JetBrains\PhpStorm\Pure;
76

87
abstract class AbstractAggregate implements AggregateInterface
98
{

src/Common/Collection.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@ public function all(): array
2323
/**
2424
* {@inheritDoc}
2525
*/
26-
public function first()
26+
public function first(): mixed
2727
{
2828
return $this->items[0];
2929
}
3030

3131
/**
3232
* {@inheritDoc}
3333
*/
34-
public function last()
34+
public function last(): mixed
3535
{
36-
$count = count($this->items);
37-
return $this->items[$count-1];
36+
$key = array_key_last($this->items);
37+
return $this->items[$key];
3838
}
3939

4040
/**
4141
* {@inheritDoc}
4242
*/
43-
public function random()
43+
public function random(): mixed
4444
{
4545
$key = array_rand($this->items);
4646
return $this->get($key);

src/Common/CollectionInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ public function all(): array;
2424
*
2525
* @return mixed
2626
*/
27-
public function first();
27+
public function first(): mixed;
2828

2929
/**
3030
* Returns the last item in the collection.
3131
*
3232
* @return mixed
3333
*/
34-
public function last();
34+
public function last(): mixed;
3535

3636
/**
3737
* Returns a random item from the collection.
3838
*
3939
* @return mixed
4040
*/
41-
public function random();
41+
public function random(): mixed;
4242

4343
/**
4444
* Returns the number of items in the collection.

tests/Common/AggregateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class AggregateTest extends TestCase
1111
/**
1212
* @var AbstractAggregate
1313
*/
14-
protected $aggregate;
14+
protected AbstractAggregate $aggregate;
1515

1616
public function testSetAndGet()
1717
{

tests/Common/CollectionTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CollectionTest extends TestCase
1111
/**
1212
* @var array
1313
*/
14-
private $items = [
14+
private array $items = [
1515
['name' => 'Me', 'age' => 30],
1616
['name' => 'You', 'age' => 21],
1717
['name' => 'Her', 'age' => 28],
@@ -21,7 +21,7 @@ class CollectionTest extends TestCase
2121
/**
2222
* @var CollectionInterface
2323
*/
24-
private $collection;
24+
private CollectionInterface $collection;
2525

2626
public function testMake()
2727
{
@@ -43,6 +43,8 @@ public function testFirst()
4343
public function testLast()
4444
{
4545
$this->assertSame($this->items[3], $this->collection->last());
46+
$this->collection->set('test', 'last');
47+
$this->assertSame('last', $this->collection->last());
4648
}
4749

4850
public function testRandom()

0 commit comments

Comments
 (0)