Skip to content

Commit 12b5cc2

Browse files
authored
Merge pull request #165 from php-school/phpcs12
PSR-12
2 parents e06c2fa + 0aa0501 commit 12b5cc2

File tree

124 files changed

+717
-738
lines changed

Some content is hidden

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

124 files changed

+717
-738
lines changed

appveyor.yml

-28
This file was deleted.

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
},
5353
"scripts" : {
5454
"cs" : [
55-
"phpcs src --standard=PSR2 --encoding=UTF-8",
56-
"phpcs test --standard=PSR2 --encoding=UTF-8"
55+
"phpcs src --standard=PSR12 --encoding=UTF-8",
56+
"phpcs test --standard=PSR12 --encoding=UTF-8"
5757
]
5858
}
5959
}

src/Application.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function run()
220220
*/
221221
private function getContainer()
222222
{
223-
$containerBuilder = new ContainerBuilder;
223+
$containerBuilder = new ContainerBuilder();
224224
$containerBuilder->addDefinitions(
225225
array_merge_recursive(
226226
require $this->frameworkConfigLocation,

src/Check/CheckInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ interface CheckInterface
1010
/**
1111
* Return the check's name
1212
*/
13-
public function getName() : string;
13+
public function getName(): string;
1414

1515
/**
1616
* This returns the interface the exercise should implement
1717
* when requiring this check. It should be the FQCN of the interface.
1818
*/
19-
public function getExerciseInterface() : string;
19+
public function getExerciseInterface(): string;
2020
}

src/Check/CheckRepository.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(array $checks = [])
2828
/**
2929
* Add a new check to the repository.
3030
*/
31-
public function registerCheck(CheckInterface $check) : void
31+
public function registerCheck(CheckInterface $check): void
3232
{
3333
$this->checks[get_class($check)] = $check;
3434
}
@@ -38,7 +38,7 @@ public function registerCheck(CheckInterface $check) : void
3838
*
3939
* @return array
4040
*/
41-
public function getAll() : array
41+
public function getAll(): array
4242
{
4343
return array_values($this->checks);
4444
}
@@ -50,7 +50,7 @@ public function getAll() : array
5050
* @return CheckInterface The instance.
5151
* @throws InvalidArgumentException If an instance of the check does not exist.
5252
*/
53-
public function getByClass(string $class) : CheckInterface
53+
public function getByClass(string $class): CheckInterface
5454
{
5555
if (!isset($this->checks[$class])) {
5656
throw new InvalidArgumentException(sprintf('Check: "%s" does not exist', $class));
@@ -62,7 +62,7 @@ public function getByClass(string $class) : CheckInterface
6262
/**
6363
* Query whether a check instance exists in this repository via its class name.
6464
*/
65-
public function has(string $class) : bool
65+
public function has(string $class): bool
6666
{
6767
try {
6868
$this->getByClass($class);

src/Check/CodeParseCheck.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(Parser $parser)
3535
/**
3636
* Return the check's name
3737
*/
38-
public function getName() : string
38+
public function getName(): string
3939
{
4040
return 'Code Parse Check';
4141
}
@@ -49,7 +49,7 @@ public function getName() : string
4949
* @param Input $input The command line arguments passed to the command.
5050
* @return ResultInterface The result of the check.
5151
*/
52-
public function check(ExerciseInterface $exercise, Input $input) : ResultInterface
52+
public function check(ExerciseInterface $exercise, Input $input): ResultInterface
5353
{
5454

5555
$code = file_get_contents($input->getArgument('program'));
@@ -66,15 +66,15 @@ public function check(ExerciseInterface $exercise, Input $input) : ResultInterfa
6666
/**
6767
* This check can run on any exercise type.
6868
*/
69-
public function canRun(ExerciseType $exerciseType) : bool
69+
public function canRun(ExerciseType $exerciseType): bool
7070
{
7171
return in_array($exerciseType->getValue(), [ExerciseType::CGI, ExerciseType::CLI], true);
7272
}
7373

7474
/**
7575
* @return string
7676
*/
77-
public function getExerciseInterface() : string
77+
public function getExerciseInterface(): string
7878
{
7979
return ExerciseInterface::class;
8080
}
@@ -83,7 +83,7 @@ public function getExerciseInterface() : string
8383
* This check should be run before executing the student's solution, as, if it cannot be parsed
8484
* it probably cannot be executed.
8585
*/
86-
public function getPosition() : string
86+
public function getPosition(): string
8787
{
8888
return SimpleCheckInterface::CHECK_BEFORE;
8989
}

src/Check/ComposerCheck.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ComposerCheck implements SimpleCheckInterface
2121
/**
2222
* Return the check's name
2323
*/
24-
public function getName() : string
24+
public function getName(): string
2525
{
2626
return 'Composer Dependency Check';
2727
}
@@ -35,10 +35,10 @@ public function getName() : string
3535
* @param Input $input The command line arguments passed to the command.
3636
* @return ResultInterface The result of the check.
3737
*/
38-
public function check(ExerciseInterface $exercise, Input $input) : ResultInterface
38+
public function check(ExerciseInterface $exercise, Input $input): ResultInterface
3939
{
4040
if (!$exercise instanceof ComposerExerciseCheck) {
41-
throw new \InvalidArgumentException;
41+
throw new \InvalidArgumentException();
4242
}
4343

4444
if (!file_exists(sprintf('%s/composer.json', dirname($input->getArgument('program'))))) {
@@ -74,20 +74,20 @@ public function check(ExerciseInterface $exercise, Input $input) : ResultInterfa
7474
/**
7575
* This check can run on any exercise type.
7676
*/
77-
public function canRun(ExerciseType $exerciseType) : bool
77+
public function canRun(ExerciseType $exerciseType): bool
7878
{
7979
return in_array($exerciseType->getValue(), [ExerciseType::CGI, ExerciseType::CLI], true);
8080
}
8181

82-
public function getExerciseInterface() : string
82+
public function getExerciseInterface(): string
8383
{
8484
return ComposerExerciseCheck::class;
8585
}
8686

8787
/**
8888
* This check can run before because if it fails, there is no point executing the solution.
8989
*/
90-
public function getPosition() : string
90+
public function getPosition(): string
9191
{
9292
return SimpleCheckInterface::CHECK_BEFORE;
9393
}

src/Check/DatabaseCheck.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ public function __construct()
6161
/**
6262
* Return the check's name
6363
*/
64-
public function getName() : string
64+
public function getName(): string
6565
{
6666
return 'Database Verification Check';
6767
}
6868

69-
public function getExerciseInterface() : string
69+
public function getExerciseInterface(): string
7070
{
7171
return DatabaseExerciseCheck::class;
7272
}
@@ -75,7 +75,7 @@ public function getExerciseInterface() : string
7575
* Here we attach to various events to seed, verify and inject the DSN's
7676
* to the student & reference solution programs's CLI arguments.
7777
*/
78-
public function attach(EventDispatcher $eventDispatcher) : void
78+
public function attach(EventDispatcher $eventDispatcher): void
7979
{
8080
if (file_exists($this->databaseDirectory)) {
8181
throw new \RuntimeException(

src/Check/FileExistsCheck.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class FileExistsCheck implements SimpleCheckInterface
1717
/**
1818
* Return the check's name.
1919
*/
20-
public function getName() : string
20+
public function getName(): string
2121
{
2222
return 'File Exists Check';
2323
}
@@ -29,7 +29,7 @@ public function getName() : string
2929
* @param Input $input The command line arguments passed to the command.
3030
* @return ResultInterface The result of the check.
3131
*/
32-
public function check(ExerciseInterface $exercise, Input $input) : ResultInterface
32+
public function check(ExerciseInterface $exercise, Input $input): ResultInterface
3333
{
3434
if (file_exists($input->getArgument('program'))) {
3535
return Success::fromCheck($this);
@@ -41,20 +41,20 @@ public function check(ExerciseInterface $exercise, Input $input) : ResultInterfa
4141
/**
4242
* This check can run on any exercise type.
4343
*/
44-
public function canRun(ExerciseType $exerciseType) : bool
44+
public function canRun(ExerciseType $exerciseType): bool
4545
{
4646
return in_array($exerciseType->getValue(), [ExerciseType::CGI, ExerciseType::CLI], true);
4747
}
4848

49-
public function getExerciseInterface() : string
49+
public function getExerciseInterface(): string
5050
{
5151
return ExerciseInterface::class;
5252
}
5353

5454
/**
5555
* This check must run before executing the solution becuase it may not exist.
5656
*/
57-
public function getPosition() : string
57+
public function getPosition(): string
5858
{
5959
return SimpleCheckInterface::CHECK_BEFORE;
6060
}

src/Check/FunctionRequirementsCheck.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(Parser $parser)
3939
/**
4040
* Return the check's name.
4141
*/
42-
public function getName() : string
42+
public function getName(): string
4343
{
4444
return 'Function Requirements Check';
4545
}
@@ -53,10 +53,10 @@ public function getName() : string
5353
* @param Input $input The command line arguments passed to the command.
5454
* @return ResultInterface The result of the check.
5555
*/
56-
public function check(ExerciseInterface $exercise, Input $input) : ResultInterface
56+
public function check(ExerciseInterface $exercise, Input $input): ResultInterface
5757
{
5858
if (!$exercise instanceof FunctionRequirementsExerciseCheck) {
59-
throw new \InvalidArgumentException;
59+
throw new \InvalidArgumentException();
6060
}
6161

6262
$requiredFunctions = $exercise->getRequiredFunctions();
@@ -71,7 +71,7 @@ public function check(ExerciseInterface $exercise, Input $input) : ResultInterfa
7171
}
7272

7373
$visitor = new FunctionVisitor($requiredFunctions, $bannedFunctions);
74-
$traverser = new NodeTraverser;
74+
$traverser = new NodeTraverser();
7575
$traverser->addVisitor($visitor);
7676

7777
$traverser->traverse($ast);
@@ -98,12 +98,12 @@ public function check(ExerciseInterface $exercise, Input $input) : ResultInterfa
9898
/**
9999
* This check can run on any exercise type.
100100
*/
101-
public function canRun(ExerciseType $exerciseType) : bool
101+
public function canRun(ExerciseType $exerciseType): bool
102102
{
103103
return in_array($exerciseType->getValue(), [ExerciseType::CGI, ExerciseType::CLI], true);
104104
}
105105

106-
public function getExerciseInterface() : string
106+
public function getExerciseInterface(): string
107107
{
108108
return FunctionRequirementsExerciseCheck::class;
109109
}
@@ -113,7 +113,7 @@ public function getExerciseInterface() : string
113113
* output, but do it in a way that was not correct for the task. This way the student can see the program works
114114
* but missed some requirements.
115115
*/
116-
public function getPosition() : string
116+
public function getPosition(): string
117117
{
118118
return SimpleCheckInterface::CHECK_AFTER;
119119
}

src/Check/ListenableCheckInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ interface ListenableCheckInterface extends CheckInterface
1313
* Attach to events throughout the running/verifying process. Inject verifiers
1414
* and listeners.
1515
*/
16-
public function attach(EventDispatcher $eventDispatcher) : void;
16+
public function attach(EventDispatcher $eventDispatcher): void;
1717
}

src/Check/PhpLintCheck.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class PhpLintCheck implements SimpleCheckInterface
2020
/**
2121
* Return the check's name
2222
*/
23-
public function getName() : string
23+
public function getName(): string
2424
{
2525
return 'PHP Code Check';
2626
}
@@ -32,7 +32,7 @@ public function getName() : string
3232
* @param Input $input The command line arguments passed to the command.
3333
* @return ResultInterface The result of the check.
3434
*/
35-
public function check(ExerciseInterface $exercise, Input $input) : ResultInterface
35+
public function check(ExerciseInterface $exercise, Input $input): ResultInterface
3636
{
3737
$process = new Process([PHP_BINARY, '-l', $input->getArgument('program')]);
3838
$process->run();
@@ -47,12 +47,12 @@ public function check(ExerciseInterface $exercise, Input $input) : ResultInterfa
4747
/**
4848
* This check can run on any exercise type.
4949
*/
50-
public function canRun(ExerciseType $exerciseType) : bool
50+
public function canRun(ExerciseType $exerciseType): bool
5151
{
5252
return in_array($exerciseType->getValue(), [ExerciseType::CGI, ExerciseType::CLI], true);
5353
}
5454

55-
public function getExerciseInterface() : string
55+
public function getExerciseInterface(): string
5656
{
5757
return ExerciseInterface::class;
5858
}
@@ -61,7 +61,7 @@ public function getExerciseInterface() : string
6161
* This check should be run before executing the student's solution, as, if it cannot be linted
6262
* it probably cannot be executed.
6363
*/
64-
public function getPosition() : string
64+
public function getPosition(): string
6565
{
6666
return SimpleCheckInterface::CHECK_BEFORE;
6767
}

src/Check/SimpleCheckInterface.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface SimpleCheckInterface extends CheckInterface
3030
/**
3131
* Can this check run this exercise?
3232
*/
33-
public function canRun(ExerciseType $exerciseType) : bool;
33+
public function canRun(ExerciseType $exerciseType): bool;
3434

3535
/**
3636
* The check is ran against an exercise and a filename which
@@ -45,12 +45,12 @@ public function canRun(ExerciseType $exerciseType) : bool;
4545
* @param Input $input The command line arguments passed to the command.
4646
* @return ResultInterface The result of the check.
4747
*/
48-
public function check(ExerciseInterface $exercise, Input $input) : ResultInterface;
48+
public function check(ExerciseInterface $exercise, Input $input): ResultInterface;
4949

5050
/**
5151
* Either `static::CHECK_BEFORE` | `static::CHECK_AFTER`.
5252
*
5353
* @return string
5454
*/
55-
public function getPosition() : string;
55+
public function getPosition(): string;
5656
}

src/CodeInsertion.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class CodeInsertion
1414
* Denotes that the block of code this insertion
1515
* represents, should be inserted at the top of the solution.
1616
*/
17-
const TYPE_BEFORE = 'before';
17+
public const TYPE_BEFORE = 'before';
1818

1919
/**
2020
* Denotes that the block of code this insertion
2121
* represents, should be inserted at the bottom of the solution.
2222
*/
23-
const TYPE_AFTER = 'after';
23+
public const TYPE_AFTER = 'after';
2424

2525
/**
2626
* @var array

0 commit comments

Comments
 (0)