Skip to content

Commit 581f5e9

Browse files
committed
phpstan max level
1 parent d703e7b commit 581f5e9

File tree

67 files changed

+565
-361
lines changed

Some content is hidden

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

67 files changed

+565
-361
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
"squizlabs/php_codesniffer": "^3.4",
3737
"symfony/phpunit-bridge": "^5.1",
3838
"phpstan/phpstan": "^0.12.50",
39-
"timeweb/phpstan-enum": "^2.2"
39+
"timeweb/phpstan-enum": "^2.2",
40+
"phpstan/extension-installer": "^1.0",
41+
"phpstan/phpstan-symfony": "^0.12.8"
4042
},
4143
"autoload" : {
4244
"psr-4" : {
@@ -57,6 +59,6 @@
5759
"phpcs src --standard=PSR12 --encoding=UTF-8",
5860
"phpcs test --standard=PSR12 --encoding=UTF-8"
5961
],
60-
"static": "phpstan --ansi analyse --level 6 src"
62+
"static": "phpstan --ansi analyse --level max src"
6163
}
6264
}

composer.lock

Lines changed: 116 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
parameters:
22
treatPhpDocTypesAsCertain: false
3-
3+
ignoreErrors:
4+
-
5+
message: '#PhpSchool\\PhpWorkshop\\ExerciseRunner\\CliRunner\:\:preserveOldArgFormat\(\) should return#'
6+
path: src/ExerciseRunner/CliRunner.php
7+
-
8+
message: '#Call to an undefined method PhpParser\\Node\\Expr\|PhpParser\\Node\\Name\:\:__toString\(\)#'
9+
path: src/Check/FunctionRequirementsCheck.php

src/Application.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ final class Application
2222
private $workshopTitle;
2323

2424
/**
25-
* @var array
25+
* @var array<class-string>
2626
*/
2727
private $checks = [];
2828

2929
/**
30-
* @var class-string[]
30+
* @var array<class-string>
3131
*/
3232
private $exercises = [];
3333

3434
/**
35-
* @var array
35+
* @var array<array{resultClass: class-string, resultRendererClass: class-string}>
3636
*/
3737
private $results = [];
3838

@@ -68,7 +68,7 @@ final class Application
6868
* @param string $workshopTitle The workshop title - this is used throughout the application
6969
* @param string $diConfigFile The absolute path to the DI configuration file
7070
*/
71-
public function __construct($workshopTitle, $diConfigFile)
71+
public function __construct(string $workshopTitle, string $diConfigFile)
7272
{
7373
Assertion::string($workshopTitle);
7474
Assertion::file($diConfigFile);
@@ -81,9 +81,9 @@ public function __construct($workshopTitle, $diConfigFile)
8181
* Register a custom check with the application. Exercises will only be able to use the check
8282
* if it has been registered here.
8383
*
84-
* @param string $check The FQCN of the check
84+
* @param class-string $check The FQCN of the check
8585
*/
86-
public function addCheck($check)
86+
public function addCheck(string $check): void
8787
{
8888
$this->checks[] = $check;
8989
}
@@ -94,16 +94,16 @@ public function addCheck($check)
9494
*
9595
* @param class-string $exercise The FQCN of the check
9696
*/
97-
public function addExercise($exercise)
97+
public function addExercise(string $exercise): void
9898
{
9999
$this->exercises[] = $exercise;
100100
}
101101

102102
/**
103-
* @param string $resultClass
104-
* @param string $resultRendererClass
103+
* @param class-string $resultClass
104+
* @param class-string $resultRendererClass
105105
*/
106-
public function addResult($resultClass, $resultRendererClass)
106+
public function addResult(string $resultClass, string $resultRendererClass): void
107107
{
108108
Assertion::classExists($resultClass);
109109
Assertion::classExists($resultRendererClass);
@@ -120,7 +120,7 @@ public function addResult($resultClass, $resultRendererClass)
120120
*
121121
* @param string $logo The logo
122122
*/
123-
public function setLogo($logo)
123+
public function setLogo(string $logo): void
124124
{
125125
Assertion::string($logo);
126126
$this->logo = $logo;
@@ -132,7 +132,7 @@ public function setLogo($logo)
132132
*
133133
* @param string $colour The colour
134134
*/
135-
public function setFgColour($colour)
135+
public function setFgColour(string $colour): void
136136
{
137137
Assertion::string($colour);
138138
$this->fgColour = $colour;
@@ -144,7 +144,7 @@ public function setFgColour($colour)
144144
*
145145
* @param string $colour The colour
146146
*/
147-
public function setBgColour($colour)
147+
public function setBgColour(string $colour): void
148148
{
149149
Assertion::string($colour);
150150
$this->bgColour = $colour;
@@ -156,7 +156,7 @@ public function setBgColour($colour)
156156
*
157157
* @return int The exit code
158158
*/
159-
public function run()
159+
public function run(): int
160160
{
161161
$container = $this->getContainer();
162162

@@ -218,7 +218,7 @@ public function run()
218218
/**
219219
* @return \DI\Container
220220
*/
221-
private function getContainer()
221+
private function getContainer(): \DI\Container
222222
{
223223
$containerBuilder = new ContainerBuilder();
224224
$containerBuilder->addDefinitions(

src/Check/CheckRepository.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
class CheckRepository
1212
{
1313
/**
14-
* @var CheckInterface[]
14+
* @var array<CheckInterface>
1515
*/
1616
private $checks = [];
1717

1818
/**
19-
* @param CheckInterface[] $checks An array of checks available to the workshop framework.
19+
* @param array<CheckInterface> $checks An array of checks available to the workshop framework.
2020
*/
2121
public function __construct(array $checks = [])
2222
{
@@ -27,6 +27,7 @@ public function __construct(array $checks = [])
2727

2828
/**
2929
* Add a new check to the repository.
30+
* @param CheckInterface $check
3031
*/
3132
public function registerCheck(CheckInterface $check): void
3233
{
@@ -36,7 +37,7 @@ public function registerCheck(CheckInterface $check): void
3637
/**
3738
* Get all of the checks in the repository.
3839
*
39-
* @return array
40+
* @return array<CheckInterface>
4041
*/
4142
public function getAll(): array
4243
{
@@ -61,6 +62,9 @@ public function getByClass(string $class): CheckInterface
6162

6263
/**
6364
* Query whether a check instance exists in this repository via its class name.
65+
*
66+
* @param string $class
67+
* @return bool
6468
*/
6569
public function has(string $class): bool
6670
{

src/Check/CodeParseCheck.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ public function getName(): string
5151
*/
5252
public function check(ExerciseInterface $exercise, Input $input): ResultInterface
5353
{
54-
55-
$code = file_get_contents($input->getArgument('program'));
54+
$code = (string) file_get_contents($input->getRequiredArgument('program'));
5655

5756
try {
5857
$this->parser->parse($code);
5958
} catch (Error $e) {
60-
return Failure::fromCheckAndCodeParseFailure($this, $e, $input->getArgument('program'));
59+
return Failure::fromCheckAndCodeParseFailure($this, $e, $input->getRequiredArgument('program'));
6160
}
6261

6362
return Success::fromCheck($this);

src/Check/ComposerCheck.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ public function check(ExerciseInterface $exercise, Input $input): ResultInterfac
4141
throw new \InvalidArgumentException();
4242
}
4343

44-
if (!file_exists(sprintf('%s/composer.json', dirname($input->getArgument('program'))))) {
44+
if (!file_exists(sprintf('%s/composer.json', dirname($input->getRequiredArgument('program'))))) {
4545
return new Failure($this->getName(), 'No composer.json file found');
4646
}
4747

48-
if (!file_exists(sprintf('%s/composer.lock', dirname($input->getArgument('program'))))) {
48+
if (!file_exists(sprintf('%s/composer.lock', dirname($input->getRequiredArgument('program'))))) {
4949
return new Failure($this->getName(), 'No composer.lock file found');
5050
}
5151

52-
if (!file_exists(sprintf('%s/vendor', dirname($input->getArgument('program'))))) {
52+
if (!file_exists(sprintf('%s/vendor', dirname($input->getRequiredArgument('program'))))) {
5353
return new Failure($this->getName(), 'No vendor folder found');
5454
}
5555

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

src/Check/FileExistsCheck.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ public function getName(): string
3131
*/
3232
public function check(ExerciseInterface $exercise, Input $input): ResultInterface
3333
{
34-
if (file_exists($input->getArgument('program'))) {
34+
if (file_exists($input->getRequiredArgument('program'))) {
3535
return Success::fromCheck($this);
3636
}
3737

38-
return Failure::fromCheckAndReason($this, sprintf('File: "%s" does not exist', $input->getArgument('program')));
38+
return Failure::fromCheckAndReason(
39+
$this,
40+
sprintf('File: "%s" does not exist', $input->getRequiredArgument('program'))
41+
);
3942
}
4043

4144
/**

0 commit comments

Comments
 (0)