From 487b176201905881df625341e5e7f01da1df871c Mon Sep 17 00:00:00 2001 From: Sibin Grasic Date: Wed, 17 Jan 2024 22:33:40 +0100 Subject: [PATCH 1/6] chore: Added PHPCS and config --- .editorconfig | 14 ++++++++++++++ composer.json | 9 ++++++++- phpcs.xml | 11 +++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 phpcs.xml 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/composer.json b/composer.json index 1f864429..d842b35f 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,9 @@ "require-dev": { "phpunit/phpunit": "^9", "mockery/mockery": "^1.6", - "phpstan/phpstan": "^1" + "phpstan/phpstan": "^1", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "squizlabs/php_codesniffer": "^3.8" }, "suggest": { "ext-exif": "Recommended to be able to read EXIF data properly." @@ -34,5 +36,10 @@ "psr-4": { "Intervention\\Image\\Tests\\": "tests" } + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..1f034a16 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,11 @@ + + + + + + + 0 + + + src/ + From 598981d743601f41f8ccaa10057c26ae58205bd1 Mon Sep 17 00:00:00 2001 From: Sibin Grasic Date: Thu, 18 Jan 2024 11:37:09 +0100 Subject: [PATCH 2/6] fix: Standardizing config --- .gitattributes | 18 ++++++++++-------- phpcs.xml | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) 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/phpcs.xml b/phpcs.xml index 1f034a16..3e412b4e 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -8,4 +8,5 @@ src/ + tests/ From b2b8581880e8d1cb9a13caa82b02e720c2b0f3c9 Mon Sep 17 00:00:00 2001 From: Sibin Grasic Date: Thu, 18 Jan 2024 12:50:42 +0100 Subject: [PATCH 3/6] revert(deps): PHPCS-Plugin installer package removed --- composer.json | 84 +++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/composer.json b/composer.json index d842b35f..edaf37a5 100644 --- a/composer.json +++ b/composer.json @@ -1,45 +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", - "dealerdirect/phpcodesniffer-composer-installer": "^1.0", - "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" - } - }, - "config": { - "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true - } + "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" + } + } } From 5c25680390fda4676c78d57842458511a4034d79 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 18 Jan 2024 14:03:21 +0100 Subject: [PATCH 4/6] Add validation of coding standards to github workflow Project standards and files to be checked are configured in phpcs.xml. --- .github/workflows/run-tests.yml | 3 +++ 1 file changed, 3 insertions(+) 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 From 13ce4e94c14dd5919e7b18378872224067796af6 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 18 Jan 2024 14:12:54 +0100 Subject: [PATCH 5/6] Add code standards check to dev environment --- docker-compose.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 From d356930d73accda5ae225eac8fdf516cd283e0a6 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 18 Jan 2024 14:13:54 +0100 Subject: [PATCH 6/6] Include line length check in code standards --- phpcs.xml | 4 ---- src/Colors/Rgb/Decoders/StringColorDecoder.php | 5 +++-- tests/Drivers/Gd/InputHandlerTest.php | 3 ++- tests/Drivers/Imagick/InputHandlerTest.php | 3 ++- 4 files changed, 7 insertions(+), 8 deletions(-) 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); }