Skip to content

Commit d272bfe

Browse files
committed
refactor: simplify ImageMagickHandler::getVersion()
1 parent 3503b4d commit d272bfe

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

system/Images/Handlers/ImageMagickHandler.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,10 @@ protected function _flip(string $direction)
167167
*/
168168
public function getVersion(): string
169169
{
170-
$result = $this->process('-version');
170+
$versionString = $this->process('-version')[0];
171+
preg_match('/ImageMagick\s(?P<version>[\S]+)/', $versionString, $matches);
171172

172-
// The first line has the version in it...
173-
preg_match('/(ImageMagick\s[\S]+)/', $result[0], $matches);
174-
175-
return str_replace('ImageMagick ', '', $matches[0]);
173+
return $matches['version'];
176174
}
177175

178176
/**

tests/system/Images/ImageMagickHandlerTest.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ protected function setUp(): void
8080
public function testGetVersion(): void
8181
{
8282
$version = $this->handler->getVersion();
83-
// make sure that the call worked
84-
$this->assertNotFalse($version);
85-
// we should have a numeric version, greater than 6
86-
$this->assertGreaterThanOrEqual(0, version_compare($version, '6.0.0'));
87-
$this->assertLessThan(0, version_compare($version, '99.0.0'));
83+
84+
$this->assertNotSame('', $version);
85+
$this->assertTrue(version_compare($version, '6.0.0', '>'));
86+
$this->assertTrue(version_compare($version, '99.0.0', '<'));
8887
}
8988

9089
public function testImageProperties(): void

0 commit comments

Comments
 (0)