Skip to content

Commit

Permalink
Use phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Oct 27, 2024
1 parent 77fb61c commit 9b3132b
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ trim_trailing_whitespace = true

[*.{yml,yaml}]
indent_size = 2

[*.neon]
indent_style = tab
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
/tests export-ignore
/CHANGELOG.md export-ignore
/CONTRIBUTING.md export-ignore
/phpstan.neon export-ignore
9 changes: 7 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -69,11 +69,16 @@ 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

- name: psalm
run: |
psalm --output-format=github
- name: phpstan
if: always()
run: |
phpstan --error-format=github
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
level: 8
paths:
- src/
ignoreErrors:
-
identifier: missingType.iterableValue
4 changes: 2 additions & 2 deletions src/Api/Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function run(ImageInterface $image): EncodedImageInterface
$format = 'jpg';
}

$encoderOptions = ['extension' => $format];
$encoderOptions = [];
switch ($format) {
case 'avif':
case 'heic':
Expand All @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Manipulators/Helpers/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/Manipulators/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Urls/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9b3132b

Please sign in to comment.