From 4af389281c382de0c94acc3222e1d9c5a5f2652c Mon Sep 17 00:00:00 2001 From: Baspa Date: Wed, 6 Aug 2025 10:26:16 +0200 Subject: [PATCH 1/3] fix: deprecated warnings in Transformations.php --- src/Transformations.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Transformations.php b/src/Transformations.php index 5c8a481..fd904c9 100644 --- a/src/Transformations.php +++ b/src/Transformations.php @@ -58,7 +58,7 @@ public function preview(int $width, int $height): self * @param int|null $height in pixels. * @param string|null $mode one of the resize modes. */ - public function resize(int $width = null, int $height = null, bool $stretch = false, string $mode = null): self + public function resize(int|null $width = null, int|null $height = null, bool $stretch = false, string|null $mode = null): self { $this->transformations['resize'] = Resize::transform($width, $height, $stretch, $mode); @@ -86,7 +86,7 @@ public function smartResize(int $width, int $height): self * @param int $height in pixels or percents. * @param int|string $offsetX horizontal and vertical offsets in pixels or percents (e.g. 50p) or shortcuts. */ - public function crop(int|string $width, int|string $height, int|string $offsetX = null, int|string $offsetY = null): self + public function crop(int|string $width, int|string $height, int|string|null $offsetX = null, int|string|null $offsetY = null): self { $this->transformations['crop'] = Crop::transform($width, $height, $offsetX, $offsetY); @@ -100,7 +100,7 @@ public function crop(int|string $width, int|string $height, int|string $offsetX * @param int|string $offsetX horizontal and vertical offsets in pixels or percents or shortcuts. * @param string|null $offsetY horizontal and vertical offsets in percents. */ - public function cropByRatio(string $ratio, int|string $offsetX = null, string|null $offsetY = null): self + public function cropByRatio(string $ratio, int|string|null $offsetX = null, string|null $offsetY = null): self { $this->transformations['crop_by_ratio'] = CropByRatio::transform($ratio, $offsetX, $offsetY); @@ -117,7 +117,7 @@ public function cropByRatio(string $ratio, int|string $offsetX = null, string|nu * @param int|string $offsetX horizontal and vertical offsets in percents or shortcuts. * @param string|null $offsetY horizontal and vertical offsets in percents. */ - public function cropByObjects(string $tag, string $ratio = null, string $width = null, string $height = null, int|string $offsetX = null, string|null $offsetY = null): self + public function cropByObjects(string $tag, string|null $ratio = null, string|null $width = null, string|null $height = null, int|string|null $offsetX = null, string|null $offsetY = null): self { $this->transformations['crop_by_objects'] = CropByObjects::transform($tag, $ratio, $width, $height, $offsetX, $offsetY); @@ -132,7 +132,7 @@ public function cropByObjects(string $tag, string $ratio = null, string $width = * @param string $offsetX horizontal and vertical offsets in percents or shortcuts. * @param string|null $offsetY horizontal and vertical offsets in percents. */ - public function scaleCrop(int $width, int $height, string $offsetX = null, string|null $offsetY = null): self + public function scaleCrop(int $width, int $height, string|null $offsetX = null, string|null $offsetY = null): self { $this->transformations['scale_crop'] = ScaleCrop::transform($width, $height, $offsetX, $offsetY); @@ -148,7 +148,7 @@ public function scaleCrop(int $width, int $height, string $offsetX = null, strin * @param string $offsetX horizontal and vertical offsets in percents or shortcuts. * @param string|null $offsetY horizontal and vertical offsets in percents. */ - public function smartCrop(int $width, int $height, string $type, string $offsetX = null, string|null $offsetY = null): self + public function smartCrop(int $width, int $height, string $type, string|null $offsetX = null, string|null $offsetY = null): self { $this->transformations['smart_crop'] = SmartCrop::transform($width, $height, $type, $offsetX, $offsetY); @@ -281,7 +281,7 @@ public function iccProfileSizeThreshold(int $number = 10): self * @param string $name one of the filters. * @param int $value optional value for the filter. */ - public function filter(string $name, int $value = null): self + public function filter(string $name, int|null $value = null): self { $this->transformations['filter'] = Filter::transform($name, $value); @@ -291,7 +291,7 @@ public function filter(string $name, int $value = null): self /** * Blurs images by the :strength factor. */ - public function blur(int $strength = null, int $amount = null): self + public function blur(int|null $strength = null, int|null $amount = null): self { $this->transformations['blur'] = Blur::transform($strength, $amount); @@ -306,7 +306,7 @@ public function blur(int $strength = null, int $amount = null): self * @param int $coordinateX in pixels or percentages. * @param int $coordinateY in pixels or percentages. */ - public function blurRegion(int $dimensionX, int|string $dimensionY, int|string $coordinateX, int|string $coordinateY, int $strength = null): self + public function blurRegion(int $dimensionX, int|string $dimensionY, int|string $coordinateX, int|string $coordinateY, int|null $strength = null): self { $this->transformations['blur_region'] = BlurRegion::transform($dimensionX, $dimensionY, $coordinateX, $coordinateY, $strength); @@ -316,7 +316,7 @@ public function blurRegion(int $dimensionX, int|string $dimensionY, int|string $ /** * When faces is specified the regions are selected automatically by utilizing face detection. */ - public function blurFaces(int $strength = null): self + public function blurFaces(int|null $strength = null): self { $this->transformations['blur_faces'] = BlurFaces::transform($strength); @@ -326,7 +326,7 @@ public function blurFaces(int $strength = null): self /** * Sharpens an image, might be especially useful with images that were subjected to downscaling. */ - public function sharpen(int $strength = null): self + public function sharpen(int|null $strength = null): self { $this->transformations['sharpen'] = Sharpen::transform($strength); From 9fa5fdb8044725e2a2874997a05ed57e2dcac2a0 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 8 Aug 2025 13:34:42 +0000 Subject: [PATCH 2/3] Update dependencies, improve type handling, and migrate to PHPUnit 10 Co-authored-by: bspbaspa --- .phpunit.cache/test-results | 1 + composer.json | 12 ++-- phpunit.xml.dist | 58 +++++++------------ phpunit.xml.dist.bak | 39 +++++++++++++ src/Transformations/BasicColorAdjustments.php | 7 ++- src/Transformations/ConvertToSRGB.php | 9 ++- src/Transformations/Crop.php | 2 +- src/Transformations/CropByObjects.php | 8 ++- src/Transformations/CropByRatio.php | 4 +- src/Transformations/Filter.php | 7 ++- src/Transformations/Format.php | 9 ++- src/Transformations/Overlay.php | 2 +- src/Transformations/Quality.php | 7 ++- src/Transformations/Resize.php | 2 +- src/Transformations/SmartCrop.php | 7 ++- src/Transformations/TransformationsFinder.php | 4 +- src/UploadcareTransformation.php | 3 +- 17 files changed, 119 insertions(+), 62 deletions(-) create mode 100644 .phpunit.cache/test-results create mode 100644 phpunit.xml.dist.bak diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results new file mode 100644 index 0000000..31a0057 --- /dev/null +++ b/.phpunit.cache/test-results @@ -0,0 +1 @@ +{"version":"pest_2.36.0","defects":[],"times":{"P\\Tests\\GenerateUrlTest::__pest_evaluable_it_can_generate_a_url_with_cdn":0,"P\\Tests\\GenerateUrlTest::__pest_evaluable_it_can_generate_a_url_without_cdn":0,"P\\Tests\\GenerateUrlTest::__pest_evaluable_it_adds_preview_automatically_to_url_when_using_blur__region__enhance__filter_or_zoom__objects_transformation_when_not_already_using_preview__scale__crop_or_resize":0.001,"P\\Tests\\GenerateUrlTest::__pest_evaluable_it_can_generate_a_url_using_convert_to_SRGB_and_ICC_profile_size_threshold":0,"P\\Tests\\GenerateUrlTest::__pest_evaluable_it_can_generate_a_proxy_url_for_urls":0,"P\\Tests\\GenerateUrlTest::__pest_evaluable_it_can_generate_a_url_including_filename_with_transformations":0,"P\\Tests\\ValidationTest::__pest_evaluable_it_can_validate_crop_type_enum":0,"P\\Tests\\ValidationTest::__pest_evaluable_it_can_validate_resize_mode_enum":0,"P\\Tests\\ValidationTest::__pest_evaluable_it_can_validate_filter_enum":0,"P\\Tests\\ValidationTest::__pest_evaluable_it_can_validate_quality_enum":0,"P\\Tests\\ValidationTest::__pest_evaluable_it_can_validate_basic_color_adjustment_value":0,"P\\Tests\\ValidationTest::__pest_evaluable_it_can_validate_format_enum":0,"P\\Tests\\ValidationTest::__pest_evaluable_it_can_validate_tag_enum":0.002,"P\\Tests\\ValidationTest::__pest_evaluable_it_can_validate_color_profile_enum":0,"P\\Tests\\ValidationTest::__pest_evaluable_it_can_validate_offset_enum":0,"P\\Tests\\ValidationTest::__pest_evaluable_it_can_validate_color_enum":0,"P\\Tests\\ValidationTest::__pest_evaluable_it_can_validate_ratio":0,"P\\Tests\\ValidationTest::__pest_evaluable_it_can_validate_percentages":0,"P\\Tests\\TransformationTest::__pest_evaluable_it_can_add_an_overlay":0,"P\\Tests\\TransformationTest::__pest_evaluable_it_can_scale_crop":0,"P\\Tests\\TransformationTest::__pest_evaluable_it_can_resize":0,"P\\Tests\\TransformationTest::__pest_evaluable_it_can_transform_using_array_input":0.002,"P\\Tests\\TransformationTest::__pest_evaluable_it_can_crop_by_ratio":0,"P\\Tests\\TransformationTest::__pest_evaluable_it_can_smart_crop":0,"P\\Tests\\TransformationTest::__pest_evaluable_it_can_crop":0,"P\\Tests\\TransformationTest::__pest_evaluable_it_can_strip_meta_information":0,"P\\Tests\\TransformationTest::__pest_evaluable_it_can_crop_by_objects":0}} \ No newline at end of file diff --git a/composer.json b/composer.json index ab7e18c..3ddf70e 100644 --- a/composer.json +++ b/composer.json @@ -15,14 +15,14 @@ } ], "require": { - "php": "^8.1" + "php": "^8.1|^8.2|^8.3" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.0", - "pestphp/pest": "^1.21", - "phpstan/phpstan": "^1.8", - "rector/rector": "^0.14.5", - "spatie/ray": "^1.28" + "friendsofphp/php-cs-fixer": "^3.85", + "pestphp/pest": "^2.0", + "phpstan/phpstan": "^1.12", + "rector/rector": "^1.0", + "spatie/ray": "^1.42" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a5779f4..7177269 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,39 +1,23 @@ - - - - tests - - - - - ./src - - - - - - - - - - + + + + tests + + + + + + + + + + + + + + + ./src + + diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak new file mode 100644 index 0000000..a5779f4 --- /dev/null +++ b/phpunit.xml.dist.bak @@ -0,0 +1,39 @@ + + + + + tests + + + + + ./src + + + + + + + + + + + diff --git a/src/Transformations/BasicColorAdjustments.php b/src/Transformations/BasicColorAdjustments.php index 874de0a..4767bcc 100644 --- a/src/Transformations/BasicColorAdjustments.php +++ b/src/Transformations/BasicColorAdjustments.php @@ -12,7 +12,12 @@ class BasicColorAdjustments implements TransformationInterface public static function transform(...$args): array { - $color = Color::tryFrom($args[0]); + $colorValue = is_string($args[0]) || is_int($args[0]) ? (string) $args[0] : null; + if ($colorValue === null) { + throw new \InvalidArgumentException('Invalid color value type'); + } + + $color = Color::tryFrom($colorValue); $value = $args[1]; if (! $color instanceof \Vormkracht10\UploadcareTransformations\Transformations\Enums\Color) { diff --git a/src/Transformations/ConvertToSRGB.php b/src/Transformations/ConvertToSRGB.php index 6adda5f..f7fcb89 100644 --- a/src/Transformations/ConvertToSRGB.php +++ b/src/Transformations/ConvertToSRGB.php @@ -11,14 +11,17 @@ class ConvertToSRGB implements TransformationInterface public static function transform(...$args): array { - $profile = $args[0]; + $profileValue = is_string($args[0]) || is_int($args[0]) ? (string) $args[0] : null; + if ($profileValue === null) { + throw new \InvalidArgumentException('Invalid profile value type'); + } - if (ColorProfile::tryFrom($profile) === null) { + if (ColorProfile::tryFrom($profileValue) === null) { throw new \InvalidArgumentException('Invalid color profile'); } return [ - self::PROFILE => $profile, + self::PROFILE => $profileValue, ]; } diff --git a/src/Transformations/Crop.php b/src/Transformations/Crop.php index 5f79d07..6d0b0ca 100644 --- a/src/Transformations/Crop.php +++ b/src/Transformations/Crop.php @@ -39,7 +39,7 @@ public static function transform(...$args): array throw new \InvalidArgumentException('Invalid offset Y'); } - if (isset($offsetX) && Offset::tryFrom($offsetX)) { + if (isset($offsetX) && (is_string($offsetX) || is_int($offsetX)) && Offset::tryFrom((string) $offsetX)) { return [ self::WIDTH => $width, self::HEIGHT => $height, diff --git a/src/Transformations/CropByObjects.php b/src/Transformations/CropByObjects.php index a07e3f2..c037cb5 100644 --- a/src/Transformations/CropByObjects.php +++ b/src/Transformations/CropByObjects.php @@ -28,8 +28,12 @@ public static function transform(...$args): array $offsetX = $args[4] ?? null; $offsetY = $args[5] ?? null; + $tagValue = is_string($tag) || is_int($tag) ? (string) $tag : null; + if ($tagValue === null) { + throw new \InvalidArgumentException('Invalid tag value type'); + } - if (Tag::tryFrom($tag) === null) { + if (Tag::tryFrom($tagValue) === null) { throw new \InvalidArgumentException('Invalid tag'); } @@ -70,7 +74,7 @@ public static function validate(string $key, ...$args): bool $value = $args[0]; if ($key === self::RATIO) { - return preg_match('/^\d+:\d+$/', (string) $value); + return (bool) preg_match('/^\d+:\d+$/', (string) $value); } if ($key === self::OFFSET_X) { diff --git a/src/Transformations/CropByRatio.php b/src/Transformations/CropByRatio.php index 3c8b645..648c9de 100644 --- a/src/Transformations/CropByRatio.php +++ b/src/Transformations/CropByRatio.php @@ -33,7 +33,7 @@ public static function transform(...$args): array throw new \InvalidArgumentException('Invalid offset Y'); } - if (isset($offsetX) && Offset::tryFrom($offsetX)) { + if (isset($offsetX) && (is_string($offsetX) || is_int($offsetX)) && Offset::tryFrom((string) $offsetX)) { return [ self::RATIO => $ratio, self::ALIGN => $offsetX, @@ -58,7 +58,7 @@ public static function validate(string $key, ...$args): bool $value = $args[0]; if ($key === self::RATIO) { - return preg_match('/^\d+:\d+$/', (string) $value); + return (bool) preg_match('/^\d+:\d+$/', (string) $value); } if ($key === self::OFFSET_X && is_string($value)) { diff --git a/src/Transformations/Filter.php b/src/Transformations/Filter.php index 0d83453..9550b65 100644 --- a/src/Transformations/Filter.php +++ b/src/Transformations/Filter.php @@ -15,7 +15,12 @@ public static function transform(...$args): array $name = $args[0]; $amount = $args[1]; - if (FilterEnum::tryFrom($name) === null) { + $nameValue = is_string($name) || is_int($name) ? (string) $name : null; + if ($nameValue === null) { + throw new \InvalidArgumentException('Invalid filter name type'); + } + + if (FilterEnum::tryFrom($nameValue) === null) { throw new \InvalidArgumentException('Invalid filter'); } diff --git a/src/Transformations/Format.php b/src/Transformations/Format.php index 4a07361..ca627e4 100644 --- a/src/Transformations/Format.php +++ b/src/Transformations/Format.php @@ -13,12 +13,17 @@ public static function transform(...$args): array { $format = $args[0]; - if (FormatEnum::tryFrom($format) === null) { + $formatValue = is_string($format) || is_int($format) ? (string) $format : null; + if ($formatValue === null) { + throw new \InvalidArgumentException('Invalid format value type'); + } + + if (FormatEnum::tryFrom($formatValue) === null) { throw new \InvalidArgumentException('Invalid format'); } return [ - self::FORMAT => $format, + self::FORMAT => $formatValue, ]; } diff --git a/src/Transformations/Overlay.php b/src/Transformations/Overlay.php index dfcf1b0..3db9f8b 100644 --- a/src/Transformations/Overlay.php +++ b/src/Transformations/Overlay.php @@ -42,7 +42,7 @@ public static function transform(...$args): array throw new \InvalidArgumentException('Invalid coordinate Y'); } - if ($opacity && ! self::isValidPercentage($opacity)) { + if ($opacity && is_string($opacity) && ! self::isValidPercentage($opacity)) { throw new \InvalidArgumentException('Invalid opacity'); } diff --git a/src/Transformations/Quality.php b/src/Transformations/Quality.php index 0f9830b..c797df9 100644 --- a/src/Transformations/Quality.php +++ b/src/Transformations/Quality.php @@ -11,7 +11,12 @@ class Quality implements TransformationInterface public static function transform(...$args): array { - $quality = QualityEnum::tryFrom($args[0]); + $qualityValue = is_string($args[0]) || is_int($args[0]) ? (string) $args[0] : null; + if ($qualityValue === null) { + throw new \InvalidArgumentException('Invalid quality value type'); + } + + $quality = QualityEnum::tryFrom($qualityValue); if (! $quality instanceof \Vormkracht10\UploadcareTransformations\Transformations\Enums\Quality) { throw new \InvalidArgumentException('Invalid quality'); diff --git a/src/Transformations/Resize.php b/src/Transformations/Resize.php index a3cd19e..5fb6e7b 100644 --- a/src/Transformations/Resize.php +++ b/src/Transformations/Resize.php @@ -19,7 +19,7 @@ public static function transform(...$args): array $stretch = $args[2] ?? false; $mode = $args[3] ?? null; - if ($mode && ! ResizeMode::tryFrom($mode)) { + if ($mode && (is_string($mode) || is_int($mode)) && ! ResizeMode::tryFrom((string) $mode)) { throw new \InvalidArgumentException('Invalid resize mode'); } diff --git a/src/Transformations/SmartCrop.php b/src/Transformations/SmartCrop.php index 87ac046..4e7c39f 100644 --- a/src/Transformations/SmartCrop.php +++ b/src/Transformations/SmartCrop.php @@ -22,7 +22,12 @@ public static function transform(...$args): array { $width = $args[0]; $height = $args[1]; - $type = CropType::tryFrom($args[2]); + $typeValue = is_string($args[2]) || is_int($args[2]) ? (string) $args[2] : null; + if ($typeValue === null) { + throw new \InvalidArgumentException('Invalid crop type value type'); + } + + $type = CropType::tryFrom($typeValue); $offsetX = $args[3] ?? null; $offsetY = $args[4] ?? null; diff --git a/src/Transformations/TransformationsFinder.php b/src/Transformations/TransformationsFinder.php index 85d5fb0..4e9bc44 100644 --- a/src/Transformations/TransformationsFinder.php +++ b/src/Transformations/TransformationsFinder.php @@ -82,7 +82,7 @@ public static function getTransformation(string $key): string|null * Get all transformations * * @param array>> $transformations - * @return array>}> + * @return array>}> */ public static function for(array $transformations): array { @@ -110,7 +110,7 @@ public static function for(array $transformations): array } $classes[$transformation] = [ - 'class' => self::getTransformation($transformation), + 'class' => $class, 'values' => $transformations[$transformation], ]; } diff --git a/src/UploadcareTransformation.php b/src/UploadcareTransformation.php index 0c142e6..b75a189 100755 --- a/src/UploadcareTransformation.php +++ b/src/UploadcareTransformation.php @@ -39,7 +39,8 @@ public function applyTransformations(string $url): string $transformations = TransformationsFinder::for($this->transformations); foreach ($transformations as $transformation) { - $url = $transformation['class']::generateUrl($url, $transformation['values']); + $className = get_class($transformation['class']); + $url = $className::generateUrl($url, $transformation['values']); } return $url; From cdebf942201d968e3c07cbc1bc00cba478d21afe Mon Sep 17 00:00:00 2001 From: Baspa Date: Fri, 8 Aug 2025 16:03:53 +0200 Subject: [PATCH 3/3] wip --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0d7f602..73104fa 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -9,7 +9,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.1] + php: [8.1, 8.2, 8.3] stability: [prefer-lowest, prefer-stable] name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}