Skip to content

Commit 26af6ff

Browse files
authored
Merge pull request #403 from thephpleague/chore/phpstan
Use phpstan
2 parents 77fb61c + 9b3132b commit 26af6ff

File tree

10 files changed

+30
-10
lines changed

10 files changed

+30
-10
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ trim_trailing_whitespace = true
1212

1313
[*.{yml,yaml}]
1414
indent_size = 2
15+
16+
[*.neon]
17+
indent_style = tab

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
/tests export-ignore
1313
/CHANGELOG.md export-ignore
1414
/CONTRIBUTING.md export-ignore
15+
/phpstan.neon export-ignore

.github/workflows/test.yaml

+7-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
run: |
6161
vendor/bin/php-cs-fixer fix --dry-run --diff
6262
63-
psalm:
63+
static-analysis:
6464
runs-on: ubuntu-24.04
6565
steps:
6666
- uses: actions/checkout@v4
@@ -69,11 +69,16 @@ jobs:
6969
with:
7070
php-version: '8.3'
7171
extensions: gd, imagick
72-
tools: vimeo/psalm:5
72+
tools: vimeo/psalm:5, phpstan:1
7373

7474
- name: Composer install
7575
uses: ramsey/composer-install@v3
7676

7777
- name: psalm
7878
run: |
7979
psalm --output-format=github
80+
81+
- name: phpstan
82+
if: always()
83+
run: |
84+
phpstan --error-format=github

.php-cs-fixer.dist.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'use_nullable_type_declaration' => true,
1414
],
1515
'phpdoc_to_comment' => [
16-
'ignored_tags' => ['psalm-suppress'],
16+
'ignored_tags' => ['psalm-suppress', 'phpstan-ignore-line', 'phpstan-ignore-next-line'],
1717
],
1818
])
1919
->setFinder($finder)

phpstan.neon

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- src/
5+
ignoreErrors:
6+
-
7+
identifier: missingType.iterableValue

src/Api/Encoder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function run(ImageInterface $image): EncodedImageInterface
6767
$format = 'jpg';
6868
}
6969

70-
$encoderOptions = ['extension' => $format];
70+
$encoderOptions = [];
7171
switch ($format) {
7272
case 'avif':
7373
case 'heic':
@@ -87,7 +87,7 @@ public function run(ImageInterface $image): EncodedImageInterface
8787
throw new \Exception("Invalid format provided: {$format}");
8888
}
8989

90-
return $image->encodeByExtension(...$encoderOptions);
90+
return $image->encodeByExtension($format, ...$encoderOptions);
9191
}
9292

9393
/**

src/Manipulators/Helpers/Color.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function __construct(string $value)
8585

8686
$rgba = [255, 255, 255];
8787
$alpha = 0;
88-
} while (false);
88+
} while (false); // @phpstan-ignore-line
8989

9090
$this->red = $rgba[0];
9191
$this->green = $rgba[1];

src/Manipulators/Size.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(?int $maxImageSize = null)
2525
/**
2626
* Set the maximum image size.
2727
*
28-
* @param int|null Maximum image size in pixels.
28+
* @param int|null $maxImageSize Maximum image size in pixels.
2929
*/
3030
public function setMaxImageSize(?int $maxImageSize = null): void
3131
{

src/Server.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ public function getCachePath(string $path, array $params = []): string
361361

362362
if ($this->cacheWithFileExtensions) {
363363
/** @psalm-suppress PossiblyUndefinedArrayOffset */
364-
$ext = (isset($params['fm']) ? $params['fm'] : pathinfo($path)['extension']);
365-
$ext = ('pjpg' === $ext) ? 'jpg' : $ext;
364+
$ext = isset($params['fm']) ? $params['fm'] : pathinfo($path, PATHINFO_EXTENSION);
365+
$ext = 'pjpg' === $ext ? 'jpg' : $ext;
366366
$cachedPath .= '.'.$ext;
367367
}
368368

src/Urls/UrlBuilder.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ public function getUrl(string $path, array $params = []): string
7474
throw new \InvalidArgumentException('Not a valid path.');
7575
}
7676

77-
/** @psalm-suppress PossiblyNullArgument, PossiblyUndefinedArrayOffset */
77+
/**
78+
* @psalm-suppress PossiblyNullArgument, PossiblyUndefinedArrayOffset
79+
*
80+
* @phpstan-ignore-next-line
81+
*/
7882
$parts['path'] = '/'.trim($parts['path'], '/');
7983

8084
if ($this->signature) {

0 commit comments

Comments
 (0)