Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .phpunit.cache/test-results
Original file line number Diff line number Diff line change
@@ -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}}
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
58 changes: 21 additions & 37 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
>
<testsuites>
<testsuite name="Vormkracht10 Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<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">
<testsuites>
<testsuite name="Vormkracht10 Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
39 changes: 39 additions & 0 deletions phpunit.xml.dist.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
>
<testsuites>
<testsuite name="Vormkracht10 Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
22 changes: 11 additions & 11 deletions src/Transformations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion src/Transformations/BasicColorAdjustments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 6 additions & 3 deletions src/Transformations/ConvertToSRGB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Transformations/Crop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/Transformations/CropByObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/Transformations/CropByRatio.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)) {
Expand Down
7 changes: 6 additions & 1 deletion src/Transformations/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
9 changes: 7 additions & 2 deletions src/Transformations/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Transformations/Overlay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
7 changes: 6 additions & 1 deletion src/Transformations/Quality.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Transformations/Resize.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
7 changes: 6 additions & 1 deletion src/Transformations/SmartCrop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading
Loading