Skip to content

Commit

Permalink
Merge pull request #296 from php-school/05-11-migrate_to_php-cs-fixer
Browse files Browse the repository at this point in the history
Migrate to php-cs-fixer
  • Loading branch information
AydinHassan committed May 17, 2024
2 parents a35a0e1 + 02b0fdc commit 90a77ba
Show file tree
Hide file tree
Showing 188 changed files with 2,655 additions and 1,058 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-workshop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
tools: php-cs-fixer,composer:v2
coverage: none

- name: Install Dependencies
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
program.php
.phpunit.result.cache
/build
/vendor-bin/**/vendor/
.php-cs-fixer.cache
13 changes: 13 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->exclude('test/res')
;

return (new PhpCsFixer\Config())
->setRules([
'@PER-CS2.0' => true,
'no_unused_imports' => true,
])
->setFinder($finder);
84 changes: 42 additions & 42 deletions app/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
use PhpSchool\PhpWorkshop\Logger\ConsoleLogger;
use PhpSchool\PhpWorkshop\Logger\Logger;
use PhpSchool\PhpWorkshop\Markdown\CurrentContext;
use PhpSchool\PhpWorkshop\Markdown\Parser\ContextSpecificBlockParser;
use PhpSchool\PhpWorkshop\Markdown\ProblemFileExtension;
use PhpSchool\PhpWorkshop\Markdown\Renderer\ContextSpecificRenderer;
use PhpSchool\PhpWorkshop\Markdown\Shorthands\Cli\AppName;
Expand Down Expand Up @@ -104,6 +103,7 @@
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Filesystem\Filesystem;

use function DI\create;
use function DI\factory;
use function PhpSchool\PhpWorkshop\canonicalise_path;
Expand Down Expand Up @@ -147,7 +147,7 @@
$c->get(ComposerCheck::class),
$c->get(FunctionRequirementsCheck::class),
$c->get(DatabaseCheck::class),
$c->get(FileComparisonCheck::class)
$c->get(FileComparisonCheck::class),
]);
},
CommandRouter::class => function (ContainerInterface $c) {
Expand All @@ -158,16 +158,16 @@
new CommandDefinition('print', [], PrintCommand::class),
new CommandDefinition('verify', [], VerifyCommand::class),
new CommandDefinition('run', [], RunCommand::class),
new CommandDefinition('credits', [], CreditsCommand::class)
new CommandDefinition('credits', [], CreditsCommand::class),
],
'menu',
$c->get(EventDispatcher::class),
$c
$c,
);
},

Color::class => function () {
$colors = new Color;
$colors = new Color();
$colors->setForceStyle(true);
return $colors;
},
Expand All @@ -179,7 +179,7 @@
return new ExerciseRepository(
array_map(function ($exerciseClass) use ($c) {
return $c->get($exerciseClass);
}, $c->get('exercises'))
}, $c->get('exercises')),
);
},

Expand All @@ -196,12 +196,12 @@
$manager->addFactory(new CliRunnerFactory(
$c->get(EventDispatcher::class),
$c->get(ProcessFactory::class),
$c->get(EnvironmentManager::class)
$c->get(EnvironmentManager::class),
));
$manager->addFactory(new CgiRunnerFactory(
$c->get(EventDispatcher::class),
$c->get(ProcessFactory::class),
$c->get(EnvironmentManager::class)
$c->get(EnvironmentManager::class),
));
$manager->addFactory(new CustomVerifyingRunnerFactory());
return $manager;
Expand All @@ -222,7 +222,7 @@
$c->get(ExerciseRepository::class),
$c->get(UserState::class),
$c->get(MarkdownRenderer::class),
$c->get(OutputInterface::class)
$c->get(OutputInterface::class),
);
},

Expand All @@ -233,7 +233,7 @@
$c->get(UserState::class),
$c->get(Serializer::class),
$c->get(OutputInterface::class),
$c->get(ResultsRenderer::class)
$c->get(ResultsRenderer::class),
);
},

Expand All @@ -242,7 +242,7 @@
$c->get(ExerciseRepository::class),
$c->get(ExerciseDispatcher::class),
$c->get(UserState::class),
$c->get(OutputInterface::class)
$c->get(OutputInterface::class),
);
},

Expand All @@ -251,15 +251,15 @@
$c->get('coreContributors'),
$c->get('appContributors'),
$c->get(OutputInterface::class),
$c->get(Color::class)
$c->get(Color::class),
);
},

HelpCommand::class => function (ContainerInterface $c) {
return new HelpCommand(
$c->get('appName'),
$c->get(OutputInterface::class),
$c->get(Color::class)
$c->get(Color::class),
);
},

Expand All @@ -269,14 +269,14 @@
},
PrepareSolutionListener::class => function (ContainerInterface $c) {
return new PrepareSolutionListener(
$c->get(ProcessFactory::class)
$c->get(ProcessFactory::class),
);
},
CodePatchListener::class => function (ContainerInterface $c) {
return new CodePatchListener(
$c->get(CodePatcher::class),
$c->get(LoggerInterface::class),
$c->get('debugMode')
$c->get('debugMode'),
);
},
SelfCheckListener::class => function (ContainerInterface $c) {
Expand All @@ -289,7 +289,7 @@
return new ConfigureCommandListener(
$c->get(UserState::class),
$c->get(ExerciseRepository::class),
$c->get(RunnerManager::class)
$c->get(RunnerManager::class),
);
},
RealPathListener::class => create(),
Expand Down Expand Up @@ -320,14 +320,14 @@
//Utils
Filesystem::class => create(),
Parser::class => function () {
$parserFactory = new ParserFactory;
$parserFactory = new ParserFactory();
return $parserFactory->create(ParserFactory::PREFER_PHP7);
},
CodePatcher::class => function (ContainerInterface $c) {
$patch = (new Patch())
->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'ini_set("display_errors", "1");'))
->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'error_reporting(E_ALL);'))
->withInsertion(new Insertion(Insertion ::TYPE_BEFORE, 'date_default_timezone_set("Europe/London");'));
->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'date_default_timezone_set("Europe/London");'));

return new CodePatcher($c->get(Parser::class), new Standard(), $c->get(LoggerInterface::class), $patch);
},
Expand All @@ -347,7 +347,7 @@
$c->get(Serializer::class),
$c->get(MarkdownRenderer::class),
$c->get(Color::class),
$c->get(OutputInterface::class)
$c->get(OutputInterface::class),
);
},
ContextSpecificRenderer::class => function (ContainerInterface $c) {
Expand All @@ -364,7 +364,7 @@

$environment = new Environment([
'renderer' => [
'width' => $terminal->getWidth()
'width' => $terminal->getWidth(),
],
]);

Expand All @@ -377,29 +377,29 @@
new Documentation(),
new Run($c->get('appName')),
new Verify($c->get('appName')),
$c->get(Context::class)
]
$c->get(Context::class),
],
));

return $environment;
},
MarkdownRenderer::class => function (ContainerInterface $c) {
return new MarkdownRenderer(
new DocParser($c->get(Environment::class)),
$c->get(ElementRendererInterface::class)
$c->get(ElementRendererInterface::class),
);
},
ElementRendererInterface::class => function (ContainerInterface $c) {
return new CliRenderer(
$c->get(Environment::class),
$c->get(Color::class)
$c->get(Color::class),
);
},
Serializer::class => function (ContainerInterface $c) {
return new LocalJsonSerializer(
getenv('HOME'),
$c->get('workshopTitle'),
$c->get(ExerciseRepository::class)
$c->get(ExerciseRepository::class),
);
},
UserState::class => function (ContainerInterface $c) {
Expand All @@ -409,15 +409,15 @@
return new ResetProgress($c->get(Serializer::class));
},
ResultRendererFactory::class => function (ContainerInterface $c) {
$factory = new ResultRendererFactory;
$factory = new ResultRendererFactory();
$factory->registerRenderer(FunctionRequirementsFailure::class, FunctionRequirementsFailureRenderer::class);
$factory->registerRenderer(Failure::class, FailureRenderer::class);
$factory->registerRenderer(
CgiResult::class,
CgiResultRenderer::class,
function (CgiResult $result) use ($c) {
return new CgiResultRenderer($result, $c->get(RequestRenderer::class));
}
},
);
$factory->registerRenderer(CgiGenericFailure::class, FailureRenderer::class);
$factory->registerRenderer(CgiRequestFailure::class, CgiRequestFailureRenderer::class);
Expand All @@ -439,12 +439,12 @@ function (CgiResult $result) use ($c) {
$c->get(Terminal::class),
$c->get(ExerciseRepository::class),
$c->get(KeyLighter::class),
$c->get(ResultRendererFactory::class)
$c->get(ResultRendererFactory::class),
);
},

KeyLighter::class => function () {
$keylighter = new KeyLighter;
$keylighter = new KeyLighter();
$keylighter->init();
return $keylighter;
},
Expand All @@ -453,26 +453,26 @@ function (CgiResult $result) use ($c) {
'@AydinHassan' => 'Aydin Hassan',
'@mikeymike' => 'Michael Woodward',
'@shakeyShane' => 'Shane Osbourne',
'@chris3ailey' => 'Chris Bailey'
'@chris3ailey' => 'Chris Bailey',
],
'appContributors' => [],
'eventListeners' => [
'realpath-student-submission' => [
'verify.start' => [
containerListener(RealPathListener::class)
containerListener(RealPathListener::class),
],
'run.start' => [
containerListener(RealPathListener::class)
containerListener(RealPathListener::class),
],
],
'check-exercise-assigned' => [
'route.pre.resolve.args' => [
containerListener(CheckExerciseAssignedListener::class)
containerListener(CheckExerciseAssignedListener::class),
],
],
'configure-command-arguments' => [
'route.pre.resolve.args' => [
containerListener(ConfigureCommandListener::class)
containerListener(ConfigureCommandListener::class),
],
],
'prepare-solution' => [
Expand Down Expand Up @@ -511,26 +511,26 @@ function (CgiResult $result) use ($c) {
],
'self-check' => [
'verify.post.check' => [
containerListener(SelfCheckListener::class)
containerListener(SelfCheckListener::class),
],
],
'create-initial-code' => [
'exercise.selected' => [
containerListener(InitialCodeListener::class)
]
containerListener(InitialCodeListener::class),
],
],
'cleanup-filesystem' => [
'application.tear-down' => [
containerListener(TearDownListener::class, 'cleanupTempDir')
]
containerListener(TearDownListener::class, 'cleanupTempDir'),
],
],
'decorate-run-output' => [
'cli.run.student-execute.pre' => [
containerListener(OutputRunInfoListener::class)
containerListener(OutputRunInfoListener::class),
],
'cgi.run.student-execute.pre' => [
containerListener(OutputRunInfoListener::class)
]
containerListener(OutputRunInfoListener::class),
],
],
],
];
29 changes: 18 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
"require-dev": {
"phpunit/phpunit": "^8.5",
"composer/composer": "^2.0",
"squizlabs/php_codesniffer": "^3.7",
"phpstan/phpstan": "^1.8",
"phpstan/extension-installer": "^1.0",
"yoast/phpunit-polyfills": "^0.2.0"
"yoast/phpunit-polyfills": "^0.2.0",
"bamarni/composer-bin-plugin": "^1.8"
},
"autoload" : {
"psr-4" : {
Expand All @@ -62,19 +62,26 @@
"@static"
],
"unit-tests": "phpunit",
"cs" : [
"phpcs src --standard=PSR12 --encoding=UTF-8 --exclude=Generic.Files.LineLength",
"phpcs test --standard=PSR12 --encoding=UTF-8 --exclude=Generic.Files.LineLength"
],
"cs-fix" : [
"phpcbf src --standard=PSR12 --encoding=UTF-8",
"phpcbf test --standard=PSR12 --encoding=UTF-8"
],
"cs" : "@cs-fix --dry-run",
"cs-fix" : "php-cs-fixer fix",
"static": "phpstan --ansi analyse --level max src"
},
"post-install-cmd": [
"@composer bin all install --ansi"
],
"post-update-cmd": [
"@composer bin all update --ansi"
],
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
"phpstan/extension-installer": true,
"bamarni/composer-bin-plugin": true
}
},
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": false
}
}
}
Loading

0 comments on commit 90a77ba

Please sign in to comment.