1010
1111/**
1212 * Exercise repository, use to locate individual/all exercises by certain criteria.
13+ *
14+ * @implements IteratorAggregate<int, ExerciseInterface>
1315 */
1416class ExerciseRepository implements IteratorAggregate, Countable
1517{
@@ -21,7 +23,7 @@ class ExerciseRepository implements IteratorAggregate, Countable
2123 /**
2224 * Requires an array of `ExerciseInterface` instances.
2325 *
24- * @param ExerciseInterface[] $exercises
26+ * @param array< ExerciseInterface> $exercises
2527 */
2628 public function __construct (array $ exercises )
2729 {
@@ -34,7 +36,7 @@ public function __construct(array $exercises)
3436 * @param ExerciseInterface $exercise
3537 * @return ExerciseInterface
3638 */
37- private function validateExercise (ExerciseInterface $ exercise )
39+ private function validateExercise (ExerciseInterface $ exercise ): ExerciseInterface
3840 {
3941 $ type = $ exercise ->getType ();
4042
@@ -50,9 +52,9 @@ private function validateExercise(ExerciseInterface $exercise)
5052 /**
5153 * Retrieve all of the exercises as an array.
5254 *
53- * @return ExerciseInterface[]
55+ * @return array< ExerciseInterface>
5456 */
55- public function findAll ()
57+ public function findAll (): array
5658 {
5759 return $ this ->exercises ;
5860 }
@@ -65,7 +67,7 @@ public function findAll()
6567 * @return ExerciseInterface
6668 * @throws InvalidArgumentException
6769 */
68- public function findByName ($ name )
70+ public function findByName (string $ name ): ExerciseInterface
6971 {
7072 foreach ($ this ->exercises as $ exercise ) {
7173 if ($ name === $ exercise ->getName ()) {
@@ -79,9 +81,9 @@ public function findByName($name)
7981 /**
8082 * Get the names of each exercise as an array.
8183 *
82- * @return array
84+ * @return array<string>
8385 */
84- public function getAllNames ()
86+ public function getAllNames (): array
8587 {
8688 return array_map (function (ExerciseInterface $ exercise ) {
8789 return $ exercise ->getName ();
@@ -93,17 +95,17 @@ public function getAllNames()
9395 *
9496 * @return int
9597 */
96- public function count ()
98+ public function count (): int
9799 {
98100 return count ($ this ->exercises );
99101 }
100102
101103 /**
102104 * Allow to iterate over the repository with `foreach`.
103105 *
104- * @return ArrayIterator
106+ * @return ArrayIterator<int, ExerciseInterface>
105107 */
106- public function getIterator ()
108+ public function getIterator (): ArrayIterator
107109 {
108110 return new ArrayIterator ($ this ->exercises );
109111 }
0 commit comments