diff --git a/.editorconfig b/.editorconfig index c5f4ac7..56583b9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,6 @@ trim_trailing_whitespace = true [*.{yml,yaml}] indent_size = 2 + +[*.neon] +indent_style = tab diff --git a/.gitattributes b/.gitattributes index 9b46665..eb80432 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12,3 +12,4 @@ /tests export-ignore /CHANGELOG.md export-ignore /CONTRIBUTING.md export-ignore +/phpstan.neon export-ignore diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2246594..68ea79e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -60,7 +60,7 @@ jobs: run: | vendor/bin/php-cs-fixer fix --dry-run --diff - psalm: + static-analysis: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 @@ -69,7 +69,7 @@ jobs: with: php-version: '8.3' extensions: gd, imagick - tools: vimeo/psalm:5 + tools: vimeo/psalm:5, phpstan:1 - name: Composer install uses: ramsey/composer-install@v3 @@ -77,3 +77,8 @@ jobs: - name: psalm run: | psalm --output-format=github + + - name: phpstan + if: always() + run: | + phpstan --error-format=github diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index b9f83c5..a2f9d0c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -13,7 +13,7 @@ 'use_nullable_type_declaration' => true, ], 'phpdoc_to_comment' => [ - 'ignored_tags' => ['psalm-suppress'], + 'ignored_tags' => ['psalm-suppress', 'phpstan-ignore-line', 'phpstan-ignore-next-line'], ], ]) ->setFinder($finder) diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..c58cb50 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + level: 8 + paths: + - src/ + ignoreErrors: + - + identifier: missingType.iterableValue diff --git a/src/Api/Encoder.php b/src/Api/Encoder.php index 4d42a1f..5422d85 100644 --- a/src/Api/Encoder.php +++ b/src/Api/Encoder.php @@ -67,7 +67,7 @@ public function run(ImageInterface $image): EncodedImageInterface $format = 'jpg'; } - $encoderOptions = ['extension' => $format]; + $encoderOptions = []; switch ($format) { case 'avif': case 'heic': @@ -87,7 +87,7 @@ public function run(ImageInterface $image): EncodedImageInterface throw new \Exception("Invalid format provided: {$format}"); } - return $image->encodeByExtension(...$encoderOptions); + return $image->encodeByExtension($format, ...$encoderOptions); } /** diff --git a/src/Manipulators/Helpers/Color.php b/src/Manipulators/Helpers/Color.php index 7f5d90d..5ade904 100644 --- a/src/Manipulators/Helpers/Color.php +++ b/src/Manipulators/Helpers/Color.php @@ -85,7 +85,7 @@ public function __construct(string $value) $rgba = [255, 255, 255]; $alpha = 0; - } while (false); + } while (false); // @phpstan-ignore-line $this->red = $rgba[0]; $this->green = $rgba[1]; diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index a8ba90d..e9404fb 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -25,7 +25,7 @@ public function __construct(?int $maxImageSize = null) /** * Set the maximum image size. * - * @param int|null Maximum image size in pixels. + * @param int|null $maxImageSize Maximum image size in pixels. */ public function setMaxImageSize(?int $maxImageSize = null): void { diff --git a/src/Server.php b/src/Server.php index fcc34d6..8f73b90 100644 --- a/src/Server.php +++ b/src/Server.php @@ -361,8 +361,8 @@ public function getCachePath(string $path, array $params = []): string if ($this->cacheWithFileExtensions) { /** @psalm-suppress PossiblyUndefinedArrayOffset */ - $ext = (isset($params['fm']) ? $params['fm'] : pathinfo($path)['extension']); - $ext = ('pjpg' === $ext) ? 'jpg' : $ext; + $ext = isset($params['fm']) ? $params['fm'] : pathinfo($path, PATHINFO_EXTENSION); + $ext = 'pjpg' === $ext ? 'jpg' : $ext; $cachedPath .= '.'.$ext; } diff --git a/src/Urls/UrlBuilder.php b/src/Urls/UrlBuilder.php index 72d026f..8ff2f7f 100644 --- a/src/Urls/UrlBuilder.php +++ b/src/Urls/UrlBuilder.php @@ -74,7 +74,11 @@ public function getUrl(string $path, array $params = []): string throw new \InvalidArgumentException('Not a valid path.'); } - /** @psalm-suppress PossiblyNullArgument, PossiblyUndefinedArrayOffset */ + /** + * @psalm-suppress PossiblyNullArgument, PossiblyUndefinedArrayOffset + * + * @phpstan-ignore-next-line + */ $parts['path'] = '/'.trim($parts['path'], '/'); if ($this->signature) {