From 44da484ad081e58ea2d3814fbb417c4af4c73ff6 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Sat, 24 Oct 2020 21:46:33 +0100 Subject: [PATCH] More type coverage --- src/Check/ComposerCheck.php | 1 - src/Check/DatabaseCheck.php | 8 +++---- src/Check/FunctionRequirementsCheck.php | 1 - src/Check/PhpLintCheck.php | 1 - src/Command/HelpCommand.php | 10 ++++---- src/Command/MenuCommand.php | 2 +- src/Command/PrintCommand.php | 16 ++++++------- src/Command/RunCommand.php | 12 +++++----- src/Command/VerifyCommand.php | 16 ++++++------- src/CommandArgument.php | 10 ++++---- src/CommandDefinition.php | 16 ++++++------- src/CommandRouter.php | 2 +- src/Event/ContainerListenerHelper.php | 6 ++--- src/Event/functions.php | 2 +- src/Exception/CheckNotApplicableException.php | 2 +- src/Exception/CliRouteNotExistsException.php | 2 +- src/Exception/CodeExecutionException.php | 2 +- .../ExerciseNotConfiguredException.php | 2 +- src/Exercise/CgiExercise.php | 4 ++-- src/Exercise/CliExercise.php | 4 ++-- src/Exercise/CustomVerifyingExercise.php | 2 +- src/Exercise/SubmissionPatchable.php | 2 +- src/ExerciseCheck/DatabaseExerciseCheck.php | 4 ++-- .../FunctionRequirementsExerciseCheck.php | 8 +++---- src/ExerciseCheck/SelfCheck.php | 2 +- src/ExerciseDispatcher.php | 4 ++-- src/ExerciseRenderer.php | 24 +++++++++---------- src/ExerciseRepository.php | 2 +- .../Factory/CgiRunnerFactory.php | 1 + src/ExerciseRunner/RunnerManager.php | 2 +- src/Factory/MarkdownCliRendererFactory.php | 2 +- src/Factory/MenuFactory.php | 10 ++++---- src/Listener/PrepareSolutionListener.php | 2 +- src/MarkdownRenderer.php | 2 +- src/NodeVisitor/FunctionVisitor.php | 5 ++-- src/Result/Cgi/GenericFailure.php | 12 ++++++---- src/Result/Cgi/ResultInterface.php | 2 +- src/Result/Cgi/Success.php | 4 ++-- src/Result/Cli/CliResult.php | 2 +- src/Result/Cli/GenericFailure.php | 4 ++-- src/Result/ComparisonFailure.php | 14 +++++------ src/Result/Failure.php | 6 ++--- src/Result/ResultGroupInterface.php | 6 ++--- src/Result/ResultInterface.php | 2 +- src/Result/ResultTrait.php | 2 +- src/Result/Success.php | 2 +- .../Cli/RequestFailureRenderer.php | 4 ++-- .../ComparisonFailureRenderer.php | 4 ++-- .../FunctionRequirementsFailureRenderer.php | 2 +- .../ResultRendererInterface.php | 2 +- src/ResultRenderer/ResultsRenderer.php | 12 +++++----- src/Solution/DirectorySolution.php | 2 +- src/UserStateSerializer.php | 9 ++++--- src/Utils/RequestRenderer.php | 2 +- test/Check/DatabaseCheckTest.php | 5 +++- 55 files changed, 147 insertions(+), 142 deletions(-) diff --git a/src/Check/ComposerCheck.php b/src/Check/ComposerCheck.php index e724c938..73d4691c 100644 --- a/src/Check/ComposerCheck.php +++ b/src/Check/ComposerCheck.php @@ -17,7 +17,6 @@ */ class ComposerCheck implements SimpleCheckInterface { - /** * Return the check's name */ diff --git a/src/Check/DatabaseCheck.php b/src/Check/DatabaseCheck.php index d0c79e59..d7e18ae6 100644 --- a/src/Check/DatabaseCheck.php +++ b/src/Check/DatabaseCheck.php @@ -51,11 +51,11 @@ class DatabaseCheck implements ListenableCheckInterface */ public function __construct() { - $this->databaseDirectory = $this->getTemporaryPath(); - $this->userDatabasePath = sprintf('%s/user-db.sqlite', $this->databaseDirectory); + $this->databaseDirectory = $this->getTemporaryPath(); + $this->userDatabasePath = sprintf('%s/user-db.sqlite', $this->databaseDirectory); $this->solutionDatabasePath = sprintf('%s/solution-db.sqlite', $this->databaseDirectory); - $this->solutionDsn = sprintf('sqlite:%s', $this->solutionDatabasePath); - $this->userDsn = sprintf('sqlite:%s', $this->userDatabasePath); + $this->solutionDsn = sprintf('sqlite:%s', $this->solutionDatabasePath); + $this->userDsn = sprintf('sqlite:%s', $this->userDatabasePath); } /** diff --git a/src/Check/FunctionRequirementsCheck.php b/src/Check/FunctionRequirementsCheck.php index e275daff..9446a5a2 100644 --- a/src/Check/FunctionRequirementsCheck.php +++ b/src/Check/FunctionRequirementsCheck.php @@ -24,7 +24,6 @@ */ class FunctionRequirementsCheck implements SimpleCheckInterface { - /** * @var Parser */ diff --git a/src/Check/PhpLintCheck.php b/src/Check/PhpLintCheck.php index 2ddf0613..e6cc6ed3 100644 --- a/src/Check/PhpLintCheck.php +++ b/src/Check/PhpLintCheck.php @@ -16,7 +16,6 @@ */ class PhpLintCheck implements SimpleCheckInterface { - /** * Return the check's name */ diff --git a/src/Command/HelpCommand.php b/src/Command/HelpCommand.php index 646c30e4..11756c37 100644 --- a/src/Command/HelpCommand.php +++ b/src/Command/HelpCommand.php @@ -31,17 +31,17 @@ class HelpCommand * @param OutputInterface $output * @param Color $color */ - public function __construct($appName, OutputInterface $output, Color $color) + public function __construct(string $appName, OutputInterface $output, Color $color) { - $this->output = $output; - $this->color = $color; - $this->appName = $appName; + $this->output = $output; + $this->color = $color; + $this->appName = $appName; } /** * @return void */ - public function __invoke() + public function __invoke(): void { $this->output->writeLine($this->color->__invoke('Usage')->yellow()->bold()); $this->output->writeLine(""); diff --git a/src/Command/MenuCommand.php b/src/Command/MenuCommand.php index c64a3762..b925c912 100644 --- a/src/Command/MenuCommand.php +++ b/src/Command/MenuCommand.php @@ -25,7 +25,7 @@ public function __construct(CliMenu $menu) /** * @return void */ - public function __invoke() + public function __invoke(): void { $this->menu->open(); } diff --git a/src/Command/PrintCommand.php b/src/Command/PrintCommand.php index c6b62447..9850e3f1 100644 --- a/src/Command/PrintCommand.php +++ b/src/Command/PrintCommand.php @@ -46,23 +46,23 @@ class PrintCommand * @param OutputInterface $output */ public function __construct( - $appName, + string $appName, ExerciseRepository $exerciseRepository, UserState $userState, MarkdownRenderer $markdownRenderer, OutputInterface $output ) { - $this->appName = $appName; - $this->markdownRenderer = $markdownRenderer; - $this->output = $output; - $this->userState = $userState; - $this->exerciseRepository = $exerciseRepository; + $this->appName = $appName; + $this->markdownRenderer = $markdownRenderer; + $this->output = $output; + $this->userState = $userState; + $this->exerciseRepository = $exerciseRepository; } /** - * @return int|void + * @return void */ - public function __invoke() + public function __invoke(): void { $currentExercise = $this->userState->getCurrentExercise(); $exercise = $this->exerciseRepository->findByName($currentExercise); diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php index 4ab3262a..ccbfc7e3 100644 --- a/src/Command/RunCommand.php +++ b/src/Command/RunCommand.php @@ -45,18 +45,18 @@ public function __construct( UserState $userState, OutputInterface $output ) { - $this->output = $output; - $this->exerciseRepository = $exerciseRepository; - $this->userState = $userState; - $this->exerciseDispatcher = $exerciseDispatcher; + $this->output = $output; + $this->exerciseRepository = $exerciseRepository; + $this->userState = $userState; + $this->exerciseDispatcher = $exerciseDispatcher; } /** * @param Input $input The command line arguments passed to the command. * - * @return int|void + * @return void */ - public function __invoke(Input $input) + public function __invoke(Input $input): void { $exercise = $this->exerciseRepository->findByName($this->userState->getCurrentExercise()); $this->exerciseDispatcher->run($exercise, $input, $this->output); diff --git a/src/Command/VerifyCommand.php b/src/Command/VerifyCommand.php index e233de4c..d939c210 100644 --- a/src/Command/VerifyCommand.php +++ b/src/Command/VerifyCommand.php @@ -62,20 +62,20 @@ public function __construct( OutputInterface $output, ResultsRenderer $resultsRenderer ) { - $this->output = $output; - $this->exerciseRepository = $exerciseRepository; - $this->userState = $userState; - $this->userStateSerializer = $userStateSerializer; - $this->resultsRenderer = $resultsRenderer; - $this->exerciseDispatcher = $exerciseDispatcher; + $this->output = $output; + $this->exerciseRepository = $exerciseRepository; + $this->userState = $userState; + $this->userStateSerializer = $userStateSerializer; + $this->resultsRenderer = $resultsRenderer; + $this->exerciseDispatcher = $exerciseDispatcher; } /** * @param Input $input The command line arguments passed to the command. * - * @return int|void + * @return int */ - public function __invoke(Input $input) + public function __invoke(Input $input): int { $exercise = $this->exerciseRepository->findByName($this->userState->getCurrentExercise()); $results = $this->exerciseDispatcher->verify($exercise, $input); diff --git a/src/CommandArgument.php b/src/CommandArgument.php index 2c69f85d..3db84e1c 100644 --- a/src/CommandArgument.php +++ b/src/CommandArgument.php @@ -31,7 +31,7 @@ public function __construct(string $name, bool $optional = false) * @param string $name * @return self */ - public static function optional($name) + public static function optional(string $name): self { return new self($name, true); } @@ -40,7 +40,7 @@ public static function optional($name) * @param string $name * @return self */ - public static function required($name) + public static function required(string $name): self { return new self($name); } @@ -48,7 +48,7 @@ public static function required($name) /** * @return string */ - public function getName() + public function getName(): string { return $this->name; } @@ -56,7 +56,7 @@ public function getName() /** * @return bool */ - public function isRequired() + public function isRequired(): bool { return !$this->isOptional(); } @@ -64,7 +64,7 @@ public function isRequired() /** * @return bool */ - public function isOptional() + public function isOptional(): bool { return $this->optional; } diff --git a/src/CommandDefinition.php b/src/CommandDefinition.php index 923bc4b1..b46b07e5 100644 --- a/src/CommandDefinition.php +++ b/src/CommandDefinition.php @@ -17,7 +17,7 @@ class CommandDefinition private $name; /** - * @var CommandArgument[] + * @var array */ private $args = []; @@ -31,10 +31,10 @@ class CommandDefinition * @param string[]|CommandArgument[] $args A list of arguments. Must be an array of strings or `CommandArgument`'s. * @param string|callable $commandCallable The name of a callable container entry or an actual PHP callable. */ - public function __construct($name, array $args, $commandCallable) + public function __construct(string $name, array $args, $commandCallable) { - $this->name = $name; - $this->commandCallable = $commandCallable; + $this->name = $name; + $this->commandCallable = $commandCallable; array_walk($args, function ($arg) { $this->addArgument($arg); @@ -45,7 +45,7 @@ public function __construct($name, array $args, $commandCallable) * @param string|CommandArgument $argument * @return $this */ - public function addArgument($argument) + public function addArgument($argument): self { if (!is_string($argument) && !$argument instanceof CommandArgument) { throw InvalidArgumentException::notValidParameter( @@ -80,7 +80,7 @@ public function addArgument($argument) * * @return string */ - public function getName() + public function getName(): string { return $this->name; } @@ -88,9 +88,9 @@ public function getName() /** * Get the list of required arguments. * - * @return CommandArgument[] + * @return array */ - public function getRequiredArgs() + public function getRequiredArgs(): array { return $this->args; } diff --git a/src/CommandRouter.php b/src/CommandRouter.php index 15d65357..469c6db8 100644 --- a/src/CommandRouter.php +++ b/src/CommandRouter.php @@ -218,7 +218,7 @@ private function resolveCallable(CommandDefinition $command, Input $input): int * @param Input $input * @return ?int */ - private function callCommand(CommandDefinition $command, callable $callable, Input $input) + private function callCommand(CommandDefinition $command, callable $callable, Input $input): ?int { $this->eventDispatcher->dispatch(new Event\Event('route.pre.invoke')); $this->eventDispatcher->dispatch(new Event\Event(sprintf('route.pre.invoke.%s', $command->getName()))); diff --git a/src/Event/ContainerListenerHelper.php b/src/Event/ContainerListenerHelper.php index 7ee2614d..35a2594b 100644 --- a/src/Event/ContainerListenerHelper.php +++ b/src/Event/ContainerListenerHelper.php @@ -21,7 +21,7 @@ class ContainerListenerHelper * @param string $service * @param string $method */ - public function __construct($service, $method = '__invoke') + public function __construct(string $service, string $method = '__invoke') { $this->service = $service; $this->method = $method; @@ -30,7 +30,7 @@ public function __construct($service, $method = '__invoke') /** * @return string */ - public function getService() + public function getService(): string { return $this->service; } @@ -38,7 +38,7 @@ public function getService() /** * @return string */ - public function getMethod() + public function getMethod(): string { return $this->method; } diff --git a/src/Event/functions.php b/src/Event/functions.php index 878d8e12..62b8bfbe 100644 --- a/src/Event/functions.php +++ b/src/Event/functions.php @@ -9,7 +9,7 @@ * @param string $method * @return ContainerListenerHelper */ - function containerListener($service, $method = '__invoke') + function containerListener(string $service, string $method = '__invoke') { return new ContainerListenerHelper($service, $method); } diff --git a/src/Exception/CheckNotApplicableException.php b/src/Exception/CheckNotApplicableException.php index 7606cf9d..0f93fe51 100644 --- a/src/Exception/CheckNotApplicableException.php +++ b/src/Exception/CheckNotApplicableException.php @@ -19,7 +19,7 @@ class CheckNotApplicableException extends RuntimeException * @param ExerciseInterface $exercise The exercise Instance. * @return self */ - public static function fromCheckAndExercise(CheckInterface $check, ExerciseInterface $exercise) + public static function fromCheckAndExercise(CheckInterface $check, ExerciseInterface $exercise): self { return new self( sprintf( diff --git a/src/Exception/CliRouteNotExistsException.php b/src/Exception/CliRouteNotExistsException.php index 08e13ddd..494293cd 100644 --- a/src/Exception/CliRouteNotExistsException.php +++ b/src/Exception/CliRouteNotExistsException.php @@ -12,7 +12,7 @@ class CliRouteNotExistsException extends RuntimeException /** * @param string $routeName The name of the command which was typed. */ - public function __construct($routeName) + public function __construct(string $routeName) { parent::__construct(sprintf('Command: "%s" does not exist', $routeName)); } diff --git a/src/Exception/CodeExecutionException.php b/src/Exception/CodeExecutionException.php index 758d8000..ea6cc45b 100644 --- a/src/Exception/CodeExecutionException.php +++ b/src/Exception/CodeExecutionException.php @@ -16,7 +16,7 @@ class CodeExecutionException extends RuntimeException * @param Process $process The `Symfony\Component\Process\Process` instance which failed. * @return self */ - public static function fromProcess(Process $process) + public static function fromProcess(Process $process): self { return new self( sprintf( diff --git a/src/Exception/ExerciseNotConfiguredException.php b/src/Exception/ExerciseNotConfiguredException.php index 533a7eb3..f3163d03 100644 --- a/src/Exception/ExerciseNotConfiguredException.php +++ b/src/Exception/ExerciseNotConfiguredException.php @@ -18,7 +18,7 @@ class ExerciseNotConfiguredException extends RuntimeException * @param string $interface The FQCN of the interface. * @return self */ - public static function missingImplements(ExerciseInterface $exercise, $interface) + public static function missingImplements(ExerciseInterface $exercise, string $interface): self { return new self(sprintf('Exercise: "%s" should implement interface: "%s"', $exercise->getName(), $interface)); } diff --git a/src/Exercise/CgiExercise.php b/src/Exercise/CgiExercise.php index 44ac2438..0cbe1152 100644 --- a/src/Exercise/CgiExercise.php +++ b/src/Exercise/CgiExercise.php @@ -13,7 +13,7 @@ interface CgiExercise extends ProvidesSolution * This method should return an array of PSR-7 requests, which will be forwarded to the student's * solution. * - * @return RequestInterface[] An array of PSR-7 requests. + * @return array An array of PSR-7 requests. */ - public function getRequests(); + public function getRequests(): array; } diff --git a/src/Exercise/CliExercise.php b/src/Exercise/CliExercise.php index 1391f2d3..b7edf9da 100644 --- a/src/Exercise/CliExercise.php +++ b/src/Exercise/CliExercise.php @@ -11,7 +11,7 @@ interface CliExercise extends ProvidesSolution * This method should return an array of an array of strings. * Each set of arguments will be passed to the students solution as command line arguments. * - * @return string[][] An array of string arguments. + * @return array> An array of string arguments. */ - public function getArgs(); + public function getArgs(): array; } diff --git a/src/Exercise/CustomVerifyingExercise.php b/src/Exercise/CustomVerifyingExercise.php index 4d31475e..bd5580db 100644 --- a/src/Exercise/CustomVerifyingExercise.php +++ b/src/Exercise/CustomVerifyingExercise.php @@ -12,5 +12,5 @@ interface CustomVerifyingExercise /** * @return ResultInterface */ - public function verify(); + public function verify(): ResultInterface; } diff --git a/src/Exercise/SubmissionPatchable.php b/src/Exercise/SubmissionPatchable.php index 50833043..de3ce70b 100644 --- a/src/Exercise/SubmissionPatchable.php +++ b/src/Exercise/SubmissionPatchable.php @@ -18,5 +18,5 @@ interface SubmissionPatchable * * @return Patch */ - public function getPatch(); + public function getPatch(): Patch; } diff --git a/src/ExerciseCheck/DatabaseExerciseCheck.php b/src/ExerciseCheck/DatabaseExerciseCheck.php index 0ab25e7b..1c99de88 100644 --- a/src/ExerciseCheck/DatabaseExerciseCheck.php +++ b/src/ExerciseCheck/DatabaseExerciseCheck.php @@ -17,7 +17,7 @@ interface DatabaseExerciseCheck * @param PDO $db A `PDO` instance pointing to the database which will be accessible to the student's solution. * @return void */ - public function seed(PDO $db); + public function seed(PDO $db): void; /** * This method allows your exercise to verify the state of database *after* the student's solution has been @@ -28,5 +28,5 @@ public function seed(PDO $db); * @param PDO $db A `PDO` instance pointing to the database which was accessible by the student's solution. * @return bool The result of the verification. */ - public function verify(PDO $db); + public function verify(PDO $db): bool; } diff --git a/src/ExerciseCheck/FunctionRequirementsExerciseCheck.php b/src/ExerciseCheck/FunctionRequirementsExerciseCheck.php index 2641b2f3..85570f52 100644 --- a/src/ExerciseCheck/FunctionRequirementsExerciseCheck.php +++ b/src/ExerciseCheck/FunctionRequirementsExerciseCheck.php @@ -12,15 +12,15 @@ interface FunctionRequirementsExerciseCheck * Returns an array of function names that the student's solution should use. The solution * will be parsed and checked for usages of these functions. * - * @return string[] An array of function names that *should* be used. + * @return array An array of function names that *should* be used. */ - public function getRequiredFunctions(); + public function getRequiredFunctions(): array; /** * Returns an array of function names that the student's solution should not use. The solution * will be parsed and checked for usages of these functions. * - * @return string[] An array of function names that *should not* be used. + * @return array An array of function names that *should not* be used. */ - public function getBannedFunctions(); + public function getBannedFunctions(): array; } diff --git a/src/ExerciseCheck/SelfCheck.php b/src/ExerciseCheck/SelfCheck.php index 19dc8b14..a98bb08e 100644 --- a/src/ExerciseCheck/SelfCheck.php +++ b/src/ExerciseCheck/SelfCheck.php @@ -22,5 +22,5 @@ interface SelfCheck * @param Input $input The command line arguments passed to the command. * @return ResultInterface The result of the check. */ - public function check(Input $input); + public function check(Input $input): ResultInterface; } diff --git a/src/ExerciseDispatcher.php b/src/ExerciseDispatcher.php index 77292b37..b4dfc05f 100644 --- a/src/ExerciseDispatcher.php +++ b/src/ExerciseDispatcher.php @@ -24,12 +24,12 @@ class ExerciseDispatcher { /** - * @var SimpleCheckInterface[] + * @var array */ private $checksToRunBefore = []; /** - * @var SimpleCheckInterface[] + * @var array */ private $checksToRunAfter = []; diff --git a/src/ExerciseRenderer.php b/src/ExerciseRenderer.php index ba1c75f5..20690d27 100644 --- a/src/ExerciseRenderer.php +++ b/src/ExerciseRenderer.php @@ -65,13 +65,13 @@ public function __construct( Color $color, OutputInterface $output ) { - $this->appName = $appName; - $this->exerciseRepository = $exerciseRepository; - $this->markdownRenderer = $markdownRenderer; - $this->color = $color; - $this->output = $output; - $this->userState = $userState; - $this->userStateSerializer = $userStateSerializer; + $this->appName = $appName; + $this->exerciseRepository = $exerciseRepository; + $this->markdownRenderer = $markdownRenderer; + $this->color = $color; + $this->output = $output; + $this->userState = $userState; + $this->userStateSerializer = $userStateSerializer; } /** @@ -81,15 +81,15 @@ public function __invoke(CliMenu $menu): void { $menu->close(); - $item = $menu->getSelectedItem(); - $exercise = $this->exerciseRepository->findByName($item->getText()); - $exercises = $this->exerciseRepository->findAll(); + $item = $menu->getSelectedItem(); + $exercise = $this->exerciseRepository->findByName($item->getText()); + $exercises = $this->exerciseRepository->findAll(); $this->userState->setCurrentExercise($item->getText()); $this->userStateSerializer->serialize($this->userState); - $numExercises = count($exercises); - $exerciseIndex = ((int) array_search($exercise, $exercises)) + 1; + $numExercises = count($exercises); + $exerciseIndex = ((int) array_search($exercise, $exercises)) + 1; $output = "\n"; $output .= $this->color->__invoke(' LEARN YOU THE PHP FOR MUCH WIN! ')->magenta()->bold() . "\n"; diff --git a/src/ExerciseRepository.php b/src/ExerciseRepository.php index 4438d82e..56fabf74 100644 --- a/src/ExerciseRepository.php +++ b/src/ExerciseRepository.php @@ -16,7 +16,7 @@ class ExerciseRepository implements IteratorAggregate, Countable { /** - * @var ExerciseInterface[] + * @var array */ private $exercises; diff --git a/src/ExerciseRunner/Factory/CgiRunnerFactory.php b/src/ExerciseRunner/Factory/CgiRunnerFactory.php index 56a8a50d..7b574895 100644 --- a/src/ExerciseRunner/Factory/CgiRunnerFactory.php +++ b/src/ExerciseRunner/Factory/CgiRunnerFactory.php @@ -34,6 +34,7 @@ class CgiRunnerFactory implements ExerciseRunnerFactoryInterface /** * @param EventDispatcher $eventDispatcher + * @param RequestRenderer $requestRenderer */ public function __construct(EventDispatcher $eventDispatcher, RequestRenderer $requestRenderer) { diff --git a/src/ExerciseRunner/RunnerManager.php b/src/ExerciseRunner/RunnerManager.php index 9596dfd0..1dbaf025 100644 --- a/src/ExerciseRunner/RunnerManager.php +++ b/src/ExerciseRunner/RunnerManager.php @@ -13,7 +13,7 @@ class RunnerManager { /** - * @var ExerciseRunnerFactoryInterface[] + * @var array */ private $factories = []; diff --git a/src/Factory/MarkdownCliRendererFactory.php b/src/Factory/MarkdownCliRendererFactory.php index a1521737..7a3e8b32 100644 --- a/src/Factory/MarkdownCliRendererFactory.php +++ b/src/Factory/MarkdownCliRendererFactory.php @@ -44,7 +44,7 @@ class MarkdownCliRendererFactory * @param ContainerInterface $c * @return CliRenderer */ - public function __invoke(ContainerInterface $c) + public function __invoke(ContainerInterface $c): CliRenderer { $terminal = $c->get(Terminal::class); diff --git a/src/Factory/MenuFactory.php b/src/Factory/MenuFactory.php index e684816d..91fd1a6e 100644 --- a/src/Factory/MenuFactory.php +++ b/src/Factory/MenuFactory.php @@ -31,7 +31,7 @@ class MenuFactory * @param ContainerInterface $c * @return CliMenu */ - public function __invoke(ContainerInterface $c) + public function __invoke(ContainerInterface $c): CliMenu { $userStateSerializer = $c->get(UserStateSerializer::class); $exerciseRepository = $c->get(ExerciseRepository::class); @@ -116,11 +116,11 @@ function (CliMenu $menu) use ($exerciseRenderer, $eventDispatcher, $exercise) { /** * @param ExerciseInterface $exercise - * @param UserState $userState - * @param WorkshopType $type + * @param UserState $userState + * @param WorkshopType $type * @return bool */ - private function isExerciseDisabled(ExerciseInterface $exercise, UserState $userState, WorkshopType $type) + private function isExerciseDisabled(ExerciseInterface $exercise, UserState $userState, WorkshopType $type): bool { static $previous = null; @@ -129,7 +129,7 @@ private function isExerciseDisabled(ExerciseInterface $exercise, UserState $user return false; } - if (in_array($previous->getName(), $userState->getCompletedExercises())) { + if (in_array($previous->getName(), $userState->getCompletedExercises(), true)) { $previous = $exercise; return false; } diff --git a/src/Listener/PrepareSolutionListener.php b/src/Listener/PrepareSolutionListener.php index 0095fa4f..16c77f1e 100644 --- a/src/Listener/PrepareSolutionListener.php +++ b/src/Listener/PrepareSolutionListener.php @@ -54,7 +54,7 @@ public function __invoke(ExerciseRunnerEvent $event): void /** * @return string */ - private function locateComposer() + private function locateComposer(): string { foreach ($this->composerLocations as $location) { if (file_exists($location) && is_executable($location)) { diff --git a/src/MarkdownRenderer.php b/src/MarkdownRenderer.php index 238e14c9..2529cde3 100644 --- a/src/MarkdownRenderer.php +++ b/src/MarkdownRenderer.php @@ -41,7 +41,7 @@ public function __construct(DocParser $docParser, CliRenderer $cliRenderer) * @param string $markdown * @return string */ - public function render($markdown) + public function render(string $markdown): string { $ast = $this->docParser->parse($markdown); return $this->cliRenderer->renderBlock($ast); diff --git a/src/NodeVisitor/FunctionVisitor.php b/src/NodeVisitor/FunctionVisitor.php index 6db8540d..5661b3c6 100644 --- a/src/NodeVisitor/FunctionVisitor.php +++ b/src/NodeVisitor/FunctionVisitor.php @@ -36,13 +36,12 @@ class FunctionVisitor extends NodeVisitorAbstract */ public function __construct(array $requiredFunctions, array $bannedFunctions) { - $this->requiredFunctions = $requiredFunctions; - $this->bannedFunctions = $bannedFunctions; + $this->requiredFunctions = $requiredFunctions; + $this->bannedFunctions = $bannedFunctions; } /** * @param Node $node - * @return null */ public function leaveNode(Node $node) { diff --git a/src/Result/Cgi/GenericFailure.php b/src/Result/Cgi/GenericFailure.php index b8353f9e..52cf42fb 100644 --- a/src/Result/Cgi/GenericFailure.php +++ b/src/Result/Cgi/GenericFailure.php @@ -26,7 +26,7 @@ class GenericFailure extends Failure implements FailureInterface * @param RequestInterface $request The request that caused the failure. * @param string|null $reason */ - public function __construct(RequestInterface $request, $reason = null) + public function __construct(RequestInterface $request, string $reason = null) { $this->request = $request; parent::__construct(static::$name, $reason); @@ -39,7 +39,7 @@ public function __construct(RequestInterface $request, $reason = null) * @param string|null $reason The reason (if any) of the failure. * @return self The result. */ - public static function fromRequestAndReason(RequestInterface $request, $reason) + public static function fromRequestAndReason(RequestInterface $request, string $reason = null): self { return new self($request, $reason); } @@ -51,8 +51,10 @@ public static function fromRequestAndReason(RequestInterface $request, $reason) * @param CodeExecutionException $e The exception. * @return self The result. */ - public static function fromRequestAndCodeExecutionFailure(RequestInterface $request, CodeExecutionException $e) - { + public static function fromRequestAndCodeExecutionFailure( + RequestInterface $request, + CodeExecutionException $e + ): self { return new self($request, $e->getMessage()); } @@ -61,7 +63,7 @@ public static function fromRequestAndCodeExecutionFailure(RequestInterface $requ * * @return RequestInterface */ - public function getRequest() + public function getRequest(): RequestInterface { return $this->request; } diff --git a/src/Result/Cgi/ResultInterface.php b/src/Result/Cgi/ResultInterface.php index a9fa6e82..e54424ab 100644 --- a/src/Result/Cgi/ResultInterface.php +++ b/src/Result/Cgi/ResultInterface.php @@ -14,5 +14,5 @@ interface ResultInterface extends \PhpSchool\PhpWorkshop\Result\ResultInterface * * @return RequestInterface */ - public function getRequest(); + public function getRequest(): RequestInterface; } diff --git a/src/Result/Cgi/Success.php b/src/Result/Cgi/Success.php index a5e76973..25f7873b 100644 --- a/src/Result/Cgi/Success.php +++ b/src/Result/Cgi/Success.php @@ -33,7 +33,7 @@ public function __construct(RequestInterface $request) * * @return string */ - public function getCheckName() + public function getCheckName(): string { return $this->name; } @@ -43,7 +43,7 @@ public function getCheckName() * * @return RequestInterface */ - public function getRequest() + public function getRequest(): RequestInterface { return $this->request; } diff --git a/src/Result/Cli/CliResult.php b/src/Result/Cli/CliResult.php index 3a6ff39c..02082588 100644 --- a/src/Result/Cli/CliResult.php +++ b/src/Result/Cli/CliResult.php @@ -67,7 +67,7 @@ public function isSuccessful(): bool } /** - * @return ResultInterface[] + * @return array */ public function getResults(): array { diff --git a/src/Result/Cli/GenericFailure.php b/src/Result/Cli/GenericFailure.php index bdaf3ae9..4ec12974 100644 --- a/src/Result/Cli/GenericFailure.php +++ b/src/Result/Cli/GenericFailure.php @@ -25,7 +25,7 @@ class GenericFailure extends Failure implements FailureInterface * @param ArrayObject $args The arguments that caused the failure. * @param string|null $reason The reason (if any) of the failure. */ - public function __construct(ArrayObject $args, $reason = null) + public function __construct(ArrayObject $args, string $reason = null) { $this->args = $args; parent::__construct(static::$name, $reason); @@ -38,7 +38,7 @@ public function __construct(ArrayObject $args, $reason = null) * @param string|null $reason The reason (if any) of the failure. * @return self The result. */ - public static function fromArgsAndReason(ArrayObject $args, ?string $reason): self + public static function fromArgsAndReason(ArrayObject $args, string $reason = null): self { return new self($args, $reason); } diff --git a/src/Result/ComparisonFailure.php b/src/Result/ComparisonFailure.php index 8ea5efea..2d28c073 100644 --- a/src/Result/ComparisonFailure.php +++ b/src/Result/ComparisonFailure.php @@ -27,11 +27,11 @@ class ComparisonFailure implements FailureInterface * @param string $expectedValue * @param string $actualValue */ - public function __construct($name, $expectedValue, $actualValue) + public function __construct(string $name, string $expectedValue, string $actualValue) { - $this->name = $name; + $this->name = $name; $this->expectedValue = $expectedValue; - $this->actualValue = $actualValue; + $this->actualValue = $actualValue; } /** @@ -40,7 +40,7 @@ public function __construct($name, $expectedValue, $actualValue) * @param string $actualValue * @return self */ - public static function fromNameAndValues($name, $expectedValue, $actualValue) + public static function fromNameAndValues(string $name, string $expectedValue, string $actualValue): self { return new self($name, $expectedValue, $actualValue); } @@ -50,7 +50,7 @@ public static function fromNameAndValues($name, $expectedValue, $actualValue) * * @return string */ - public function getCheckName() + public function getCheckName(): string { return $this->name; } @@ -60,7 +60,7 @@ public function getCheckName() * * @return string */ - public function getExpectedValue() + public function getExpectedValue(): string { return $this->expectedValue; } @@ -70,7 +70,7 @@ public function getExpectedValue() * * @return string */ - public function getActualValue() + public function getActualValue(): string { return $this->actualValue; } diff --git a/src/Result/Failure.php b/src/Result/Failure.php index d7f643ce..a00c9d5a 100644 --- a/src/Result/Failure.php +++ b/src/Result/Failure.php @@ -41,7 +41,7 @@ public function __construct(string $name, string $reason = null) * @param string|null $reason The reason (if any) of the failure. * @return self The result. */ - public static function fromNameAndReason(string $name, ?string $reason): self + public static function fromNameAndReason(string $name, string $reason = null): self { return new self($name, $reason); } @@ -50,10 +50,10 @@ public static function fromNameAndReason(string $name, ?string $reason): self * Static constructor to create from an instance of `PhpSchool\PhpWorkshop\Check\CheckInterface`. * * @param CheckInterface $check The check instance. - * @param string $reason The reason (if any) of the failure. + * @param string|null $reason The reason (if any) of the failure. * @return self The result. */ - public static function fromCheckAndReason(CheckInterface $check, string $reason): self + public static function fromCheckAndReason(CheckInterface $check, string $reason = null): self { return new self($check->getName(), $reason); } diff --git a/src/Result/ResultGroupInterface.php b/src/Result/ResultGroupInterface.php index 1624ea97..d2d23cbe 100644 --- a/src/Result/ResultGroupInterface.php +++ b/src/Result/ResultGroupInterface.php @@ -10,10 +10,10 @@ interface ResultGroupInterface extends ResultInterface /** * @return bool */ - public function isSuccessful(); + public function isSuccessful(): bool; /** - * @return ResultInterface[] + * @return array */ - public function getResults(); + public function getResults(): array; } diff --git a/src/Result/ResultInterface.php b/src/Result/ResultInterface.php index 855291f2..c4fa891a 100644 --- a/src/Result/ResultInterface.php +++ b/src/Result/ResultInterface.php @@ -14,5 +14,5 @@ interface ResultInterface * * @return string */ - public function getCheckName(); + public function getCheckName(): string; } diff --git a/src/Result/ResultTrait.php b/src/Result/ResultTrait.php index 4c565d07..efb79773 100644 --- a/src/Result/ResultTrait.php +++ b/src/Result/ResultTrait.php @@ -21,7 +21,7 @@ trait ResultTrait * * @return string */ - public function getCheckName() + public function getCheckName(): string { return $this->check->getName(); } diff --git a/src/Result/Success.php b/src/Result/Success.php index 846acb9a..2e573d17 100644 --- a/src/Result/Success.php +++ b/src/Result/Success.php @@ -28,7 +28,7 @@ public function __construct(string $name) * @param CheckInterface $check The check instance. * @return self The result. */ - public static function fromCheck(CheckInterface $check) + public static function fromCheck(CheckInterface $check): self { return new self($check->getName()); } diff --git a/src/ResultRenderer/Cli/RequestFailureRenderer.php b/src/ResultRenderer/Cli/RequestFailureRenderer.php index 1afb5bea..0bab93d1 100644 --- a/src/ResultRenderer/Cli/RequestFailureRenderer.php +++ b/src/ResultRenderer/Cli/RequestFailureRenderer.php @@ -30,7 +30,7 @@ public function __construct(RequestFailure $result) * @param ResultsRenderer $renderer * @return string */ - public function render(ResultsRenderer $renderer) + public function render(ResultsRenderer $renderer): string { return sprintf( " %s\n%s\n\n %s\n%s\n", @@ -45,7 +45,7 @@ public function render(ResultsRenderer $renderer) * @param string $string * @return string */ - private function indent($string) + private function indent(string $string): string { return implode( "\n", diff --git a/src/ResultRenderer/ComparisonFailureRenderer.php b/src/ResultRenderer/ComparisonFailureRenderer.php index 752f097f..7a3c6504 100644 --- a/src/ResultRenderer/ComparisonFailureRenderer.php +++ b/src/ResultRenderer/ComparisonFailureRenderer.php @@ -29,7 +29,7 @@ public function __construct(ComparisonFailure $result) * @param ResultsRenderer $renderer * @return string */ - public function render(ResultsRenderer $renderer) + public function render(ResultsRenderer $renderer): string { return sprintf( " %s\n%s\n\n %s\n%s\n", @@ -44,7 +44,7 @@ public function render(ResultsRenderer $renderer) * @param string $string * @return string */ - private function indent($string) + private function indent(string $string): string { return implode( "\n", diff --git a/src/ResultRenderer/FunctionRequirementsFailureRenderer.php b/src/ResultRenderer/FunctionRequirementsFailureRenderer.php index c5584b88..2d28e89e 100644 --- a/src/ResultRenderer/FunctionRequirementsFailureRenderer.php +++ b/src/ResultRenderer/FunctionRequirementsFailureRenderer.php @@ -28,7 +28,7 @@ public function __construct(FunctionRequirementsFailure $result) * @param ResultsRenderer $renderer * @return string */ - public function render(ResultsRenderer $renderer) + public function render(ResultsRenderer $renderer): string { $output = ''; if (count($bannedFunctions = $this->result->getBannedFunctions())) { diff --git a/src/ResultRenderer/ResultRendererInterface.php b/src/ResultRenderer/ResultRendererInterface.php index f652cabb..1e4d4315 100644 --- a/src/ResultRenderer/ResultRendererInterface.php +++ b/src/ResultRenderer/ResultRendererInterface.php @@ -19,5 +19,5 @@ interface ResultRendererInterface * @param ResultsRenderer $renderer The main renderer instance. * @return string The string representation of the result. */ - public function render(ResultsRenderer $renderer); + public function render(ResultsRenderer $renderer): string; } diff --git a/src/ResultRenderer/ResultsRenderer.php b/src/ResultRenderer/ResultsRenderer.php index 827bccfe..33686ee4 100644 --- a/src/ResultRenderer/ResultsRenderer.php +++ b/src/ResultRenderer/ResultsRenderer.php @@ -70,11 +70,11 @@ public function __construct( KeyLighter $keyLighter, ResultRendererFactory $resultRendererFactory ) { - $this->color = $color; - $this->terminal = $terminal; - $this->exerciseRepository = $exerciseRepository; - $this->keyLighter = $keyLighter; - $this->appName = $appName; + $this->color = $color; + $this->terminal = $terminal; + $this->exerciseRepository = $exerciseRepository; + $this->keyLighter = $keyLighter; + $this->appName = $appName; $this->resultRendererFactory = $resultRendererFactory; } @@ -137,7 +137,7 @@ public function render( */ private function renderErrorInformation( array $failures, - $padLength, + int $padLength, ExerciseInterface $exercise, OutputInterface $output ): void { diff --git a/src/Solution/DirectorySolution.php b/src/Solution/DirectorySolution.php index 3e49dc2f..de8cf91f 100644 --- a/src/Solution/DirectorySolution.php +++ b/src/Solution/DirectorySolution.php @@ -58,7 +58,7 @@ public function __construct(string $directory, string $entryPoint, array $exclus } sort($files); - if (!in_array($entryPoint, $files)) { + if (!in_array($entryPoint, $files, true)) { throw new InvalidArgumentException( sprintf('Entry point: "%s" does not exist in: "%s"', $entryPoint, $directory) ); diff --git a/src/UserStateSerializer.php b/src/UserStateSerializer.php index e2a5a7a0..c9e5adce 100644 --- a/src/UserStateSerializer.php +++ b/src/UserStateSerializer.php @@ -37,8 +37,11 @@ class UserStateSerializer * @param string $workshopName The name of the current workshop. * @param ExerciseRepository $exerciseRepository The repository of exercises. */ - public function __construct($saveFileDirectory, $workshopName, ExerciseRepository $exerciseRepository) - { + public function __construct( + string $saveFileDirectory, + string $workshopName, + ExerciseRepository $exerciseRepository + ) { $this->workshopName = $workshopName; $this->path = $saveFileDirectory; $this->exerciseRepository = $exerciseRepository; @@ -173,7 +176,7 @@ private function migrateData(string $legacySaveFile): ?UserState * @param string $filePath * @return array|null */ - private function readJson($filePath): ?array + private function readJson(string $filePath): ?array { if (!file_exists($filePath)) { return null; diff --git a/src/Utils/RequestRenderer.php b/src/Utils/RequestRenderer.php index 27dd5073..825ee5f7 100644 --- a/src/Utils/RequestRenderer.php +++ b/src/Utils/RequestRenderer.php @@ -15,7 +15,7 @@ class RequestRenderer * @param RequestInterface $request * @return string */ - public function renderRequest(RequestInterface $request) + public function renderRequest(RequestInterface $request): string { $return = ''; $return .= sprintf("URL: %s\n", $request->getUri()); diff --git a/test/Check/DatabaseCheckTest.php b/test/Check/DatabaseCheckTest.php index 8f703b04..779836f3 100644 --- a/test/Check/DatabaseCheckTest.php +++ b/test/Check/DatabaseCheckTest.php @@ -237,7 +237,6 @@ public function testFailureIsReturnedIfDatabaseVerificationFails(): void { $solution = SingleFileSolution::fromFile(realpath(__DIR__ . '/../res/database/solution.php')); - $this->exercise ->expects($this->once()) ->method('getSolution') @@ -292,6 +291,10 @@ public function testAlteringDatabaseInSolutionDoesNotEffectDatabaseInUserSolutio ->method('getArgs') ->willReturn([]); + $this->exercise + ->method('verify') + ->willReturn(true); + $this->exercise ->expects($this->once()) ->method('configure')