diff --git a/composer.json b/composer.json index 87f7eeee..edf7dbdc 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ ], "require" : { "php" : ">=7.2", + "ext-pdo": "*", "ext-pdo_sqlite": "*", "php-di/php-di": "^6.0", "psr/container": "^1.0", diff --git a/src/Application.php b/src/Application.php index 4fd93ab8..7cdc923e 100644 --- a/src/Application.php +++ b/src/Application.php @@ -4,13 +4,18 @@ namespace PhpSchool\PhpWorkshop; +use DI\Container; use DI\ContainerBuilder; use PhpSchool\PhpWorkshop\Check\CheckRepository; use PhpSchool\PhpWorkshop\Exception\InvalidArgumentException; use PhpSchool\PhpWorkshop\Exception\MissingArgumentException; -use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; use PhpSchool\PhpWorkshop\Factory\ResultRendererFactory; use PhpSchool\PhpWorkshop\Output\OutputInterface; +use RuntimeException; + +use function class_exists; +use function is_file; +use function sprintf; /** * This is the main application class, this takes care of bootstrapping, routing and @@ -46,7 +51,7 @@ final class Application /** * @var string|null */ - private $logo = null; + private $logo; /** * @var string @@ -72,8 +77,8 @@ final class Application */ public function __construct(string $workshopTitle, string $diConfigFile) { - if (!\is_file($diConfigFile)) { - throw new InvalidArgumentException(\sprintf('File "%s" was expected to exist.', $diConfigFile)); + if (!is_file($diConfigFile)) { + throw new InvalidArgumentException(sprintf('File "%s" was expected to exist.', $diConfigFile)); } $this->workshopTitle = $workshopTitle; @@ -108,12 +113,12 @@ public function addExercise(string $exercise): void */ public function addResult(string $resultClass, string $resultRendererClass): void { - if (!\class_exists($resultClass)) { - throw new InvalidArgumentException(\sprintf('Class "%s" does not exist', $resultClass)); + if (!class_exists($resultClass)) { + throw new InvalidArgumentException(sprintf('Class "%s" does not exist', $resultClass)); } - if (!\class_exists($resultRendererClass)) { - throw new InvalidArgumentException(\sprintf('Class "%s" does not exist', $resultRendererClass)); + if (!class_exists($resultRendererClass)) { + throw new InvalidArgumentException(sprintf('Class "%s" does not exist', $resultRendererClass)); } $this->results[] = [ @@ -167,7 +172,7 @@ public function run(): int foreach ($this->exercises as $exercise) { if (false === $container->has($exercise)) { - throw new \RuntimeException( + throw new RuntimeException( sprintf('No DI config found for exercise: "%s". Register a factory.', $exercise) ); } @@ -176,7 +181,7 @@ public function run(): int $checkRepository = $container->get(CheckRepository::class); foreach ($this->checks as $check) { if (false === $container->has($check)) { - throw new \RuntimeException( + throw new RuntimeException( sprintf('No DI config found for check: "%s". Register a factory.', $check) ); } @@ -206,7 +211,7 @@ public function run(): int ) ); return 1; - } catch (\RuntimeException $e) { + } catch (RuntimeException $e) { $container ->get(OutputInterface::class) ->printError( @@ -221,9 +226,9 @@ public function run(): int } /** - * @return \DI\Container + * @return Container */ - private function getContainer(): \DI\Container + private function getContainer(): Container { $containerBuilder = new ContainerBuilder(); $containerBuilder->addDefinitions( diff --git a/src/Check/CodeParseCheck.php b/src/Check/CodeParseCheck.php index b697889f..670ec1b1 100644 --- a/src/Check/CodeParseCheck.php +++ b/src/Check/CodeParseCheck.php @@ -5,8 +5,6 @@ namespace PhpSchool\PhpWorkshop\Check; use PhpParser\Error; -use PhpParser\Node\Expr\FuncCall; -use PhpParser\NodeTraverser; use PhpParser\Parser; use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; use PhpSchool\PhpWorkshop\Exercise\ExerciseType; @@ -66,6 +64,8 @@ public function check(ExerciseInterface $exercise, Input $input): ResultInterfac /** * This check can run on any exercise type. + * @param ExerciseType $exerciseType + * @return bool */ public function canRun(ExerciseType $exerciseType): bool { diff --git a/src/Check/ComposerCheck.php b/src/Check/ComposerCheck.php index 3b663853..81318156 100644 --- a/src/Check/ComposerCheck.php +++ b/src/Check/ComposerCheck.php @@ -4,6 +4,7 @@ namespace PhpSchool\PhpWorkshop\Check; +use InvalidArgumentException; use PhpSchool\PhpWorkshop\ComposerUtil\LockFileParser; use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; use PhpSchool\PhpWorkshop\Exercise\ExerciseType; @@ -35,11 +36,12 @@ public function getName(): string * @param ExerciseInterface $exercise The exercise to check against. * @param Input $input The command line arguments passed to the command. * @return ResultInterface The result of the check. + * @noinspection SpellCheckingInspection */ public function check(ExerciseInterface $exercise, Input $input): ResultInterface { if (!$exercise instanceof ComposerExerciseCheck) { - throw new \InvalidArgumentException(); + throw new InvalidArgumentException(); } if (!file_exists(sprintf('%s/composer.json', dirname($input->getRequiredArgument('program'))))) { @@ -74,6 +76,9 @@ public function check(ExerciseInterface $exercise, Input $input): ResultInterfac /** * This check can run on any exercise type. + * + * @param ExerciseType $exerciseType + * @return bool */ public function canRun(ExerciseType $exerciseType): bool { diff --git a/src/Check/DatabaseCheck.php b/src/Check/DatabaseCheck.php index 29de3f68..2eba2878 100644 --- a/src/Check/DatabaseCheck.php +++ b/src/Check/DatabaseCheck.php @@ -5,6 +5,7 @@ namespace PhpSchool\PhpWorkshop\Check; use PDO; +use PDOException; use PhpSchool\PhpWorkshop\Event\CliExecuteEvent; use PhpSchool\PhpWorkshop\Event\Event; use PhpSchool\PhpWorkshop\Event\EventDispatcher; @@ -12,6 +13,7 @@ use PhpSchool\PhpWorkshop\ExerciseCheck\DatabaseExerciseCheck; use PhpSchool\PhpWorkshop\Result\Failure; use PhpSchool\PhpWorkshop\Result\Success; +use RuntimeException; /** * This check sets up a database and a `PDO` object. It prepends the database DSN as a CLI argument to the student's @@ -75,12 +77,14 @@ public function getExerciseInterface(): string /** * Here we attach to various events to seed, verify and inject the DSN's - * to the student & reference solution programs's CLI arguments. + * to the student & reference solution programs' CLI arguments. + * + * @param EventDispatcher $eventDispatcher */ public function attach(EventDispatcher $eventDispatcher): void { if (file_exists($this->databaseDirectory)) { - throw new \RuntimeException( + throw new RuntimeException( sprintf('Database directory: "%s" already exists', $this->databaseDirectory) ); } @@ -90,7 +94,7 @@ public function attach(EventDispatcher $eventDispatcher): void try { $db = new PDO($this->userDsn); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - } catch (\PDOException $e) { + } catch (PDOException $e) { rmdir($this->databaseDirectory); throw $e; } @@ -132,7 +136,7 @@ function (CliExecuteEvent $e) { 'verify.finish', 'run.finish' ], - function (Event $e) use ($db) { + function () use ($db) { unset($db); @unlink($this->userDatabasePath); @unlink($this->solutionDatabasePath); diff --git a/src/Check/FileExistsCheck.php b/src/Check/FileExistsCheck.php index ff0952b9..5dba56e8 100644 --- a/src/Check/FileExistsCheck.php +++ b/src/Check/FileExistsCheck.php @@ -45,6 +45,9 @@ public function check(ExerciseInterface $exercise, Input $input): ResultInterfac /** * This check can run on any exercise type. + * + * @param ExerciseType $exerciseType + * @return bool */ public function canRun(ExerciseType $exerciseType): bool { @@ -57,7 +60,7 @@ public function getExerciseInterface(): string } /** - * This check must run before executing the solution becuase it may not exist. + * This check must run before executing the solution because it may not exist. */ public function getPosition(): string { diff --git a/src/Check/FunctionRequirementsCheck.php b/src/Check/FunctionRequirementsCheck.php index 2684b5d9..4c14f851 100644 --- a/src/Check/FunctionRequirementsCheck.php +++ b/src/Check/FunctionRequirementsCheck.php @@ -4,9 +4,9 @@ namespace PhpSchool\PhpWorkshop\Check; +use InvalidArgumentException; use PhpParser\Error; use PhpParser\Node\Expr\FuncCall; -use PhpParser\Node\Name; use PhpParser\NodeTraverser; use PhpParser\Parser; use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; @@ -18,7 +18,6 @@ use PhpSchool\PhpWorkshop\Result\FunctionRequirementsFailure; use PhpSchool\PhpWorkshop\Result\ResultInterface; use PhpSchool\PhpWorkshop\Result\Success; -use PhpSchool\PhpWorkshop\Utils\Collection; /** * This check verifies that the student's solution contains usages of some required functions @@ -59,7 +58,7 @@ public function getName(): string public function check(ExerciseInterface $exercise, Input $input): ResultInterface { if (!$exercise instanceof FunctionRequirementsExerciseCheck) { - throw new \InvalidArgumentException(); + throw new InvalidArgumentException(); } $requiredFunctions = $exercise->getRequiredFunctions(); @@ -100,6 +99,9 @@ public function check(ExerciseInterface $exercise, Input $input): ResultInterfac /** * This check can run on any exercise type. + * + * @param ExerciseType $exerciseType + * @return bool */ public function canRun(ExerciseType $exerciseType): bool { diff --git a/src/Check/ListenableCheckInterface.php b/src/Check/ListenableCheckInterface.php index 8995b72d..ac517530 100644 --- a/src/Check/ListenableCheckInterface.php +++ b/src/Check/ListenableCheckInterface.php @@ -14,6 +14,8 @@ interface ListenableCheckInterface extends CheckInterface /** * Attach to events throughout the running/verifying process. Inject verifiers * and listeners. + * + * @param EventDispatcher $eventDispatcher */ public function attach(EventDispatcher $eventDispatcher): void; } diff --git a/src/Check/PhpLintCheck.php b/src/Check/PhpLintCheck.php index 9d148251..17c8984f 100644 --- a/src/Check/PhpLintCheck.php +++ b/src/Check/PhpLintCheck.php @@ -47,6 +47,9 @@ public function check(ExerciseInterface $exercise, Input $input): ResultInterfac /** * This check can run on any exercise type. + * + * @param ExerciseType $exerciseType + * @return bool */ public function canRun(ExerciseType $exerciseType): bool { diff --git a/src/Check/SimpleCheckInterface.php b/src/Check/SimpleCheckInterface.php index af72aa9a..5b4bf78a 100644 --- a/src/Check/SimpleCheckInterface.php +++ b/src/Check/SimpleCheckInterface.php @@ -31,6 +31,9 @@ interface SimpleCheckInterface extends CheckInterface /** * Can this check run this exercise? + * + * @param ExerciseType $exerciseType + * @return bool */ public function canRun(ExerciseType $exerciseType): bool; diff --git a/src/Command/PrintCommand.php b/src/Command/PrintCommand.php index 7e63bb58..89a7a429 100644 --- a/src/Command/PrintCommand.php +++ b/src/Command/PrintCommand.php @@ -4,7 +4,6 @@ namespace PhpSchool\PhpWorkshop\Command; -use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; use PhpSchool\PhpWorkshop\ExerciseRepository; use PhpSchool\PhpWorkshop\MarkdownRenderer; use PhpSchool\PhpWorkshop\Output\OutputInterface; diff --git a/src/Command/VerifyCommand.php b/src/Command/VerifyCommand.php index 416c0799..f99c15fa 100644 --- a/src/Command/VerifyCommand.php +++ b/src/Command/VerifyCommand.php @@ -6,7 +6,6 @@ use PhpSchool\PhpWorkshop\ExerciseDispatcher; use PhpSchool\PhpWorkshop\ExerciseRepository; -use PhpSchool\PhpWorkshop\ExerciseRunner; use PhpSchool\PhpWorkshop\Input\Input; use PhpSchool\PhpWorkshop\Output\OutputInterface; use PhpSchool\PhpWorkshop\ResultRenderer\ResultsRenderer; diff --git a/src/CommandRouter.php b/src/CommandRouter.php index c86a3b20..168f2dec 100644 --- a/src/CommandRouter.php +++ b/src/CommandRouter.php @@ -4,11 +4,13 @@ namespace PhpSchool\PhpWorkshop; +use InvalidArgumentException; use PhpSchool\PhpWorkshop\Event\EventDispatcher; use PhpSchool\PhpWorkshop\Exception\CliRouteNotExistsException; use PhpSchool\PhpWorkshop\Exception\MissingArgumentException; use Psr\Container\ContainerInterface; use PhpSchool\PhpWorkshop\Input\Input; +use RuntimeException; /** * Parses $argv (or passed array) and attempts to find a command @@ -60,7 +62,7 @@ public function __construct( } if (!isset($this->commands[$default])) { - throw new \InvalidArgumentException(sprintf('Default command: "%s" is not available', $default)); + throw new InvalidArgumentException(sprintf('Default command: "%s" is not available', $default)); } $this->defaultCommand = $default; $this->eventDispatcher = $eventDispatcher; @@ -73,7 +75,7 @@ public function __construct( private function addCommand(CommandDefinition $c): void { if (isset($this->commands[$c->getName()])) { - throw new \InvalidArgumentException(sprintf('Command with name: "%s" already exists', $c->getName())); + throw new InvalidArgumentException(sprintf('Command with name: "%s" already exists', $c->getName())); } $this->commands[$c->getName()] = $c; @@ -100,7 +102,7 @@ public function route(array $args = null): int { if (null === $args) { - $args = isset($_SERVER['argv']) ? $_SERVER['argv'] : []; + $args = $_SERVER['argv'] ?? []; } $appName = array_shift($args); @@ -196,17 +198,17 @@ private function resolveCallable(CommandDefinition $command, Input $input): int } if (!is_string($commandCallable)) { - throw new \RuntimeException('Callable must be a callable or a container entry for a callable service'); + throw new RuntimeException('Callable must be a callable or a container entry for a callable service'); } if (!$this->container->has($commandCallable)) { - throw new \RuntimeException(sprintf('Container has no entry named: "%s"', $commandCallable)); + throw new RuntimeException(sprintf('Container has no entry named: "%s"', $commandCallable)); } $callable = $this->container->get($commandCallable); if (!is_callable($callable)) { - throw new \RuntimeException(sprintf('Container entry: "%s" not callable', $commandCallable)); + throw new RuntimeException(sprintf('Container entry: "%s" not callable', $commandCallable)); } $return = $this->callCommand($command, $callable, $input); diff --git a/src/ComposerUtil/LockFileParser.php b/src/ComposerUtil/LockFileParser.php index d6b14d26..afb63593 100644 --- a/src/ComposerUtil/LockFileParser.php +++ b/src/ComposerUtil/LockFileParser.php @@ -61,7 +61,7 @@ public function getInstalledPackages(): array * @param string $packageName * @return bool */ - public function hasInstalledPackage($packageName): bool + public function hasInstalledPackage(string $packageName): bool { foreach ($this->contents['packages'] as $packageDetails) { if ($packageName === $packageDetails['name']) { diff --git a/src/Event/EventDispatcher.php b/src/Event/EventDispatcher.php index dfacca14..8999e526 100644 --- a/src/Event/EventDispatcher.php +++ b/src/Event/EventDispatcher.php @@ -94,8 +94,6 @@ public function insertVerifier(string $eventName, callable $verifier): void //return type hints pls if ($result instanceof ResultInterface) { $this->resultAggregator->add($result); - } else { - //??!! } }); } diff --git a/src/Exception/ExerciseNotAssignedException.php b/src/Exception/ExerciseNotAssignedException.php index 490276f9..80cd5e41 100644 --- a/src/Exception/ExerciseNotAssignedException.php +++ b/src/Exception/ExerciseNotAssignedException.php @@ -4,10 +4,12 @@ namespace PhpSchool\PhpWorkshop\Exception; +use RuntimeException; + /** * When a student has no exercise assigned */ -class ExerciseNotAssignedException extends \RuntimeException +class ExerciseNotAssignedException extends RuntimeException { /** * @return self diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 038f389a..4804e51d 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -52,7 +52,7 @@ public static function notValidParameter(string $parameterName, array $allowedVa * @param class-string $requiredInterface * @return self */ - public static function missingImplements($object, string $requiredInterface): self + public static function missingImplements(object $object, string $requiredInterface): self { return new self( sprintf( diff --git a/src/Exception/MissingArgumentException.php b/src/Exception/MissingArgumentException.php index 552d5e72..d4dbcc65 100644 --- a/src/Exception/MissingArgumentException.php +++ b/src/Exception/MissingArgumentException.php @@ -14,7 +14,7 @@ class MissingArgumentException extends RuntimeException /** * @var array */ - private $missingArguments = []; + private $missingArguments; /** * Create the exception, requires the command name and missing arguments. diff --git a/src/Exercise/ExerciseInterface.php b/src/Exercise/ExerciseInterface.php index fb3e8fc8..e636fbeb 100644 --- a/src/Exercise/ExerciseInterface.php +++ b/src/Exercise/ExerciseInterface.php @@ -5,7 +5,6 @@ namespace PhpSchool\PhpWorkshop\Exercise; use PhpSchool\PhpWorkshop\ExerciseDispatcher; -use PhpSchool\PhpWorkshop\Solution\SolutionInterface; /** * This interface describes all of the methods an exercise diff --git a/src/ExerciseDispatcher.php b/src/ExerciseDispatcher.php index 77230edc..4dbc6d3c 100644 --- a/src/ExerciseDispatcher.php +++ b/src/ExerciseDispatcher.php @@ -4,11 +4,9 @@ namespace PhpSchool\PhpWorkshop; -use PhpSchool\PhpWorkshop\Check\CheckInterface; use PhpSchool\PhpWorkshop\Check\CheckRepository; use PhpSchool\PhpWorkshop\Check\ListenableCheckInterface; use PhpSchool\PhpWorkshop\Check\SimpleCheckInterface; -use PhpSchool\PhpWorkshop\Event\Event; use PhpSchool\PhpWorkshop\Event\EventDispatcher; use PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent; use PhpSchool\PhpWorkshop\Exception\CheckNotApplicableException; diff --git a/src/ExerciseRenderer.php b/src/ExerciseRenderer.php index f578945b..6b1ffe3d 100644 --- a/src/ExerciseRenderer.php +++ b/src/ExerciseRenderer.php @@ -59,7 +59,7 @@ class ExerciseRenderer * @param OutputInterface $output */ public function __construct( - $appName, + string $appName, ExerciseRepository $exerciseRepository, UserState $userState, UserStateSerializer $userStateSerializer, @@ -91,7 +91,7 @@ public function __invoke(CliMenu $menu): void $this->userStateSerializer->serialize($this->userState); $numExercises = count($exercises); - $exerciseIndex = ((int) array_search($exercise, $exercises)) + 1; + $exerciseIndex = ((int) array_search($exercise, $exercises, true)) + 1; $output = "\n"; $output .= $this->color->__invoke(' LEARN YOU THE PHP FOR MUCH WIN! ')->magenta()->bold() . "\n"; diff --git a/src/ExerciseRunner/CgiRunner.php b/src/ExerciseRunner/CgiRunner.php index 9a8eb9f4..c5fd6305 100644 --- a/src/ExerciseRunner/CgiRunner.php +++ b/src/ExerciseRunner/CgiRunner.php @@ -28,7 +28,6 @@ use Psr\Http\Message\ResponseInterface; use RuntimeException; use Symfony\Component\Process\Process; -use Zend\Diactoros\Response\Serializer as ResponseSerializer; /** * The `CGI` runner. This runner executes solutions as if they were behind a web-server. They populate the `$_SERVER`, @@ -74,9 +73,9 @@ public function __construct( EventDispatcher $eventDispatcher, RequestRenderer $requestRenderer ) { - if (strpos(PHP_OS, 'WIN') !== false) { + if (PHP_OS_FAMILY === 'Windows') { // Check if in path. 2> nul > nul equivalent to 2>&1 /dev/null - $silence = (PHP_OS == 'CYGWIN' ? '> /dev/null 2>&1' : '2> nul > nul'); + $silence = (PHP_OS === 'CYGWIN' ? '> /dev/null 2>&1' : '2> nul > nul'); system(sprintf('php-cgi --version %s', $silence), $failedToRun); if ($failedToRun) { $newPath = realpath(sprintf('%s/%s', dirname(PHP_BINARY), 'php-cgi.exe')); diff --git a/src/ExerciseRunner/ExerciseRunnerInterface.php b/src/ExerciseRunner/ExerciseRunnerInterface.php index 42dbb023..66acec07 100644 --- a/src/ExerciseRunner/ExerciseRunnerInterface.php +++ b/src/ExerciseRunner/ExerciseRunnerInterface.php @@ -4,8 +4,6 @@ namespace PhpSchool\PhpWorkshop\ExerciseRunner; -use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; -use PhpSchool\PhpWorkshop\ExerciseDispatcher; use PhpSchool\PhpWorkshop\Input\Input; use PhpSchool\PhpWorkshop\Output\OutputInterface; use PhpSchool\PhpWorkshop\Result\ResultInterface; diff --git a/src/Factory/ResultRendererFactory.php b/src/Factory/ResultRendererFactory.php index 10109a90..f1776d52 100644 --- a/src/Factory/ResultRendererFactory.php +++ b/src/Factory/ResultRendererFactory.php @@ -7,6 +7,7 @@ use PhpSchool\PhpWorkshop\Exception\InvalidArgumentException; use PhpSchool\PhpWorkshop\Result\ResultInterface; use PhpSchool\PhpWorkshop\ResultRenderer\ResultRendererInterface; +use RuntimeException; /** * Manages and creates renderers for results @@ -53,7 +54,7 @@ public function create(ResultInterface $result): ResultRendererInterface { $class = get_class($result); if (!isset($this->mappings[$class])) { - throw new \RuntimeException(sprintf('No renderer found for "%s"', $class)); + throw new RuntimeException(sprintf('No renderer found for "%s"', $class)); } $class = $this->mappings[$class]; @@ -62,7 +63,7 @@ public function create(ResultInterface $result): ResultRendererInterface $renderer = $factory($result); if (!$renderer instanceof $class) { - throw new \RuntimeException( + throw new RuntimeException( sprintf( 'Renderer Factory for "%s" produced "%s" instead of expected "%s"', $class, diff --git a/src/Input/Input.php b/src/Input/Input.php index 4d0a0d81..a811f6fe 100644 --- a/src/Input/Input.php +++ b/src/Input/Input.php @@ -4,7 +4,6 @@ namespace PhpSchool\PhpWorkshop\Input; -use PhpSchool\PhpWorkshop\CommandDefinition; use PhpSchool\PhpWorkshop\Exception\InvalidArgumentException; /** @@ -20,7 +19,7 @@ class Input /** * @var array */ - private $arguments = []; + private $arguments; /** * @param string $appName diff --git a/src/Listener/CheckExerciseAssignedListener.php b/src/Listener/CheckExerciseAssignedListener.php index 4389dcd4..670bb60f 100644 --- a/src/Listener/CheckExerciseAssignedListener.php +++ b/src/Listener/CheckExerciseAssignedListener.php @@ -7,6 +7,7 @@ use PhpSchool\PhpWorkshop\CommandDefinition; use PhpSchool\PhpWorkshop\Event\Event; use PhpSchool\PhpWorkshop\UserState; +use RuntimeException; class CheckExerciseAssignedListener { @@ -36,7 +37,7 @@ public function __invoke(Event $event): void } if (!$this->userState->isAssignedExercise()) { - throw new \RuntimeException('No active exercise. Select one from the menu'); + throw new RuntimeException('No active exercise. Select one from the menu'); } } } diff --git a/src/Listener/CodePatchListener.php b/src/Listener/CodePatchListener.php index 26d44ed4..a1266167 100644 --- a/src/Listener/CodePatchListener.php +++ b/src/Listener/CodePatchListener.php @@ -5,9 +5,7 @@ namespace PhpSchool\PhpWorkshop\Listener; use PhpSchool\PhpWorkshop\CodePatcher; -use PhpSchool\PhpWorkshop\Event\Event; use PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent; -use PhpSchool\PhpWorkshop\Input\Input; use RuntimeException; /** diff --git a/src/Listener/RealPathListener.php b/src/Listener/RealPathListener.php index 6a8be51a..4bee01c1 100644 --- a/src/Listener/RealPathListener.php +++ b/src/Listener/RealPathListener.php @@ -4,11 +4,7 @@ namespace PhpSchool\PhpWorkshop\Listener; -use PhpSchool\PhpWorkshop\CommandDefinition; -use PhpSchool\PhpWorkshop\Event\Event; use PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent; -use PhpSchool\PhpWorkshop\Input\Input; -use PhpSchool\PhpWorkshop\UserState; /** * Replace program arg with absolute path diff --git a/src/NodeVisitor/FunctionVisitor.php b/src/NodeVisitor/FunctionVisitor.php index e2c5d03b..975bf378 100644 --- a/src/NodeVisitor/FunctionVisitor.php +++ b/src/NodeVisitor/FunctionVisitor.php @@ -44,6 +44,7 @@ public function __construct(array $requiredFunctions, array $bannedFunctions) /** * @param Node $node + * @return null */ public function leaveNode(Node $node) { diff --git a/src/Output/OutputInterface.php b/src/Output/OutputInterface.php index 5bcf1433..745055b3 100644 --- a/src/Output/OutputInterface.php +++ b/src/Output/OutputInterface.php @@ -4,8 +4,6 @@ namespace PhpSchool\PhpWorkshop\Output; -use Psr\Http\Message\RequestInterface; - /** * Output interface */ diff --git a/src/Output/StdOutput.php b/src/Output/StdOutput.php index f2d61f12..2bc15178 100644 --- a/src/Output/StdOutput.php +++ b/src/Output/StdOutput.php @@ -13,7 +13,7 @@ class StdOutput implements OutputInterface { /** - * @var \Colors\Color + * @var Color */ private $color; diff --git a/src/Result/Cgi/CgiResult.php b/src/Result/Cgi/CgiResult.php index 151ff7f7..7661aad9 100644 --- a/src/Result/Cgi/CgiResult.php +++ b/src/Result/Cgi/CgiResult.php @@ -6,7 +6,6 @@ use ArrayIterator; use IteratorAggregate; -use PhpSchool\PhpWorkshop\Result\Cgi\ResultInterface; use PhpSchool\PhpWorkshop\Result\ResultGroupInterface; /** diff --git a/src/Result/Cgi/Success.php b/src/Result/Cgi/Success.php index df92a327..e2428604 100644 --- a/src/Result/Cgi/Success.php +++ b/src/Result/Cgi/Success.php @@ -4,7 +4,6 @@ namespace PhpSchool\PhpWorkshop\Result\Cgi; -use PhpSchool\PhpWorkshop\Check\CheckInterface; use Psr\Http\Message\RequestInterface; /** diff --git a/src/ResultAggregator.php b/src/ResultAggregator.php index c73407da..c750b82d 100644 --- a/src/ResultAggregator.php +++ b/src/ResultAggregator.php @@ -5,7 +5,6 @@ namespace PhpSchool\PhpWorkshop; use ArrayIterator; -use Countable; use IteratorAggregate; use PhpSchool\PhpWorkshop\Result\FailureInterface; use PhpSchool\PhpWorkshop\Result\ResultGroupInterface; diff --git a/src/ResultRenderer/ComparisonFailureRenderer.php b/src/ResultRenderer/ComparisonFailureRenderer.php index e0c39d23..b6559e31 100644 --- a/src/ResultRenderer/ComparisonFailureRenderer.php +++ b/src/ResultRenderer/ComparisonFailureRenderer.php @@ -4,7 +4,6 @@ namespace PhpSchool\PhpWorkshop\ResultRenderer; -use PhpSchool\PhpWorkshop\Result\Cli\RequestFailure; use PhpSchool\PhpWorkshop\Result\ComparisonFailure; /** diff --git a/src/ResultRenderer/ResultsRenderer.php b/src/ResultRenderer/ResultsRenderer.php index 2aff91ba..02dd5250 100644 --- a/src/ResultRenderer/ResultsRenderer.php +++ b/src/ResultRenderer/ResultsRenderer.php @@ -7,7 +7,6 @@ use Colors\Color; use Kadet\Highlighter\Formatter\CliFormatter; use Kadet\Highlighter\KeyLighter; -use PhpSchool\PhpWorkshop\Result\FailureInterface; use PhpSchool\Terminal\Terminal; use PhpSchool\CliMenu\Util\StringUtil; use PhpSchool\PhpWorkshop\Exercise\ProvidesSolution; @@ -20,9 +19,12 @@ use PhpSchool\PhpWorkshop\Result\ResultInterface; use PhpSchool\PhpWorkshop\ResultAggregator; use PhpSchool\PhpWorkshop\UserState; +use PhpSchool\PhpWorkshop\Result\FailureInterface; + +use function mb_str_pad; /** - * Renderer which renders a `PhpSchool\PhpWorkshop\ResultAggregator` and writes it to x§the output. + * Renderer which renders a `PhpSchool\PhpWorkshop\ResultAggregator` and writes it to the output. */ class ResultsRenderer { @@ -145,7 +147,7 @@ private function renderErrorInformation( ): void { foreach ($failures as [$failure, $message]) { $output->writeLine($this->center($this->style(str_repeat(' ', $padLength), ['bg_red']))); - $output->writeLine($this->center($this->style(\mb_str_pad($message, $padLength), ['bg_red']))); + $output->writeLine($this->center($this->style(mb_str_pad($message, $padLength), ['bg_red']))); $output->writeLine($this->center($this->style(str_repeat(' ', $padLength), ['bg_red']))); $output->emptyLine(); diff --git a/src/Solution/DirectorySolution.php b/src/Solution/DirectorySolution.php index ae4b4597..b67b55fe 100644 --- a/src/Solution/DirectorySolution.php +++ b/src/Solution/DirectorySolution.php @@ -8,6 +8,7 @@ use RecursiveCallbackFilterIterator; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; +use SplFileInfo; /** * Solution which can contain multiple files, the file to execute is defined as the entry point. @@ -22,7 +23,7 @@ class DirectorySolution implements SolutionInterface /** * @var array */ - private $files = []; + private $files; /** * @var string @@ -46,7 +47,7 @@ public function __construct(string $directory, string $entryPoint, array $exclus $dir = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS); $iter = new RecursiveIteratorIterator( - new RecursiveCallbackFilterIterator($dir, function (\SplFileInfo $current) use ($exclusions) { + new RecursiveCallbackFilterIterator($dir, function (SplFileInfo $current) use ($exclusions) { return !in_array($current->getBasename(), $exclusions, true); }), RecursiveIteratorIterator::SELF_FIRST diff --git a/src/UserStateSerializer.php b/src/UserStateSerializer.php index ab9efce8..5133fd31 100644 --- a/src/UserStateSerializer.php +++ b/src/UserStateSerializer.php @@ -151,7 +151,7 @@ private function migrateData(string $legacySaveFile): ?UserState } //lets check if the data is in the old format - if (!isset($data['completed_exercises']) || !isset($data['current_exercise'])) { + if (!isset($data['completed_exercises'], $data['current_exercise'])) { unlink($legacySaveFile); return null; } @@ -162,7 +162,7 @@ private function migrateData(string $legacySaveFile): ?UserState //check to see if this old data represents THIS workshop //if not we bail foreach ($completedExercises as $completedExercise) { - if (!in_array($completedExercise, $availableExercises)) { + if (!in_array($completedExercise, $availableExercises, true)) { return null; } } diff --git a/src/Utils/ArrayObject.php b/src/Utils/ArrayObject.php index 52595e3f..26acd2c6 100644 --- a/src/Utils/ArrayObject.php +++ b/src/Utils/ArrayObject.php @@ -149,11 +149,7 @@ public function append($value): self */ public function get(string $key, $default = null) { - if (isset($this->array[$key])) { - return $this->array[$key]; - } - - return $default; + return $this->array[$key] ?? $default; } /**