Skip to content

Commit 196885b

Browse files
committed
Merge pull request #109 from php-school/hotfix/custom-checks
Fix adding custom checks
2 parents 22a3af3 + 48c801b commit 196885b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Application.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ public function __construct($workshopTitle, $diConfigFile)
6666
}
6767

6868
/**
69-
* @param CheckInterface $check
69+
* @param string $check
7070
*/
71-
public function addCheck(CheckInterface $check)
71+
public function addCheck($check)
7272
{
7373
$this->checks[] = $check;
7474
}
7575

7676
/**
77-
* @param ExerciseInterface $exercise
77+
* @param string $exercise
7878
*/
7979
public function addExercise($exercise)
8080
{
@@ -141,9 +141,15 @@ public function run()
141141
}
142142

143143
$checkRepository = $container->get(CheckRepository::class);
144-
array_walk($this->checks, function (CheckInterface $check) use ($checkRepository) {
145-
$checkRepository->registerCheck($check);
146-
});
144+
foreach ($this->checks as $check) {
145+
if (false === $container->has($check)) {
146+
throw new \RuntimeException(
147+
sprintf('No DI config found for check: "%s". Register a factory.', $check)
148+
);
149+
}
150+
151+
$checkRepository->registerCheck($container->get($check));
152+
}
147153

148154
try {
149155
$exitCode = $container->get(CommandRouter::class)->route();

0 commit comments

Comments
 (0)