Skip to content

CS Fixes #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

### Removed

## [2.3.0]
### Added
- Builds support for PHP 7.4
- Various code cleaning (phpstan, psr12, docblock removal)

### Removed
- Removed support for PHP 7.1

## [2.2.0]
### Added
- Builds for PHP 7.1 & 7.2 (#160)
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@
]
},
"autoload-dev": {
"psr-4": {
"PhpSchool\\PhpWorkshopTest\\": "test"
"psr-4": {
"PhpSchool\\PhpWorkshopTest\\": "test"
}
},
"scripts" : {
"cs" : [
"phpcs src --standard=PSR12 --encoding=UTF-8",
"phpcs test --standard=PSR12 --encoding=UTF-8"
],
"cs-fix" : [
"phpcbf src --standard=PSR12 --encoding=UTF-8",
"phpcbf test --standard=PSR12 --encoding=UTF-8"
],
"static": "phpstan --ansi analyse --level max src"
}
}
4 changes: 2 additions & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(string $workshopTitle, string $diConfigFile)
{
Assertion::string($workshopTitle);
Assertion::file($diConfigFile);

$this->workshopTitle = $workshopTitle;
$this->diConfigFile = $diConfigFile;
}
Expand Down Expand Up @@ -159,7 +159,7 @@ public function setBgColour(string $colour): void
public function run(): int
{
$container = $this->getContainer();

foreach ($this->exercises as $exercise) {
if (false === $container->has($exercise)) {
throw new \RuntimeException(
Expand Down
2 changes: 1 addition & 1 deletion src/Check/CodeParseCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function check(ExerciseInterface $exercise, Input $input): ResultInterfac
} catch (Error $e) {
return Failure::fromCheckAndCodeParseFailure($this, $e, $input->getRequiredArgument('program'));
}

return Success::fromCheck($this);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Check/ComposerCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function check(ExerciseInterface $exercise, Input $input): ResultInterfac
if (!$exercise instanceof ComposerExerciseCheck) {
throw new \InvalidArgumentException();
}

if (!file_exists(sprintf('%s/composer.json', dirname($input->getRequiredArgument('program'))))) {
return new Failure($this->getName(), 'No composer.json file found');
}
Expand All @@ -52,12 +52,12 @@ public function check(ExerciseInterface $exercise, Input $input): ResultInterfac
if (!file_exists(sprintf('%s/vendor', dirname($input->getRequiredArgument('program'))))) {
return new Failure($this->getName(), 'No vendor folder found');
}

$lockFile = new LockFileParser(sprintf('%s/composer.lock', dirname($input->getRequiredArgument('program'))));
$missingPackages = array_filter($exercise->getRequiredPackages(), function ($package) use ($lockFile) {
return !$lockFile->hasInstalledPackage($package);
});

if (count($missingPackages) > 0) {
return new Failure(
$this->getName(),
Expand Down
8 changes: 4 additions & 4 deletions src/CodePatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class CodePatcher
* @var Parser
*/
private $parser;

/**
* @var Standard
*/
private $printer;

/**
* @var Patch|null
*/
Expand All @@ -49,7 +49,7 @@ public function __construct(Parser $parser, Standard $printer, Patch $defaultPat
$this->printer = $printer;
$this->defaultPatch = $defaultPatch;
}

/**
* Accepts an exercise and a string containing the students solution to the exercise.
*
Expand All @@ -71,7 +71,7 @@ public function patch(ExerciseInterface $exercise, string $code): string
if ($exercise instanceof SubmissionPatchable) {
$code = $this->applyPatch($exercise->getPatch(), $code);
}

return $code;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Command/CreditsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CreditsCommand
* @var OutputInterface
*/
private $output;

/**
* @var Color
*/
Expand Down Expand Up @@ -61,7 +61,7 @@ private function writeContributors(array $contributors): void
$this->output->writeLine(sprintf("%s %s", str_pad($name, (int) $nameColumnSize), $gitHubUser));
}
}

/**
*
* @return void
Expand All @@ -71,7 +71,7 @@ public function __invoke(): void
if (empty($this->coreContributors)) {
return;
}

$this->output->writeLine(
$this->color->__invoke("PHP School is bought to you by...")->yellow()->__toString()
);
Expand All @@ -84,7 +84,7 @@ public function __invoke(): void

$this->output->emptyLine();
$this->output->emptyLine();

$this->output->writeLine(
$this->color->__invoke("This workshop is brought to you by...")->yellow()->__toString()
);
Expand Down
4 changes: 2 additions & 2 deletions src/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class HelpCommand
* @var string
*/
private $appName;

/**
* @var OutputInterface
*/
Expand All @@ -37,7 +37,7 @@ public function __construct($appName, OutputInterface $output, Color $color)
$this->color = $color;
$this->appName = $appName;
}

/**
* @return void
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Command/VerifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class VerifyCommand
* @var UserStateSerializer
*/
private $userStateSerializer;

/**
* @var ResultsRenderer
*/
Expand Down Expand Up @@ -84,7 +84,7 @@ public function __invoke(Input $input)
$this->userState->addCompletedExercise($exercise->getName());
$this->userStateSerializer->serialize($this->userState);
}

$this->resultsRenderer->render($results, $exercise, $this->userState, $this->output);
return $results->isSuccessful() ? 0 : 1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ComposerUtil/LockFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(string $lockFilePath)
if (!file_exists($lockFilePath)) {
throw new InvalidArgumentException(sprintf('Lock File: "%s" does not exist', $lockFilePath));
}

$this->contents = json_decode((string) file_get_contents($lockFilePath), true);

if (!isset($this->contents['packages'])) {
Expand Down Expand Up @@ -66,7 +66,7 @@ public function hasInstalledPackage($packageName): bool
return true;
}
}

return false;
}
}
6 changes: 3 additions & 3 deletions src/Result/Cgi/RequestFailure.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RequestFailure implements FailureInterface
* @var RequestInterface
*/
private $request;

/**
* @var string
*/
Expand All @@ -24,12 +24,12 @@ class RequestFailure implements FailureInterface
* @var string
*/
private $actualOutput;

/**
* @var array<string, string>
*/
private $expectedHeaders;

/**
* @var array<string, string>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Result/Cli/RequestFailure.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getArgs(): ArrayObject
{
return $this->args;
}

/**
* Get the expected output.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Result/Failure.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function fromNameAndReason(string $name, ?string $reason): self
{
return new self($name, $reason);
}

/**
* Static constructor to create from an instance of `PhpSchool\PhpWorkshop\Check\CheckInterface`.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Result/FunctionRequirementsFailure.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class FunctionRequirementsFailure implements FailureInterface
{
use ResultTrait;

/**
* @var array<int, string>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Result/ResultTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait ResultTrait
* @var CheckInterface
*/
private $check;

/**
* Get the check name from the underlying check. Assumes that the `check` property has been
* assigned an instance of `PhpSchool\PhpWorkshop\Check\CheckInterface`.
Expand Down
4 changes: 2 additions & 2 deletions src/Solution/DirectorySolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public function __construct(string $directory, string $entryPoint, array $exclus
sprintf('Entry point: "%s" does not exist in: "%s"', $entryPoint, $directory)
);
}

$this->files = array_map(function ($file) use ($directory) {
return new SolutionFile($file, $directory);
}, $files);

$this->entryPoint = sprintf('%s/%s', $directory, $entryPoint);
$this->baseDirectory = $directory;
}
Expand Down
6 changes: 3 additions & 3 deletions test/Check/CodeParseCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CodeParseCheckTest extends TestCase
* @var string
*/
private $file;

public function setUp(): void
{
$this->check = new CodeParseCheck((new ParserFactory())->create(ParserFactory::PREFER_PHP7));
Expand All @@ -42,13 +42,13 @@ public function setUp(): void
public function testUnParseableCodeReturnsFailure(): void
{
file_put_contents($this->file, '<?php $lol');

$result = $this->check->check(
$this->createMock(ExerciseInterface::class),
new Input('app', ['program' => $this->file])
);
$this->assertInstanceOf(Failure::class, $result);

$this->assertEquals('Code Parse Check', $result->getCheckName());
$this->assertMatchesRegularExpression(
sprintf('|^File: "%s" could not be parsed\. Error: "|', preg_quote($this->file)),
Expand Down
2 changes: 1 addition & 1 deletion test/Check/ComposerCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function setUp(): void
$this->assertTrue($this->check->canRun(ExerciseType::CGI()));
$this->assertTrue($this->check->canRun(ExerciseType::CLI()));
}

public function testExceptionIsThrownIfNotValidExercise(): void
{
$exercise = $this->createMock(ExerciseInterface::class);
Expand Down
2 changes: 1 addition & 1 deletion test/Check/FunctionRequirementsCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function testFailureIsReturnedIfNotAllRequiredFunctionsHaveBeenUsed(): vo
new Input('app', ['program' => __DIR__ . '/../res/function-requirements/fail-banned-function.php'])
);
$this->assertInstanceOf(FunctionRequirementsFailure::class, $failure);

$this->assertEquals(['file_get_contents', 'implode'], $failure->getMissingFunctions());
$this->assertEquals([], $failure->getBannedFunctions());
}
Expand Down
12 changes: 6 additions & 6 deletions test/CodePatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function testDefaultPatchIsAppliedIfAvailable(): void
$expected = "<?php\n\nini_set(\"display_errors\", 1);\n\$original = true;";
$this->assertEquals($expected, $patcher->patch($exercise, '<?php $original = true;'));
}


public function testPatcherDoesNotApplyPatchIfNotPatchableExercise(): void
{
$patcher = new CodePatcher((new ParserFactory())->create(ParserFactory::PREFER_PHP7), new Standard());
Expand All @@ -38,21 +38,21 @@ public function testPatcherDoesNotApplyPatchIfNotPatchableExercise(): void
$code = '<?php $original = true;';
$this->assertEquals($code, $patcher->patch($exercise, $code));
}

/**
* @dataProvider codeProvider
*/
public function testPatcher(string $code, Patch $patch, string $expectedResult): void
{
$patcher = new CodePatcher((new ParserFactory())->create(ParserFactory::PREFER_PHP7), new Standard());

$exercise = $this->createMock(PatchableExercise::class);

$exercise
->expects($this->once())
->method('getPatch')
->willReturn($patch);

$result = $patcher->patch($exercise, $code);
$this->assertEquals($expectedResult, $result);
}
Expand Down
6 changes: 3 additions & 3 deletions test/Command/CreditsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ public function testWithOnlyCoreContributors(): void
public function testWithNoContributors(): void
{
$this->expectOutputString('');

$color = new Color();
$color->setForceStyle(true);

$command = new CreditsCommand(
[],
[],
new StdOutput($color, $this->createMock(Terminal::class)),
$color
);

$command->__invoke();
}
}
2 changes: 1 addition & 1 deletion test/Command/MenuCommandInvokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testInvoker(): void
$menu
->expects($this->once())
->method('close');

$command = $this->getMockBuilder('stdClass')
->setMethods(['__invoke'])
->getMock();
Expand Down
Loading