diff --git a/phpcs.xml b/phpcs.xml index 3e412b4e..a6ca5c01 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -3,10 +3,6 @@ - - 0 - - src/ tests/ diff --git a/src/Colors/Rgb/Decoders/StringColorDecoder.php b/src/Colors/Rgb/Decoders/StringColorDecoder.php index 559fc359..c2b53604 100644 --- a/src/Colors/Rgb/Decoders/StringColorDecoder.php +++ b/src/Colors/Rgb/Decoders/StringColorDecoder.php @@ -21,11 +21,12 @@ class StringColorDecoder extends AbstractDecoder implements DecoderInterface */ public function decode(mixed $input): ImageInterface|ColorInterface { - if (! is_string($input)) { + if (!is_string($input)) { throw new DecoderException('Unable to decode input'); } - $pattern = '/^s?rgba?\((?P[0-9\.]+%?), ?(?P[0-9\.]+%?), ?(?P[0-9\.]+%?)(?:, ?(?P(?:1)|(?:1\.0*)|(?:0)|(?:0?\.\d+%?)|(?:\d{1,3}%)))?\)$/i'; + $pattern = '/^s?rgba?\((?P[0-9\.]+%?), ?(?P[0-9\.]+%?), ?(?P[0-9\.]+%?)' . + '(?:, ?(?P(?:1)|(?:1\.0*)|(?:0)|(?:0?\.\d+%?)|(?:\d{1,3}%)))?\)$/i'; if (preg_match($pattern, $input, $matches) != 1) { throw new DecoderException('Unable to decode input'); } diff --git a/tests/Drivers/Gd/InputHandlerTest.php b/tests/Drivers/Gd/InputHandlerTest.php index be376803..664e337b 100644 --- a/tests/Drivers/Gd/InputHandlerTest.php +++ b/tests/Drivers/Gd/InputHandlerTest.php @@ -61,7 +61,8 @@ class GdInputHandlerTest extends TestCase public function testHandleDataUriImage(): void { $handler = new InputHandler(); - $input = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; + $input = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNb' . + 'yblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; $result = $handler->handle($input); $this->assertInstanceOf(Image::class, $result); } diff --git a/tests/Drivers/Imagick/InputHandlerTest.php b/tests/Drivers/Imagick/InputHandlerTest.php index c2ee6f10..79e3de18 100644 --- a/tests/Drivers/Imagick/InputHandlerTest.php +++ b/tests/Drivers/Imagick/InputHandlerTest.php @@ -61,7 +61,8 @@ class InputHandlerTest extends TestCase public function testHandleDataUriImage(): void { $handler = new InputHandler(); - $input = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; + $input = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACN' . + 'byblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; $result = $handler->handle($input); $this->assertInstanceOf(Image::class, $result); }