Skip to content

Commit ed92430

Browse files
committed
Add phpstan
1 parent 8ac05cf commit ed92430

File tree

12 files changed

+149
-58
lines changed

12 files changed

+149
-58
lines changed

.circleci/config.yml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ jobs:
2727
steps:
2828
- checkout
2929
- restore_cache:
30-
key: vendor-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
30+
key: vendor-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
3131
- run:
32-
name: composer-require-checker
33-
command: bin/composerRequireChecker
32+
name: composer-require-checker
33+
command: bin/composerRequireChecker
3434

3535
phpcs:
3636
docker:
@@ -39,8 +39,8 @@ jobs:
3939
steps:
4040
- checkout
4141
- run:
42-
name: phpcs
43-
command: bin/phpcs
42+
name: phpcs
43+
command: bin/phpcs
4444

4545
phpcf:
4646
docker:
@@ -49,8 +49,20 @@ jobs:
4949
steps:
5050
- checkout
5151
- run:
52-
name: phpcf
53-
command: bin/phpcf
52+
name: phpcf
53+
command: bin/phpcf
54+
55+
phpstan:
56+
docker:
57+
- image: php:7.4-cli-alpine3.10
58+
working_directory: /app
59+
steps:
60+
- checkout
61+
- restore_cache:
62+
key: vendor-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
63+
- run:
64+
name: phpstan
65+
command: bin/phpstan
5466

5567
workflows:
5668
version: '2.1'
@@ -60,5 +72,8 @@ workflows:
6072
- phpcf
6173
- composer
6274
- composerRequireChecker:
63-
requires:
64-
- composer
75+
requires:
76+
- composer
77+
- phpstan:
78+
requires:
79+
- composer

bin/phpstan

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env sh
2+
3+
set -eu
4+
5+
readonly ROOT_DIRECTORY=$(realpath $(dirname $(realpath $0))/..)
6+
7+
if [ $(which docker || false) ]; then
8+
docker run \
9+
--rm \
10+
-it \
11+
-v ${ROOT_DIRECTORY}:/app \
12+
-w /app \
13+
php:7.4-cli-alpine3.10 \
14+
bin/phpstan
15+
else
16+
php bin/console --all-commands cache:warmup
17+
php -d memory_limit=512M /app/vendor/bin/phpstan analyse --ansi
18+
fi

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"twig/twig": "3.0.*"
3333
},
3434
"require-dev": {
35-
"phpstan/phpstan": "0.11.*",
35+
"phpstan/phpstan": "0.12.*",
36+
"phpstan/phpstan-symfony": "0.12.*",
3637
"steevanb/php-backtrace": "2.0.*",
3738
"symfony/var-dumper": "4.4.*"
3839
},

composer.lock

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

phpstan.neon

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
level: 5
3+
paths:
4+
- src/
5+
inferPrivatePropertyTypeFromConstructor: true
6+
symfony:
7+
container_xml_path: /app/var/cache/dev/srcApp_KernelDevDebugContainer.xml
8+
excludes_analyse:
9+
- src/Version.php
10+
includes:
11+
- /app/vendor/phpstan/phpstan-symfony/extension.neon

src/Command/AbstractCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ protected function writeFileFromTemplate(
182182
);
183183
}
184184

185+
/** @return $this */
185186
protected function filePutContent(string $filename, string $content, bool $rmPathPrefix = true): self
186187
{
187188
$fileExists = file_exists($filename);
@@ -197,6 +198,7 @@ protected function filePutContent(string $filename, string $content, bool $rmPat
197198
return $this;
198199
}
199200

201+
/** @return $this */
200202
protected function createDirectory(string $directory): self
201203
{
202204
if (is_dir($directory) === false) {
@@ -207,6 +209,7 @@ protected function createDirectory(string $directory): self
207209
return $this;
208210
}
209211

212+
/** @return $this */
210213
protected function removeDirectory(string $directory): self
211214
{
212215
if (is_dir($directory)) {
@@ -217,6 +220,7 @@ protected function removeDirectory(string $directory): self
217220
return $this;
218221
}
219222

223+
/** @return $this */
220224
protected function removeFile(string $file, bool $rmPrefix = true): self
221225
{
222226
if (is_file($file)) {

src/Command/Behavior/GetBodyFromUrl.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
trait GetBodyFromUrl
88
{
9-
/** @return $this */
109
protected function getBodyFromUrl(string $url, bool $assertIs200 = true): ?string
1110
{
1211
$curl = curl_init();

src/Command/Nginx/Vhost/AbstractNginxVhostCreateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected function defineVhostVariables(
120120
throw new \Exception('Error while reading ' . $vhostFilePath . '.');
121121
}
122122

123-
$content = str_replace('____PORT____', BenchmarkUrlService::getNginxPort(), $content);
123+
$content = str_replace('____PORT____', (string) BenchmarkUrlService::getNginxPort(), $content);
124124
$content = str_replace('____HOST____', $host, $content);
125125

126126
$sourceCodePath = realpath($sourceCodePath);

src/Command/Validate/Benchmark/AbstractValidateBenchmarkUrlCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ protected function doExecute(): int
4848
return 0;
4949
}
5050

51+
/** @return $this */
5152
protected function validatePhpVersion(PhpVersion $phpVersion): self
5253
{
5354
foreach (BenchmarkConfigurationService::getAvailable($phpVersion) as $benchmarkConfiguration) {
@@ -70,6 +71,7 @@ protected function validatePhpVersion(PhpVersion $phpVersion): self
7071
return $this;
7172
}
7273

74+
/** @return $this */
7375
protected function afterHttpCodeValidated(
7476
PhpVersion $phpVersion,
7577
BenchmarkConfiguration $benchmarkConfiguration,
@@ -78,6 +80,7 @@ protected function afterHttpCodeValidated(
7880
return $this;
7981
}
8082

83+
/** @return $this */
8184
protected function initBenchmark(PhpVersion $phpVersion, BenchmarkConfiguration $benchmarkConfiguration): self
8285
{
8386
return $this->runCommand(

src/Command/Validate/Benchmark/ValidateBenchmarkPhpInfoCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected function afterHttpCodeValidated(
3535
BenchmarkConfiguration $benchmarkConfiguration,
3636
?string $body
3737
): self {
38-
if (is_string($body) === false || strlen($body) === false) {
38+
if (is_string($body) === false || strlen($body) === 0) {
3939
throw new \Exception('phpinfo() should not output an empty string.');
4040
}
4141

0 commit comments

Comments
 (0)