/** * @param ExerciseInterface $exercise * @param EventDispatcher $eventDispatcher * @return ExerciseRunnerInterface */ public function create(ExerciseInterface $exercise, EventDispatcher $eventDispatcher) { switch ($exercise->getType()->getValue()) { case ExerciseType::CLI: return new CliRunner($exercise, $eventDispatcher); case ExerciseType::CGI: return new CgiRunner($exercise, $eventDispatcher); } throw new InvalidArgumentException(sprintf('Exercise Type: "%s" not supported', $exercise->getType()->getValue())); }
/** * @param ExerciseInterface $exercise * @return ExerciseInterface */ private function validateExercise(ExerciseInterface $exercise) { $type = $exercise->getType(); $requiredInterface = $type->getExerciseInterface(); if (!$exercise instanceof $requiredInterface) { throw InvalidArgumentException::missingImplements($exercise, $requiredInterface); } return $exercise; }
/** * Whether the factory supports this exercise type. * * @param ExerciseInterface $exercise * @return bool */ public function supports(ExerciseInterface $exercise) { return $exercise->getType()->getValue() === self::$type; }
/** * Static constructor to create an instance from the check & exercise. * * @param CheckInterface $check The check Instance. * @param ExerciseInterface $exercise The exercise Instance. * @return static */ public static function fromCheckAndExercise(CheckInterface $check, ExerciseInterface $exercise) { return new static(sprintf('Check: "%s" cannot process exercise: "%s" with type: "%s"', $check->getName(), $exercise->getName(), $exercise->getType())); }
/** * @param CheckInterface[] $checks * @param ExerciseInterface $exercise * @throws CheckNotApplicableException * @throws ExerciseNotConfiguredException */ private function validateChecks(array $checks, ExerciseInterface $exercise) { foreach ($checks as $check) { if (!$check->canRun($exercise->getType())) { throw CheckNotApplicableException::fromCheckAndExercise($check, $exercise); } $checkInterface = $check->getExerciseInterface(); if (!$exercise instanceof $checkInterface) { throw ExerciseNotConfiguredException::missingImplements($exercise, $checkInterface); } } }