Skip to content

Commit 2402252

Browse files
committed
Migrate to php-cs-fixer
1 parent 638cb65 commit 2402252

File tree

188 files changed

+2655
-1058
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+2655
-1058
lines changed

Diff for: .github/workflows/php-workshop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
uses: shivammathur/setup-php@v2
2222
with:
2323
php-version: ${{ matrix.php }}
24-
tools: composer:v2
24+
tools: php-cs-fixer,composer:v2
2525
coverage: none
2626

2727
- name: Install Dependencies

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
program.php
44
.phpunit.result.cache
55
/build
6+
/vendor-bin/**/vendor/
7+
.php-cs-fixer.cache

Diff for: .php-cs-fixer.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
$finder = (new PhpCsFixer\Finder())
4+
->in(__DIR__)
5+
->exclude('test/res')
6+
;
7+
8+
return (new PhpCsFixer\Config())
9+
->setRules([
10+
'@PER-CS2.0' => true,
11+
'no_unused_imports' => true,
12+
])
13+
->setFinder($finder);

Diff for: app/config.php

+42-42
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
use PhpSchool\PhpWorkshop\Logger\ConsoleLogger;
5959
use PhpSchool\PhpWorkshop\Logger\Logger;
6060
use PhpSchool\PhpWorkshop\Markdown\CurrentContext;
61-
use PhpSchool\PhpWorkshop\Markdown\Parser\ContextSpecificBlockParser;
6261
use PhpSchool\PhpWorkshop\Markdown\ProblemFileExtension;
6362
use PhpSchool\PhpWorkshop\Markdown\Renderer\ContextSpecificRenderer;
6463
use PhpSchool\PhpWorkshop\Markdown\Shorthands\Cli\AppName;
@@ -104,6 +103,7 @@
104103
use Psr\Container\ContainerInterface;
105104
use Psr\Log\LoggerInterface;
106105
use Symfony\Component\Filesystem\Filesystem;
106+
107107
use function DI\create;
108108
use function DI\factory;
109109
use function PhpSchool\PhpWorkshop\canonicalise_path;
@@ -147,7 +147,7 @@
147147
$c->get(ComposerCheck::class),
148148
$c->get(FunctionRequirementsCheck::class),
149149
$c->get(DatabaseCheck::class),
150-
$c->get(FileComparisonCheck::class)
150+
$c->get(FileComparisonCheck::class),
151151
]);
152152
},
153153
CommandRouter::class => function (ContainerInterface $c) {
@@ -158,16 +158,16 @@
158158
new CommandDefinition('print', [], PrintCommand::class),
159159
new CommandDefinition('verify', [], VerifyCommand::class),
160160
new CommandDefinition('run', [], RunCommand::class),
161-
new CommandDefinition('credits', [], CreditsCommand::class)
161+
new CommandDefinition('credits', [], CreditsCommand::class),
162162
],
163163
'menu',
164164
$c->get(EventDispatcher::class),
165-
$c
165+
$c,
166166
);
167167
},
168168

169169
Color::class => function () {
170-
$colors = new Color;
170+
$colors = new Color();
171171
$colors->setForceStyle(true);
172172
return $colors;
173173
},
@@ -179,7 +179,7 @@
179179
return new ExerciseRepository(
180180
array_map(function ($exerciseClass) use ($c) {
181181
return $c->get($exerciseClass);
182-
}, $c->get('exercises'))
182+
}, $c->get('exercises')),
183183
);
184184
},
185185

@@ -196,12 +196,12 @@
196196
$manager->addFactory(new CliRunnerFactory(
197197
$c->get(EventDispatcher::class),
198198
$c->get(ProcessFactory::class),
199-
$c->get(EnvironmentManager::class)
199+
$c->get(EnvironmentManager::class),
200200
));
201201
$manager->addFactory(new CgiRunnerFactory(
202202
$c->get(EventDispatcher::class),
203203
$c->get(ProcessFactory::class),
204-
$c->get(EnvironmentManager::class)
204+
$c->get(EnvironmentManager::class),
205205
));
206206
$manager->addFactory(new CustomVerifyingRunnerFactory());
207207
return $manager;
@@ -222,7 +222,7 @@
222222
$c->get(ExerciseRepository::class),
223223
$c->get(UserState::class),
224224
$c->get(MarkdownRenderer::class),
225-
$c->get(OutputInterface::class)
225+
$c->get(OutputInterface::class),
226226
);
227227
},
228228

@@ -233,7 +233,7 @@
233233
$c->get(UserState::class),
234234
$c->get(Serializer::class),
235235
$c->get(OutputInterface::class),
236-
$c->get(ResultsRenderer::class)
236+
$c->get(ResultsRenderer::class),
237237
);
238238
},
239239

@@ -242,7 +242,7 @@
242242
$c->get(ExerciseRepository::class),
243243
$c->get(ExerciseDispatcher::class),
244244
$c->get(UserState::class),
245-
$c->get(OutputInterface::class)
245+
$c->get(OutputInterface::class),
246246
);
247247
},
248248

@@ -251,15 +251,15 @@
251251
$c->get('coreContributors'),
252252
$c->get('appContributors'),
253253
$c->get(OutputInterface::class),
254-
$c->get(Color::class)
254+
$c->get(Color::class),
255255
);
256256
},
257257

258258
HelpCommand::class => function (ContainerInterface $c) {
259259
return new HelpCommand(
260260
$c->get('appName'),
261261
$c->get(OutputInterface::class),
262-
$c->get(Color::class)
262+
$c->get(Color::class),
263263
);
264264
},
265265

@@ -269,14 +269,14 @@
269269
},
270270
PrepareSolutionListener::class => function (ContainerInterface $c) {
271271
return new PrepareSolutionListener(
272-
$c->get(ProcessFactory::class)
272+
$c->get(ProcessFactory::class),
273273
);
274274
},
275275
CodePatchListener::class => function (ContainerInterface $c) {
276276
return new CodePatchListener(
277277
$c->get(CodePatcher::class),
278278
$c->get(LoggerInterface::class),
279-
$c->get('debugMode')
279+
$c->get('debugMode'),
280280
);
281281
},
282282
SelfCheckListener::class => function (ContainerInterface $c) {
@@ -289,7 +289,7 @@
289289
return new ConfigureCommandListener(
290290
$c->get(UserState::class),
291291
$c->get(ExerciseRepository::class),
292-
$c->get(RunnerManager::class)
292+
$c->get(RunnerManager::class),
293293
);
294294
},
295295
RealPathListener::class => create(),
@@ -320,14 +320,14 @@
320320
//Utils
321321
Filesystem::class => create(),
322322
Parser::class => function () {
323-
$parserFactory = new ParserFactory;
323+
$parserFactory = new ParserFactory();
324324
return $parserFactory->create(ParserFactory::PREFER_PHP7);
325325
},
326326
CodePatcher::class => function (ContainerInterface $c) {
327327
$patch = (new Patch())
328328
->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'ini_set("display_errors", "1");'))
329329
->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'error_reporting(E_ALL);'))
330-
->withInsertion(new Insertion(Insertion ::TYPE_BEFORE, 'date_default_timezone_set("Europe/London");'));
330+
->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'date_default_timezone_set("Europe/London");'));
331331

332332
return new CodePatcher($c->get(Parser::class), new Standard(), $c->get(LoggerInterface::class), $patch);
333333
},
@@ -347,7 +347,7 @@
347347
$c->get(Serializer::class),
348348
$c->get(MarkdownRenderer::class),
349349
$c->get(Color::class),
350-
$c->get(OutputInterface::class)
350+
$c->get(OutputInterface::class),
351351
);
352352
},
353353
ContextSpecificRenderer::class => function (ContainerInterface $c) {
@@ -364,7 +364,7 @@
364364

365365
$environment = new Environment([
366366
'renderer' => [
367-
'width' => $terminal->getWidth()
367+
'width' => $terminal->getWidth(),
368368
],
369369
]);
370370

@@ -377,29 +377,29 @@
377377
new Documentation(),
378378
new Run($c->get('appName')),
379379
new Verify($c->get('appName')),
380-
$c->get(Context::class)
381-
]
380+
$c->get(Context::class),
381+
],
382382
));
383383

384384
return $environment;
385385
},
386386
MarkdownRenderer::class => function (ContainerInterface $c) {
387387
return new MarkdownRenderer(
388388
new DocParser($c->get(Environment::class)),
389-
$c->get(ElementRendererInterface::class)
389+
$c->get(ElementRendererInterface::class),
390390
);
391391
},
392392
ElementRendererInterface::class => function (ContainerInterface $c) {
393393
return new CliRenderer(
394394
$c->get(Environment::class),
395-
$c->get(Color::class)
395+
$c->get(Color::class),
396396
);
397397
},
398398
Serializer::class => function (ContainerInterface $c) {
399399
return new LocalJsonSerializer(
400400
getenv('HOME'),
401401
$c->get('workshopTitle'),
402-
$c->get(ExerciseRepository::class)
402+
$c->get(ExerciseRepository::class),
403403
);
404404
},
405405
UserState::class => function (ContainerInterface $c) {
@@ -409,15 +409,15 @@
409409
return new ResetProgress($c->get(Serializer::class));
410410
},
411411
ResultRendererFactory::class => function (ContainerInterface $c) {
412-
$factory = new ResultRendererFactory;
412+
$factory = new ResultRendererFactory();
413413
$factory->registerRenderer(FunctionRequirementsFailure::class, FunctionRequirementsFailureRenderer::class);
414414
$factory->registerRenderer(Failure::class, FailureRenderer::class);
415415
$factory->registerRenderer(
416416
CgiResult::class,
417417
CgiResultRenderer::class,
418418
function (CgiResult $result) use ($c) {
419419
return new CgiResultRenderer($result, $c->get(RequestRenderer::class));
420-
}
420+
},
421421
);
422422
$factory->registerRenderer(CgiGenericFailure::class, FailureRenderer::class);
423423
$factory->registerRenderer(CgiRequestFailure::class, CgiRequestFailureRenderer::class);
@@ -439,12 +439,12 @@ function (CgiResult $result) use ($c) {
439439
$c->get(Terminal::class),
440440
$c->get(ExerciseRepository::class),
441441
$c->get(KeyLighter::class),
442-
$c->get(ResultRendererFactory::class)
442+
$c->get(ResultRendererFactory::class),
443443
);
444444
},
445445

446446
KeyLighter::class => function () {
447-
$keylighter = new KeyLighter;
447+
$keylighter = new KeyLighter();
448448
$keylighter->init();
449449
return $keylighter;
450450
},
@@ -453,26 +453,26 @@ function (CgiResult $result) use ($c) {
453453
'@AydinHassan' => 'Aydin Hassan',
454454
'@mikeymike' => 'Michael Woodward',
455455
'@shakeyShane' => 'Shane Osbourne',
456-
'@chris3ailey' => 'Chris Bailey'
456+
'@chris3ailey' => 'Chris Bailey',
457457
],
458458
'appContributors' => [],
459459
'eventListeners' => [
460460
'realpath-student-submission' => [
461461
'verify.start' => [
462-
containerListener(RealPathListener::class)
462+
containerListener(RealPathListener::class),
463463
],
464464
'run.start' => [
465-
containerListener(RealPathListener::class)
465+
containerListener(RealPathListener::class),
466466
],
467467
],
468468
'check-exercise-assigned' => [
469469
'route.pre.resolve.args' => [
470-
containerListener(CheckExerciseAssignedListener::class)
470+
containerListener(CheckExerciseAssignedListener::class),
471471
],
472472
],
473473
'configure-command-arguments' => [
474474
'route.pre.resolve.args' => [
475-
containerListener(ConfigureCommandListener::class)
475+
containerListener(ConfigureCommandListener::class),
476476
],
477477
],
478478
'prepare-solution' => [
@@ -511,26 +511,26 @@ function (CgiResult $result) use ($c) {
511511
],
512512
'self-check' => [
513513
'verify.post.check' => [
514-
containerListener(SelfCheckListener::class)
514+
containerListener(SelfCheckListener::class),
515515
],
516516
],
517517
'create-initial-code' => [
518518
'exercise.selected' => [
519-
containerListener(InitialCodeListener::class)
520-
]
519+
containerListener(InitialCodeListener::class),
520+
],
521521
],
522522
'cleanup-filesystem' => [
523523
'application.tear-down' => [
524-
containerListener(TearDownListener::class, 'cleanupTempDir')
525-
]
524+
containerListener(TearDownListener::class, 'cleanupTempDir'),
525+
],
526526
],
527527
'decorate-run-output' => [
528528
'cli.run.student-execute.pre' => [
529-
containerListener(OutputRunInfoListener::class)
529+
containerListener(OutputRunInfoListener::class),
530530
],
531531
'cgi.run.student-execute.pre' => [
532-
containerListener(OutputRunInfoListener::class)
533-
]
532+
containerListener(OutputRunInfoListener::class),
533+
],
534534
],
535535
],
536536
];

Diff for: composer.json

+18-11
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
"require-dev": {
3737
"phpunit/phpunit": "^8.5",
3838
"composer/composer": "^2.0",
39-
"squizlabs/php_codesniffer": "^3.7",
4039
"phpstan/phpstan": "^1.8",
4140
"phpstan/extension-installer": "^1.0",
42-
"yoast/phpunit-polyfills": "^0.2.0"
41+
"yoast/phpunit-polyfills": "^0.2.0",
42+
"bamarni/composer-bin-plugin": "^1.8"
4343
},
4444
"autoload" : {
4545
"psr-4" : {
@@ -62,19 +62,26 @@
6262
"@static"
6363
],
6464
"unit-tests": "phpunit",
65-
"cs" : [
66-
"phpcs src --standard=PSR12 --encoding=UTF-8 --exclude=Generic.Files.LineLength",
67-
"phpcs test --standard=PSR12 --encoding=UTF-8 --exclude=Generic.Files.LineLength"
68-
],
69-
"cs-fix" : [
70-
"phpcbf src --standard=PSR12 --encoding=UTF-8",
71-
"phpcbf test --standard=PSR12 --encoding=UTF-8"
72-
],
65+
"cs" : "@cs-fix --dry-run",
66+
"cs-fix" : "php-cs-fixer fix",
7367
"static": "phpstan --ansi analyse --level max src"
7468
},
69+
"post-install-cmd": [
70+
"@composer bin all install --ansi"
71+
],
72+
"post-update-cmd": [
73+
"@composer bin all update --ansi"
74+
],
7575
"config": {
7676
"allow-plugins": {
77-
"phpstan/extension-installer": true
77+
"phpstan/extension-installer": true,
78+
"bamarni/composer-bin-plugin": true
79+
}
80+
},
81+
"extra": {
82+
"bamarni-bin": {
83+
"bin-links": true,
84+
"forward-command": false
7885
}
7986
}
8087
}

0 commit comments

Comments
 (0)