File tree Expand file tree Collapse file tree 5 files changed +13
-12
lines changed Expand file tree Collapse file tree 5 files changed +13
-12
lines changed Original file line number Diff line number Diff line change 33namespace Guillermoandrae \Common ;
44
55use ArrayIterator ;
6- use JetBrains \PhpStorm \Pure ;
76
87abstract class AbstractAggregate implements AggregateInterface
98{
Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments