Skip to content

Commit de2211b

Browse files
Baspacursoragent
andauthored
fix: deprecated warnings and support PHP 8.2, 8.3, 8.4 (#43)
* fix: deprecated warnings in Transformations.php * Update dependencies, improve type handling, and migrate to PHPUnit 10 Co-authored-by: bspbaspa <bspbaspa@gmail.com> * wip --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent ba49d2c commit de2211b

19 files changed

+131
-74
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
fail-fast: true
1010
matrix:
1111
os: [ubuntu-latest, windows-latest]
12-
php: [8.1]
12+
php: [8.1, 8.2, 8.3]
1313
stability: [prefer-lowest, prefer-stable]
1414

1515
name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}

.phpunit.cache/test-results

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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}}

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^8.1"
18+
"php": "^8.1|^8.2|^8.3"
1919
},
2020
"require-dev": {
21-
"friendsofphp/php-cs-fixer": "^3.0",
22-
"pestphp/pest": "^1.21",
23-
"phpstan/phpstan": "^1.8",
24-
"rector/rector": "^0.14.5",
25-
"spatie/ray": "^1.28"
21+
"friendsofphp/php-cs-fixer": "^3.85",
22+
"pestphp/pest": "^2.0",
23+
"phpstan/phpstan": "^1.12",
24+
"rector/rector": "^1.0",
25+
"spatie/ray": "^1.42"
2626
},
2727
"autoload": {
2828
"psr-4": {

phpunit.xml.dist

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5-
backupGlobals="false"
6-
backupStaticAttributes="false"
7-
bootstrap="vendor/autoload.php"
8-
colors="true"
9-
convertErrorsToExceptions="true"
10-
convertNoticesToExceptions="true"
11-
convertWarningsToExceptions="true"
12-
processIsolation="false"
13-
stopOnFailure="false"
14-
executionOrder="random"
15-
failOnWarning="true"
16-
failOnRisky="true"
17-
failOnEmptyTestSuite="true"
18-
beStrictAboutOutputDuringTests="true"
19-
verbose="true"
20-
>
21-
<testsuites>
22-
<testsuite name="Vormkracht10 Test Suite">
23-
<directory>tests</directory>
24-
</testsuite>
25-
</testsuites>
26-
<coverage>
27-
<include>
28-
<directory suffix=".php">./src</directory>
29-
</include>
30-
<report>
31-
<html outputDirectory="build/coverage"/>
32-
<text outputFile="build/coverage.txt"/>
33-
<clover outputFile="build/logs/clover.xml"/>
34-
</report>
35-
</coverage>
36-
<logging>
37-
<junit outputFile="build/report.junit.xml"/>
38-
</logging>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<testsuites>
4+
<testsuite name="Vormkracht10 Test Suite">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<coverage>
9+
<report>
10+
<html outputDirectory="build/coverage"/>
11+
<text outputFile="build/coverage.txt"/>
12+
<clover outputFile="build/logs/clover.xml"/>
13+
</report>
14+
</coverage>
15+
<logging>
16+
<junit outputFile="build/report.junit.xml"/>
17+
</logging>
18+
<source>
19+
<include>
20+
<directory suffix=".php">./src</directory>
21+
</include>
22+
</source>
3923
</phpunit>

phpunit.xml.dist.bak

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
backupGlobals="false"
6+
backupStaticAttributes="false"
7+
bootstrap="vendor/autoload.php"
8+
colors="true"
9+
convertErrorsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertWarningsToExceptions="true"
12+
processIsolation="false"
13+
stopOnFailure="false"
14+
executionOrder="random"
15+
failOnWarning="true"
16+
failOnRisky="true"
17+
failOnEmptyTestSuite="true"
18+
beStrictAboutOutputDuringTests="true"
19+
verbose="true"
20+
>
21+
<testsuites>
22+
<testsuite name="Vormkracht10 Test Suite">
23+
<directory>tests</directory>
24+
</testsuite>
25+
</testsuites>
26+
<coverage>
27+
<include>
28+
<directory suffix=".php">./src</directory>
29+
</include>
30+
<report>
31+
<html outputDirectory="build/coverage"/>
32+
<text outputFile="build/coverage.txt"/>
33+
<clover outputFile="build/logs/clover.xml"/>
34+
</report>
35+
</coverage>
36+
<logging>
37+
<junit outputFile="build/report.junit.xml"/>
38+
</logging>
39+
</phpunit>

src/Transformations.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function preview(int $width, int $height): self
5858
* @param int|null $height in pixels.
5959
* @param string|null $mode one of the resize modes.
6060
*/
61-
public function resize(int $width = null, int $height = null, bool $stretch = false, string $mode = null): self
61+
public function resize(int|null $width = null, int|null $height = null, bool $stretch = false, string|null $mode = null): self
6262
{
6363
$this->transformations['resize'] = Resize::transform($width, $height, $stretch, $mode);
6464

@@ -86,7 +86,7 @@ public function smartResize(int $width, int $height): self
8686
* @param int $height in pixels or percents.
8787
* @param int|string $offsetX horizontal and vertical offsets in pixels or percents (e.g. 50p) or shortcuts.
8888
*/
89-
public function crop(int|string $width, int|string $height, int|string $offsetX = null, int|string $offsetY = null): self
89+
public function crop(int|string $width, int|string $height, int|string|null $offsetX = null, int|string|null $offsetY = null): self
9090
{
9191
$this->transformations['crop'] = Crop::transform($width, $height, $offsetX, $offsetY);
9292

@@ -100,7 +100,7 @@ public function crop(int|string $width, int|string $height, int|string $offsetX
100100
* @param int|string $offsetX horizontal and vertical offsets in pixels or percents or shortcuts.
101101
* @param string|null $offsetY horizontal and vertical offsets in percents.
102102
*/
103-
public function cropByRatio(string $ratio, int|string $offsetX = null, string|null $offsetY = null): self
103+
public function cropByRatio(string $ratio, int|string|null $offsetX = null, string|null $offsetY = null): self
104104
{
105105
$this->transformations['crop_by_ratio'] = CropByRatio::transform($ratio, $offsetX, $offsetY);
106106

@@ -117,7 +117,7 @@ public function cropByRatio(string $ratio, int|string $offsetX = null, string|nu
117117
* @param int|string $offsetX horizontal and vertical offsets in percents or shortcuts.
118118
* @param string|null $offsetY horizontal and vertical offsets in percents.
119119
*/
120-
public function cropByObjects(string $tag, string $ratio = null, string $width = null, string $height = null, int|string $offsetX = null, string|null $offsetY = null): self
120+
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
121121
{
122122
$this->transformations['crop_by_objects'] = CropByObjects::transform($tag, $ratio, $width, $height, $offsetX, $offsetY);
123123

@@ -132,7 +132,7 @@ public function cropByObjects(string $tag, string $ratio = null, string $width =
132132
* @param string $offsetX horizontal and vertical offsets in percents or shortcuts.
133133
* @param string|null $offsetY horizontal and vertical offsets in percents.
134134
*/
135-
public function scaleCrop(int $width, int $height, string $offsetX = null, string|null $offsetY = null): self
135+
public function scaleCrop(int $width, int $height, string|null $offsetX = null, string|null $offsetY = null): self
136136
{
137137
$this->transformations['scale_crop'] = ScaleCrop::transform($width, $height, $offsetX, $offsetY);
138138

@@ -148,7 +148,7 @@ public function scaleCrop(int $width, int $height, string $offsetX = null, strin
148148
* @param string $offsetX horizontal and vertical offsets in percents or shortcuts.
149149
* @param string|null $offsetY horizontal and vertical offsets in percents.
150150
*/
151-
public function smartCrop(int $width, int $height, string $type, string $offsetX = null, string|null $offsetY = null): self
151+
public function smartCrop(int $width, int $height, string $type, string|null $offsetX = null, string|null $offsetY = null): self
152152
{
153153
$this->transformations['smart_crop'] = SmartCrop::transform($width, $height, $type, $offsetX, $offsetY);
154154

@@ -281,7 +281,7 @@ public function iccProfileSizeThreshold(int $number = 10): self
281281
* @param string $name one of the filters.
282282
* @param int $value optional value for the filter.
283283
*/
284-
public function filter(string $name, int $value = null): self
284+
public function filter(string $name, int|null $value = null): self
285285
{
286286
$this->transformations['filter'] = Filter::transform($name, $value);
287287

@@ -291,7 +291,7 @@ public function filter(string $name, int $value = null): self
291291
/**
292292
* Blurs images by the :strength factor.
293293
*/
294-
public function blur(int $strength = null, int $amount = null): self
294+
public function blur(int|null $strength = null, int|null $amount = null): self
295295
{
296296
$this->transformations['blur'] = Blur::transform($strength, $amount);
297297

@@ -306,7 +306,7 @@ public function blur(int $strength = null, int $amount = null): self
306306
* @param int $coordinateX in pixels or percentages.
307307
* @param int $coordinateY in pixels or percentages.
308308
*/
309-
public function blurRegion(int $dimensionX, int|string $dimensionY, int|string $coordinateX, int|string $coordinateY, int $strength = null): self
309+
public function blurRegion(int $dimensionX, int|string $dimensionY, int|string $coordinateX, int|string $coordinateY, int|null $strength = null): self
310310
{
311311
$this->transformations['blur_region'] = BlurRegion::transform($dimensionX, $dimensionY, $coordinateX, $coordinateY, $strength);
312312

@@ -316,7 +316,7 @@ public function blurRegion(int $dimensionX, int|string $dimensionY, int|string $
316316
/**
317317
* When faces is specified the regions are selected automatically by utilizing face detection.
318318
*/
319-
public function blurFaces(int $strength = null): self
319+
public function blurFaces(int|null $strength = null): self
320320
{
321321
$this->transformations['blur_faces'] = BlurFaces::transform($strength);
322322

@@ -326,7 +326,7 @@ public function blurFaces(int $strength = null): self
326326
/**
327327
* Sharpens an image, might be especially useful with images that were subjected to downscaling.
328328
*/
329-
public function sharpen(int $strength = null): self
329+
public function sharpen(int|null $strength = null): self
330330
{
331331
$this->transformations['sharpen'] = Sharpen::transform($strength);
332332

src/Transformations/BasicColorAdjustments.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ class BasicColorAdjustments implements TransformationInterface
1212

1313
public static function transform(...$args): array
1414
{
15-
$color = Color::tryFrom($args[0]);
15+
$colorValue = is_string($args[0]) || is_int($args[0]) ? (string) $args[0] : null;
16+
if ($colorValue === null) {
17+
throw new \InvalidArgumentException('Invalid color value type');
18+
}
19+
20+
$color = Color::tryFrom($colorValue);
1621
$value = $args[1];
1722

1823
if (! $color instanceof \Vormkracht10\UploadcareTransformations\Transformations\Enums\Color) {

src/Transformations/ConvertToSRGB.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ class ConvertToSRGB implements TransformationInterface
1111

1212
public static function transform(...$args): array
1313
{
14-
$profile = $args[0];
14+
$profileValue = is_string($args[0]) || is_int($args[0]) ? (string) $args[0] : null;
15+
if ($profileValue === null) {
16+
throw new \InvalidArgumentException('Invalid profile value type');
17+
}
1518

16-
if (ColorProfile::tryFrom($profile) === null) {
19+
if (ColorProfile::tryFrom($profileValue) === null) {
1720
throw new \InvalidArgumentException('Invalid color profile');
1821
}
1922

2023
return [
21-
self::PROFILE => $profile,
24+
self::PROFILE => $profileValue,
2225
];
2326
}
2427

src/Transformations/Crop.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static function transform(...$args): array
3939
throw new \InvalidArgumentException('Invalid offset Y');
4040
}
4141

42-
if (isset($offsetX) && Offset::tryFrom($offsetX)) {
42+
if (isset($offsetX) && (is_string($offsetX) || is_int($offsetX)) && Offset::tryFrom((string) $offsetX)) {
4343
return [
4444
self::WIDTH => $width,
4545
self::HEIGHT => $height,

src/Transformations/CropByObjects.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ public static function transform(...$args): array
2828
$offsetX = $args[4] ?? null;
2929
$offsetY = $args[5] ?? null;
3030

31+
$tagValue = is_string($tag) || is_int($tag) ? (string) $tag : null;
32+
if ($tagValue === null) {
33+
throw new \InvalidArgumentException('Invalid tag value type');
34+
}
3135

32-
if (Tag::tryFrom($tag) === null) {
36+
if (Tag::tryFrom($tagValue) === null) {
3337
throw new \InvalidArgumentException('Invalid tag');
3438
}
3539

@@ -70,7 +74,7 @@ public static function validate(string $key, ...$args): bool
7074
$value = $args[0];
7175

7276
if ($key === self::RATIO) {
73-
return preg_match('/^\d+:\d+$/', (string) $value);
77+
return (bool) preg_match('/^\d+:\d+$/', (string) $value);
7478
}
7579

7680
if ($key === self::OFFSET_X) {

0 commit comments

Comments
 (0)