Skip to content

Commit 8af2233

Browse files
committed
phpstan max
1 parent 4bb5b82 commit 8af2233

25 files changed

+154
-90
lines changed

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
"php" : ">=7.2",
1616
"ext-pdo_sqlite": "*",
1717
"php-school/php-workshop": "dev-master",
18-
"hoa/socket": "^1.0"
18+
"hoa/socket": "^1.17.05",
19+
"phpstan/phpstan": "^0.12.52"
1920
},
2021
"require-dev": {
21-
"phpunit/phpunit": "^7.0 | ^8.0",
22+
"phpunit/phpunit": "^7.0 | ^8.0 ",
2223
"squizlabs/php_codesniffer": "^3.5"
2324
},
2425
"autoload" : {
@@ -42,6 +43,7 @@
4243
"cs-fix" : [
4344
"phpcbf src --standard=PSR12 --encoding=UTF-8",
4445
"phpcbf test --standard=PSR12 --encoding=UTF-8"
45-
]
46+
],
47+
"static": "phpstan --ansi analyse --level max src"
4648
}
4749
}

composer.lock

Lines changed: 77 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan-bootstrap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
class_exists(\Hoa\Socket\Connection::class);
6+
class_exists(\Hoa\Exception::class);

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
bootstrapFiles:
3+
- phpstan-bootstrap.php

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit colors="true">
3+
<phpunit colors="true" bootstrap="test/bootstrap.php">
44
<testsuite name="My PHP Workshop Test Suite">
55
<directory>./test</directory>
66
</testsuite>

src/Exercise/ArrayWeGo.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function getDescription(): string
5555
}
5656

5757
/**
58-
* @return array
58+
* @return array<array<string>>
5959
*/
6060
public function getArgs(): array
6161
{
@@ -73,12 +73,9 @@ public function getArgs(): array
7373
$files[] = $file;
7474
}
7575

76-
return $files;
76+
return [$files];
7777
}
7878

79-
/**
80-
* @return null
81-
*/
8279
public function tearDown(): void
8380
{
8481
$this->filesystem->remove($this->getTemporaryPath());
@@ -105,7 +102,7 @@ public function getBannedFunctions(): array
105102
*/
106103
public function getType(): ExerciseType
107104
{
108-
return ExerciseType::CLI();
105+
return new ExerciseType(ExerciseType::CLI);
109106
}
110107

111108
/**

src/Exercise/BabySteps.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@ public function getDescription(): string
2828
}
2929

3030
/**
31-
* @return array
31+
* @return array<array<string>>
3232
*/
3333
public function getArgs(): array
3434
{
3535
$numArgs = rand(0, 10);
3636

3737
$args = [];
3838
for ($i = 0; $i < $numArgs; $i++) {
39-
$args[] = rand(0, 100);
39+
$args[] = (string) rand(0, 100);
4040
}
4141

42-
return $args;
42+
return [$args];
4343
}
4444

4545
/**
4646
* @return ExerciseType
4747
*/
4848
public function getType(): ExerciseType
4949
{
50-
return ExerciseType::CLI();
50+
return new ExerciseType(ExerciseType::CLI);
5151
}
5252
}

src/Exercise/ConcernedAboutSeparation.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function getDescription(): string
7070
}
7171

7272
/**
73-
* @return array
73+
* @return array<array<string>>
7474
*/
7575
public function getArgs(): array
7676
{
@@ -109,7 +109,7 @@ public function getArgs(): array
109109
$ext = pathinfo($files[$index], PATHINFO_EXTENSION);
110110
}
111111

112-
return [$folder, $ext];
112+
return [[$folder, $ext]];
113113
}
114114

115115
/**
@@ -120,9 +120,6 @@ public function getSolution(): SolutionInterface
120120
return DirectorySolution::fromDirectory(__DIR__ . '/../../exercises/concerned-about-separation/solution');
121121
}
122122

123-
/**
124-
* @return null
125-
*/
126123
public function tearDown(): void
127124
{
128125
$this->filesystem->remove($this->getTemporaryPath());
@@ -134,7 +131,11 @@ public function tearDown(): void
134131
*/
135132
public function check(Input $input): ResultInterface
136133
{
137-
$statements = $this->parser->parse(file_get_contents($input->getArgument('program')));
134+
$statements = $this->parser->parse((string) file_get_contents($input->getRequiredArgument('program')));
135+
136+
if (null === $statements) {
137+
return Failure::fromNameAndReason($this->getName(), 'No code was found');
138+
}
138139

139140
$include = null;
140141
foreach ($statements as $statement) {
@@ -156,6 +157,6 @@ public function check(Input $input): ResultInterface
156157
*/
157158
public function getType(): ExerciseType
158159
{
159-
return ExerciseType::CLI();
160+
return new ExerciseType(ExerciseType::CLI);
160161
}
161162
}

src/Exercise/DatabaseRead.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DatabaseRead extends AbstractExercise implements ExerciseInterface, Databa
2626
private $faker;
2727

2828
/**
29-
* @var array
29+
* @var array{id: int, name: string}
3030
*/
3131
private $randomRecord;
3232

@@ -55,11 +55,11 @@ public function getDescription(): string
5555
}
5656

5757
/**
58-
* @return array
58+
* @return array<array<string>>
5959
*/
6060
public function getArgs(): array
6161
{
62-
return [$this->randomRecord['name']];
62+
return [[$this->randomRecord['name']]];
6363
}
6464

6565
/**
@@ -79,12 +79,11 @@ public function seed(PDO $db): void
7979
$gender = rand(0, 100) % 2 ? 'male' : 'female';
8080

8181
$stmt->execute([':name' => $name, ':age' => $age, ':gender' => $gender]);
82-
$id = $db->lastInsertId();
83-
$names[$id] = $name;
82+
$names[(int) $db->lastInsertId()] = $name;
8483
}
8584

86-
$randomId = array_rand($names);
87-
$this->randomRecord = ['id' => $randomId, 'name' => $names[$randomId]];
85+
$randomId = (int) array_rand($names);
86+
$this->randomRecord = ['id' => $randomId, 'name' => (string) $names[$randomId]];
8887
}
8988

9089
/**
@@ -107,7 +106,7 @@ public function verify(PDO $db): bool
107106
*/
108107
public function getType(): ExerciseType
109108
{
110-
return ExerciseType::CLI();
109+
return new ExerciseType(ExerciseType::CLI);
111110
}
112111

113112
/**

src/Exercise/DependencyHeaven.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private function newApiRequest(string $endpoint): RequestInterface
9191
}
9292

9393
/**
94-
* @return array
94+
* @return array<string>
9595
*/
9696
public function getRequiredPackages(): array
9797
{
@@ -106,7 +106,7 @@ public function getRequiredPackages(): array
106106
*/
107107
public function getType(): ExerciseType
108108
{
109-
return ExerciseType::CGI();
109+
return new ExerciseType(ExerciseType::CGI);
110110
}
111111

112112
/**

0 commit comments

Comments
 (0)