Skip to content

Commit 7ca24b2

Browse files
authored
Merge pull request #8681 from paulbalandan/imagemagick-getversion
refactor: simplify ImageMagickHandler::getVersion()
2 parents f22b8cf + d272bfe commit 7ca24b2

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
@@ -181,12 +181,10 @@ protected function _flip(string $direction)
181181
*/
182182
public function getVersion(): string
183183
{
184-
$result = $this->process('-version');
184+
$versionString = $this->process('-version')[0];
185+
preg_match('/ImageMagick\s(?P<version>[\S]+)/', $versionString, $matches);
185186

186-
// The first line has the version in it...
187-
preg_match('/(ImageMagick\s[\S]+)/', $result[0], $matches);
188-
189-
return str_replace('ImageMagick ', '', $matches[0]);
187+
return $matches['version'];
190188
}
191189

192190
/**

tests/system/Images/ImageMagickHandlerTest.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,10 @@ public static function provideNonexistentLibraryPathTerminatesProcessing(): iter
108108
public function testGetVersion(): void
109109
{
110110
$version = $this->handler->getVersion();
111-
// make sure that the call worked
112-
$this->assertNotFalse($version);
113-
// we should have a numeric version, greater than 6
114-
$this->assertGreaterThanOrEqual(0, version_compare($version, '6.0.0'));
115-
$this->assertLessThan(0, version_compare($version, '99.0.0'));
111+
112+
$this->assertNotSame('', $version);
113+
$this->assertTrue(version_compare($version, '6.0.0', '>'));
114+
$this->assertTrue(version_compare($version, '99.0.0', '<'));
116115
}
117116

118117
public function testImageProperties(): void

0 commit comments

Comments
 (0)