diff --git a/.gitignore b/.gitignore index e938c8b..60d3ddf 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ Tests/Resources/outputs/* !Tests/Resources/outputs/.gitkeep phpunit.xml +.phpunit.result.cache diff --git a/Command.php b/Command.php index 91aa78b..fae8238 100644 --- a/Command.php +++ b/Command.php @@ -76,7 +76,7 @@ class Command */ protected $version; - public function __construct(string $magickBinaryPath = null) + public function __construct(?string $magickBinaryPath = null) { $magickBinaryPath = self::findMagickBinaryPath($magickBinaryPath); @@ -102,7 +102,7 @@ public function __construct(string $magickBinaryPath = null) $this->magickBinaryPath = $magickBinaryPath; } - public static function create(string $magickBinaryPath = null): self + public static function create(?string $magickBinaryPath = null): self { return new self($magickBinaryPath); } @@ -148,7 +148,7 @@ private static function cleanPath(string $path, bool $rtrim = false): string * * @see https://imagemagick.org/script/command-line-tools.php */ - public function getExecutable(string $binary = null): array + public function getExecutable(?string $binary = null): array { if (!\in_array($binary, static::ALLOWED_EXECUTABLES, true)) { throw new \InvalidArgumentException(\sprintf( @@ -165,7 +165,7 @@ public function getExecutable(string $binary = null): array /** * Entirely reset all current command statements, and start a whole new command. */ - public function newCommand(string $binary = null): self + public function newCommand(?string $binary = null): self { $this->env = []; $this->command = $binary ? $this->getExecutable($binary) : []; @@ -185,7 +185,7 @@ public function convert(string $sourceFile, bool $checkIfFileExists = true): sel /** * @see https://imagemagick.org/script/mogrify.php */ - public function mogrify(string $sourceFile = null): self + public function mogrify(?string $sourceFile = null): self { $this->newCommand('mogrify'); if ($sourceFile) { @@ -382,7 +382,6 @@ public function size($geometry): self /** * Create a colored canvas. * - * * @see http://www.imagemagick.org/Usage/canvas/ */ public function xc(string $canvasColor = 'none'): self @@ -432,7 +431,7 @@ public function extent($geometry): self } /** - * @param string $gravity + * @param string|Gravity $gravity * * @see https://www.imagemagick.org/script/command-line-options.php#gravity */ diff --git a/README.md b/README.md index 6fad9be..47e7d07 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ composer require orbitale/imagemagick-php Requirements =============== -* PHP 7.1 or higher +* PHP 7.2 or higher * [ImageMagick 7](https://www.imagemagick.org/) has to be installed on your server, and the binaries must be executable by the user running the PHP process. Settings diff --git a/ReferenceClasses/Geometry.php b/ReferenceClasses/Geometry.php index e1dbe1e..1839b95 100644 --- a/ReferenceClasses/Geometry.php +++ b/ReferenceClasses/Geometry.php @@ -39,11 +39,14 @@ class Geometry */ private $value; + /** + * @param string|int|null $width + */ public static function createFromParameters( $width = null, - int $height = null, - int $x = null, - int $y = null, + ?int $height = null, + ?int $x = null, + ?int $y = null, ?string $aspectRatio = self::RATIO_NONE ): string { $geometry = $width; @@ -74,20 +77,21 @@ public static function createFromParameters( $geometry .= ($y >= 0 ? '+' : '-').\abs($y); } } elseif (null !== $y) { - if (null !== $y) { - $geometry .= '+0'.($y >= 0 ? '+' : '-').\abs($y); - } + $geometry .= '+0'.($y >= 0 ? '+' : '-').\abs($y); } return $geometry; } + /** + * @param string|int|null $width + */ public function __construct( $width = null, - int $height = null, - int $x = null, - int $y = null, - string $aspectRatio = self::RATIO_NONE + ?int $height = null, + ?int $x = null, + ?int $y = null, + ?string $aspectRatio = self::RATIO_NONE ) { $args = \func_get_args(); diff --git a/ReferenceClasses/Gravity.php b/ReferenceClasses/Gravity.php index c5a7a16..0f91383 100644 --- a/ReferenceClasses/Gravity.php +++ b/ReferenceClasses/Gravity.php @@ -28,11 +28,13 @@ class Gravity */ private $value; - public static function createFromParameters(string $gravity): string { + public static function createFromParameters(string $gravity): string + { return $gravity; } - public function __construct(string $gravity) { + public function __construct(string $gravity) + { $this->value = $gravity; } diff --git a/References.php b/References.php index 4a67f24..aeb59cf 100644 --- a/References.php +++ b/References.php @@ -248,6 +248,5 @@ public function threshold(string $threshold): string $threshold, 'http://www.imagemagick.org/script/command-line-options.php#threshold' )); - } } diff --git a/Tests/CommandTest.php b/Tests/CommandTest.php index 4300dd3..a67465e 100644 --- a/Tests/CommandTest.php +++ b/Tests/CommandTest.php @@ -34,7 +34,7 @@ public function testWrongConvertDirs($path, $expectedMessage, $expectedException $exception = $e->getMessage(); $exceptionClass = \get_class($e); } - static::assertContains($expectedMessage, $exception); + static::assertStringContainsString($expectedMessage, $exception); static::assertEquals($expectedException, $exceptionClass); } @@ -236,7 +236,7 @@ public function testConvertIdentifyImage($imageToIdentify, $expectedFormat, $exp $content = $response->getOutput(); - static::assertContains(\sprintf( + static::assertStringContainsString(\sprintf( '%s %s %s %s %s', $imageToIdentify, $expectedFormat, @@ -321,11 +321,10 @@ public function provideTestCommandString(): ?\Generator yield [$this->resourcesDir.'/moon_180.jpg', $this->resourcesDir.'/outputs/moon_geometry.jpg', '30x30+20+20', 50]; } - /** - * @expectedException \InvalidArgumentException - */ public function testWrongExecutable(): void { + $this->expectException(\InvalidArgumentException::class); + $command = new Command(IMAGEMAGICK_DIR); $command->getExecutable('this_executable_might_not_exist'); } @@ -341,6 +340,6 @@ public function testInexistingFiles(): void } catch (\Exception $e) { $exception = $e->getMessage(); } - static::assertContains(\sprintf('The file "%s" is not found.', $file), $exception); + static::assertStringContainsString(\sprintf('The file "%s" is not found.', $file), $exception); } } diff --git a/Tests/References/ColorsTest.php b/Tests/References/ColorsTest.php index 260f350..9e8c264 100644 --- a/Tests/References/ColorsTest.php +++ b/Tests/References/ColorsTest.php @@ -81,7 +81,7 @@ public function testIncorrectColors($color): void } catch (\InvalidArgumentException $e) { $msg = $e->getMessage(); } - static::assertContains( + static::assertStringContainsString( \sprintf('The specified color (%s) is invalid', $color), $msg ); diff --git a/Tests/References/ColorspaceValuesTest.php b/Tests/References/ColorspaceValuesTest.php index 7e7bf0f..360a728 100644 --- a/Tests/References/ColorspaceValuesTest.php +++ b/Tests/References/ColorspaceValuesTest.php @@ -66,7 +66,7 @@ public function testInvalidColorspaceValues($colorspaceValue): void } catch (\InvalidArgumentException $e) { $msg = $e->getMessage(); } - static::assertContains( + static::assertStringContainsString( \sprintf('The specified colorspace value (%s) is invalid', \trim($colorspaceValue)), $msg ); diff --git a/Tests/References/InterlaceTypesTest.php b/Tests/References/InterlaceTypesTest.php index 6416c45..3b63c52 100644 --- a/Tests/References/InterlaceTypesTest.php +++ b/Tests/References/InterlaceTypesTest.php @@ -70,7 +70,7 @@ public function testInvalidInterlaceTypes($interlaceType): void } catch (\InvalidArgumentException $e) { $msg = $e->getMessage(); } - static::assertContains( + static::assertStringContainsString( \sprintf('The specified interlace type (%s) is invalid', \mb_strtolower(\trim($interlaceType))), $msg ); diff --git a/composer.json b/composer.json index b49664b..c8fbd66 100644 --- a/composer.json +++ b/composer.json @@ -13,11 +13,12 @@ } ], "require": { - "php": "^7.2", + "php": "^7.2|^8.0", + "ext-mbstring": "*", "symfony/process": "^4.0|^5.0" }, "require-dev": { - "phpunit/phpunit": "^7.5" + "phpunit/phpunit": "^8.5|^9.5" }, "minimum-stability": "stable", "autoload": {