Skip to content

Commit 52e50aa

Browse files
committed
chore: bump PHPStan level to 6, add array shape annotations
1 parent 37fc27f commit 52e50aa

File tree

9 files changed

+41
-11
lines changed

9 files changed

+41
-11
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ includes:
22
- phpstan-baseline.neon
33

44
parameters:
5-
level: 5
5+
level: 6
66
paths:
77
- src
88
- config

src/Enums/AllowedMimeTypes.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ enum AllowedMimeTypes: string
1111
case Webp = 'image/webp';
1212
case Gif = 'image/gif';
1313

14+
/**
15+
* @return array<string>
16+
*/
1417
public static function all(): array
1518
{
1619
return array_map(fn (self $mimeType) => $mimeType->value, self::cases());
1720
}
1821

22+
/**
23+
* @return array<array{mime: string, extension: string}>
24+
*/
1925
public static function withExtension(): array
2026
{
2127
return array_map(

src/Enums/AllowedOptions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ enum AllowedOptions: string
1616
case Version = 'version';
1717
case Background = 'background';
1818

19+
/**
20+
* @return array<string>
21+
*/
1922
public static function all(): array
2023
{
2124
return array_map(fn (self $option) => $option->value, self::cases());
2225
}
2326

27+
/**
28+
* @return array<string, string>
29+
*/
2430
public static function withTypes(): array
2531
{
2632
return [

src/Exceptions/InvalidConfigurationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class InvalidConfigurationException extends RuntimeException
1111
{
12-
public function __construct(string $message, $code = 0, ?Throwable $previous = null)
12+
public function __construct(string $message, int $code = 0, ?Throwable $previous = null)
1313
{
1414
parent::__construct($message, $code, $previous);
1515
}

src/Facades/ImageTransformUrl.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
use Illuminate\Support\Facades\Facade;
88

99
/**
10-
* @method static string make(string $path, array|string $options = [], ?string $pathPrefix = null)
11-
* @method static string url(string $path, array|string $options = [], ?string $pathPrefix = null)
12-
* @method static string signedUrl(string $path, array|string $options = [], ?string $pathPrefix = null, \DateTimeInterface|\DateInterval|int|null $expiration = null, ?bool $absolute = true)
13-
* @method static string temporarySignedUrl(string $path, array|string $options = [], \DateTimeInterface|\DateInterval|int $expiration, ?string $pathPrefix = null, ?bool $absolute = true)
10+
* @method static string make(string $path, array<string, int|string>|string $options = [], ?string $pathPrefix = null)
11+
* @method static string url(string $path, array<string, int|string>|string $options = [], ?string $pathPrefix = null)
12+
* @method static string signedUrl(string $path, array<string, int|string>|string $options = [], ?string $pathPrefix = null, \DateTimeInterface|\DateInterval|int|null $expiration = null, ?bool $absolute = true)
13+
* @method static string temporarySignedUrl(string $path, array<string, int|string>|string $options = [], \DateTimeInterface|\DateInterval|int $expiration, ?string $pathPrefix = null, ?bool $absolute = true)
1414
*
1515
* @see \AceOfAces\LaravelImageTransformUrl\ImageTransformUrl
1616
*/

src/Http/Controllers/ImageTransformerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ protected function rateLimit(Request $request, string $path): void
268268
/**
269269
* Parse the given options.
270270
*
271-
* @return array<string, int>
271+
* @return array<string, int|string>
272272
*/
273273
protected static function parseOptions(string $options): array
274274
{

src/ImageTransformUrl.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ImageTransformUrl
1515
* Generate a regular URL for the image transformation.
1616
*
1717
* @param string $path The path to the image.
18-
* @param array|string $options The transformation options.
18+
* @param array<string, int|string>|string $options The transformation options.
1919
* @param string|null $pathPrefix The path prefix to use. Defaults to the default path prefix.
2020
* @return string The generated URL.
2121
*/
@@ -34,7 +34,7 @@ public function make(string $path, array|string $options = [], ?string $pathPref
3434
* Generate a regular URL for the image transformation.
3535
*
3636
* @param string $path The path to the image.
37-
* @param array|string $options The transformation options.
37+
* @param array<string, int|string>|string $options The transformation options.
3838
* @param string|null $pathPrefix The path prefix to use. Defaults to the default path prefix.
3939
* @return string The generated URL.
4040
*/
@@ -47,7 +47,7 @@ public function url(string $path, array|string $options = [], ?string $pathPrefi
4747
* Generate a signed URL for the image transformation.
4848
*
4949
* @param string $path The path to the image.
50-
* @param array|string $options The transformation options.
50+
* @param array<string, int|string>|string $options The transformation options.
5151
* @param string|null $pathPrefix The path prefix to use. Defaults to the default path prefix.
5252
* @param DateTimeInterface|\DateInterval|int|null $expiration The expiration time for the signed URL.
5353
* @return string The signed URL.
@@ -83,7 +83,7 @@ public function signedUrl(string $path, array|string $options = [], ?string $pat
8383
* Generate a temporary signed URL for the image transformation.
8484
*
8585
* @param string $path The path to the image.
86-
* @param array|string $options The transformation options.
86+
* @param array<string, int|string>|string $options The transformation options.
8787
* @param DateTimeInterface|DateInterval|int $expiration The expiration time for the signed URL.
8888
* @param string|null $pathPrefix The path prefix to use. Defaults to the default path prefix.
8989
* @param bool|null $absolute Whether the URL should be absolute. Defaults to true.
@@ -98,6 +98,8 @@ public function temporarySignedUrl(string $path, array|string $options, DateTime
9898

9999
/**
100100
* Convert array options to a string format suitable for URL generation.
101+
*
102+
* @param array<string, int|string>|string $options
101103
*/
102104
protected function optionsToString(array|string $options): string
103105
{

src/Traits/ManagesImageCache.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ protected function cleanupOldCacheFiles(Filesystem $disk, string $cacheBasePath,
9797

9898
/**
9999
* Store image in cache with size management.
100+
*
101+
* @param array<string, int|string> $options
100102
*/
101103
protected function storeCachedImage(?string $pathPrefix, ?string $path, array $options, EncodedImageInterface $encoded): void
102104
{
@@ -118,6 +120,8 @@ protected function storeCachedImage(?string $pathPrefix, ?string $path, array $o
118120

119121
/**
120122
* Get the cache path for the given path and options.
123+
*
124+
* @param array<string, int|string> $options
121125
*/
122126
protected function getCachePath(?string $pathPrefix, ?string $path, array $options): string
123127
{
@@ -126,6 +130,11 @@ protected function getCachePath(?string $pathPrefix, ?string $path, array $optio
126130
return Storage::disk(config()->string('image-transform-url.cache.disk'))->path($cachePath);
127131
}
128132

133+
/**
134+
* Get the end (relative) path for storing the cached image.
135+
*
136+
* @param array<string, int|string> $options
137+
*/
129138
protected function getCacheEndPath(?string $pathPrefix, ?string $path, array $options): string
130139
{
131140
$optionsHash = md5(json_encode($options));

src/Traits/ResolvesOptions.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ trait ResolvesOptions
1010
{
1111
/**
1212
* Get the positive int value of the given option.
13+
*
14+
* @param array<string, int|string|null> $options
1315
*/
1416
protected static function getPositiveIntOptionValue(array $options, string $option, ?int $max = null, ?int $fallback = null): ?int
1517
{
@@ -23,6 +25,8 @@ protected static function getPositiveIntOptionValue(array $options, string $opti
2325

2426
/**
2527
* Get the unsigned int value of the given option.
28+
*
29+
* @param array<string, int|string|null> $options
2630
*/
2731
protected static function getUnsignedIntOptionValue(array $options, string $option, ?int $fallback = null, ?int $min = null, ?int $max = null): ?int
2832
{
@@ -37,6 +41,8 @@ protected static function getUnsignedIntOptionValue(array $options, string $opti
3741

3842
/**
3943
* Get the string value of the given option.
44+
*
45+
* @param array<string, int|string|null> $options
4046
*/
4147
protected static function getStringOptionValue(array $options, string $option, ?string $default = null): ?string
4248
{
@@ -48,6 +54,7 @@ protected static function getStringOptionValue(array $options, string $option, ?
4854
* Get the select option value of the given option.
4955
*
5056
* @param array<string> $allowedValues
57+
* @param array<string, int|string|null> $options
5158
*/
5259
protected static function getSelectOptionValue(array $options, string $option, array $allowedValues, ?string $default = null): ?string
5360
{

0 commit comments

Comments
 (0)