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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Tests/Resources/outputs/*
!Tests/Resources/outputs/.gitkeep

phpunit.xml
.phpunit.result.cache
13 changes: 6 additions & 7 deletions Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Command
*/
protected $version;

public function __construct(string $magickBinaryPath = null)
public function __construct(?string $magickBinaryPath = null)
{
$magickBinaryPath = self::findMagickBinaryPath($magickBinaryPath);

Expand All @@ -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);
}
Expand Down Expand Up @@ -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(
Expand All @@ -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) : [];
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 14 additions & 10 deletions ReferenceClasses/Geometry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
6 changes: 4 additions & 2 deletions ReferenceClasses/Gravity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 0 additions & 1 deletion References.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,5 @@ public function threshold(string $threshold): string
$threshold,
'http://www.imagemagick.org/script/command-line-options.php#threshold'
));

}
}
11 changes: 5 additions & 6 deletions Tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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');
}
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion Tests/References/ColorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/References/ColorspaceValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/References/InterlaceTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down