Skip to content

Commit 03d55ec

Browse files
authored
Merge pull request #28 from VincentLanglet/php8
Try Php 8
2 parents fd16b34 + a082da2 commit 03d55ec

File tree

11 files changed

+37
-32
lines changed

11 files changed

+37
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Tests/Resources/outputs/*
77
!Tests/Resources/outputs/.gitkeep
88

99
phpunit.xml
10+
.phpunit.result.cache

Command.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Command
7676
*/
7777
protected $version;
7878

79-
public function __construct(string $magickBinaryPath = null)
79+
public function __construct(?string $magickBinaryPath = null)
8080
{
8181
$magickBinaryPath = self::findMagickBinaryPath($magickBinaryPath);
8282

@@ -102,7 +102,7 @@ public function __construct(string $magickBinaryPath = null)
102102
$this->magickBinaryPath = $magickBinaryPath;
103103
}
104104

105-
public static function create(string $magickBinaryPath = null): self
105+
public static function create(?string $magickBinaryPath = null): self
106106
{
107107
return new self($magickBinaryPath);
108108
}
@@ -148,7 +148,7 @@ private static function cleanPath(string $path, bool $rtrim = false): string
148148
*
149149
* @see https://imagemagick.org/script/command-line-tools.php
150150
*/
151-
public function getExecutable(string $binary = null): array
151+
public function getExecutable(?string $binary = null): array
152152
{
153153
if (!\in_array($binary, static::ALLOWED_EXECUTABLES, true)) {
154154
throw new \InvalidArgumentException(\sprintf(
@@ -165,7 +165,7 @@ public function getExecutable(string $binary = null): array
165165
/**
166166
* Entirely reset all current command statements, and start a whole new command.
167167
*/
168-
public function newCommand(string $binary = null): self
168+
public function newCommand(?string $binary = null): self
169169
{
170170
$this->env = [];
171171
$this->command = $binary ? $this->getExecutable($binary) : [];
@@ -185,7 +185,7 @@ public function convert(string $sourceFile, bool $checkIfFileExists = true): sel
185185
/**
186186
* @see https://imagemagick.org/script/mogrify.php
187187
*/
188-
public function mogrify(string $sourceFile = null): self
188+
public function mogrify(?string $sourceFile = null): self
189189
{
190190
$this->newCommand('mogrify');
191191
if ($sourceFile) {
@@ -382,7 +382,6 @@ public function size($geometry): self
382382
/**
383383
* Create a colored canvas.
384384
*
385-
*
386385
* @see http://www.imagemagick.org/Usage/canvas/
387386
*/
388387
public function xc(string $canvasColor = 'none'): self
@@ -432,7 +431,7 @@ public function extent($geometry): self
432431
}
433432

434433
/**
435-
* @param string $gravity
434+
* @param string|Gravity $gravity
436435
*
437436
* @see https://www.imagemagick.org/script/command-line-options.php#gravity
438437
*/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ composer require orbitale/imagemagick-php
1919
Requirements
2020
===============
2121

22-
* PHP 7.1 or higher
22+
* PHP 7.2 or higher
2323
* [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.
2424

2525
Settings

ReferenceClasses/Geometry.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ class Geometry
3939
*/
4040
private $value;
4141

42+
/**
43+
* @param string|int|null $width
44+
*/
4245
public static function createFromParameters(
4346
$width = null,
44-
int $height = null,
45-
int $x = null,
46-
int $y = null,
47+
?int $height = null,
48+
?int $x = null,
49+
?int $y = null,
4750
?string $aspectRatio = self::RATIO_NONE
4851
): string {
4952
$geometry = $width;
@@ -74,20 +77,21 @@ public static function createFromParameters(
7477
$geometry .= ($y >= 0 ? '+' : '-').\abs($y);
7578
}
7679
} elseif (null !== $y) {
77-
if (null !== $y) {
78-
$geometry .= '+0'.($y >= 0 ? '+' : '-').\abs($y);
79-
}
80+
$geometry .= '+0'.($y >= 0 ? '+' : '-').\abs($y);
8081
}
8182

8283
return $geometry;
8384
}
8485

86+
/**
87+
* @param string|int|null $width
88+
*/
8589
public function __construct(
8690
$width = null,
87-
int $height = null,
88-
int $x = null,
89-
int $y = null,
90-
string $aspectRatio = self::RATIO_NONE
91+
?int $height = null,
92+
?int $x = null,
93+
?int $y = null,
94+
?string $aspectRatio = self::RATIO_NONE
9195
) {
9296
$args = \func_get_args();
9397

ReferenceClasses/Gravity.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ class Gravity
2828
*/
2929
private $value;
3030

31-
public static function createFromParameters(string $gravity): string {
31+
public static function createFromParameters(string $gravity): string
32+
{
3233
return $gravity;
3334
}
3435

35-
public function __construct(string $gravity) {
36+
public function __construct(string $gravity)
37+
{
3638
$this->value = $gravity;
3739
}
3840

References.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,5 @@ public function threshold(string $threshold): string
248248
$threshold,
249249
'http://www.imagemagick.org/script/command-line-options.php#threshold'
250250
));
251-
252251
}
253252
}

Tests/CommandTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testWrongConvertDirs($path, $expectedMessage, $expectedException
3434
$exception = $e->getMessage();
3535
$exceptionClass = \get_class($e);
3636
}
37-
static::assertContains($expectedMessage, $exception);
37+
static::assertStringContainsString($expectedMessage, $exception);
3838
static::assertEquals($expectedException, $exceptionClass);
3939
}
4040

@@ -236,7 +236,7 @@ public function testConvertIdentifyImage($imageToIdentify, $expectedFormat, $exp
236236

237237
$content = $response->getOutput();
238238

239-
static::assertContains(\sprintf(
239+
static::assertStringContainsString(\sprintf(
240240
'%s %s %s %s %s',
241241
$imageToIdentify,
242242
$expectedFormat,
@@ -321,11 +321,10 @@ public function provideTestCommandString(): ?\Generator
321321
yield [$this->resourcesDir.'/moon_180.jpg', $this->resourcesDir.'/outputs/moon_geometry.jpg', '30x30+20+20', 50];
322322
}
323323

324-
/**
325-
* @expectedException \InvalidArgumentException
326-
*/
327324
public function testWrongExecutable(): void
328325
{
326+
$this->expectException(\InvalidArgumentException::class);
327+
329328
$command = new Command(IMAGEMAGICK_DIR);
330329
$command->getExecutable('this_executable_might_not_exist');
331330
}
@@ -341,6 +340,6 @@ public function testInexistingFiles(): void
341340
} catch (\Exception $e) {
342341
$exception = $e->getMessage();
343342
}
344-
static::assertContains(\sprintf('The file "%s" is not found.', $file), $exception);
343+
static::assertStringContainsString(\sprintf('The file "%s" is not found.', $file), $exception);
345344
}
346345
}

Tests/References/ColorsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function testIncorrectColors($color): void
8181
} catch (\InvalidArgumentException $e) {
8282
$msg = $e->getMessage();
8383
}
84-
static::assertContains(
84+
static::assertStringContainsString(
8585
\sprintf('The specified color (%s) is invalid', $color),
8686
$msg
8787
);

Tests/References/ColorspaceValuesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testInvalidColorspaceValues($colorspaceValue): void
6666
} catch (\InvalidArgumentException $e) {
6767
$msg = $e->getMessage();
6868
}
69-
static::assertContains(
69+
static::assertStringContainsString(
7070
\sprintf('The specified colorspace value (%s) is invalid', \trim($colorspaceValue)),
7171
$msg
7272
);

Tests/References/InterlaceTypesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testInvalidInterlaceTypes($interlaceType): void
7070
} catch (\InvalidArgumentException $e) {
7171
$msg = $e->getMessage();
7272
}
73-
static::assertContains(
73+
static::assertStringContainsString(
7474
\sprintf('The specified interlace type (%s) is invalid', \mb_strtolower(\trim($interlaceType))),
7575
$msg
7676
);

0 commit comments

Comments
 (0)