diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..09a9fd89 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.php] +indent_size = 4 diff --git a/.gitattributes b/.gitattributes index a978f604..4ca696b8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,11 +1,13 @@ * text=auto -/.github export-ignore -/tests export-ignore -/.github export-ignore -/.gitattributes export-ignore -/.gitignore export-ignore -/phpunit.xml export-ignore -/phpunit.xml.dist export-ignore +/.editorconfig export-ignore +/.github export-ignore +/tests export-ignore +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/phpcs.xml export-ignore +/phpunit.xml export-ignore +/phpunit.xml.dist export-ignore /docker-compose.yml export-ignore -/Dockerfile export-ignore +/Dockerfile export-ignore diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index c33fcdef..817190e4 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -100,3 +100,6 @@ jobs: - name: Run analyzer run: vendor/bin/phpstan analyze --level=4 ./src + + - name: Validate coding standards + run: vendor/bin/phpcs diff --git a/composer.json b/composer.json index 1f864429..edaf37a5 100644 --- a/composer.json +++ b/composer.json @@ -1,38 +1,45 @@ { - "name": "intervention/image", - "description": "PHP image manipulation", - "homepage": "https://image.intervention.io/", - "keywords": ["image", "gd", "imagick", "watermark", "thumbnail", "resize"], - "license": "MIT", - "authors": [ - { - "name": "Oliver Vogel", - "email": "oliver@intervention.io", - "homepage": "https://intervention.io/" - } - ], - "require": { - "php": "^8.1", - "ext-mbstring": "*", - "intervention/gif": "^4" - }, - "require-dev": { - "phpunit/phpunit": "^9", - "mockery/mockery": "^1.6", - "phpstan/phpstan": "^1" - }, - "suggest": { - "ext-exif": "Recommended to be able to read EXIF data properly." - - }, - "autoload": { - "psr-4": { - "Intervention\\Image\\": "src" - } - }, - "autoload-dev": { - "psr-4": { - "Intervention\\Image\\Tests\\": "tests" - } + "name": "intervention/image", + "description": "PHP image manipulation", + "homepage": "https://image.intervention.io/", + "keywords": [ + "image", + "gd", + "imagick", + "watermark", + "thumbnail", + "resize" + ], + "license": "MIT", + "authors": [ + { + "name": "Oliver Vogel", + "email": "oliver@intervention.io", + "homepage": "https://intervention.io/" } + ], + "require": { + "php": "^8.1", + "ext-mbstring": "*", + "intervention/gif": "^4" + }, + "require-dev": { + "phpunit/phpunit": "^9", + "mockery/mockery": "^1.6", + "phpstan/phpstan": "^1", + "squizlabs/php_codesniffer": "^3.8" + }, + "suggest": { + "ext-exif": "Recommended to be able to read EXIF data properly." + }, + "autoload": { + "psr-4": { + "Intervention\\Image\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Intervention\\Image\\Tests\\": "tests" + } + } } diff --git a/docker-compose.yml b/docker-compose.yml index 890602f0..fa749c11 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ version: '3' -services: +services: tests: build: ./ working_dir: /project @@ -21,3 +21,9 @@ services: command: bash -c "composer install && ./vendor/bin/phpstan analyze --memory-limit=512M --level=4 ./src" volumes: - ./:/project + standards: + build: ./ + working_dir: /project + command: bash -c "composer install && ./vendor/bin/phpcs" + volumes: + - ./:/project diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..a6ca5c01 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,8 @@ + + + + + + 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); }