1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-01 01:51:43 +02:00

Merge pull request #1276 from Intervention/oblakstudio-feat/phpcs

Oblakstudio feat/phpcs
This commit is contained in:
Oliver Vogel
2024-01-18 14:19:35 +01:00
committed by GitHub
9 changed files with 91 additions and 48 deletions

14
.editorconfig Normal file
View File

@@ -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

18
.gitattributes vendored
View File

@@ -1,11 +1,13 @@
* text=auto * text=auto
/.github export-ignore /.editorconfig export-ignore
/tests export-ignore /.github export-ignore
/.github export-ignore /tests export-ignore
/.gitattributes export-ignore /.github export-ignore
/.gitignore export-ignore /.gitattributes export-ignore
/phpunit.xml export-ignore /.gitignore export-ignore
/phpunit.xml.dist export-ignore /phpcs.xml export-ignore
/phpunit.xml export-ignore
/phpunit.xml.dist export-ignore
/docker-compose.yml export-ignore /docker-compose.yml export-ignore
/Dockerfile export-ignore /Dockerfile export-ignore

View File

@@ -100,3 +100,6 @@ jobs:
- name: Run analyzer - name: Run analyzer
run: vendor/bin/phpstan analyze --level=4 ./src run: vendor/bin/phpstan analyze --level=4 ./src
- name: Validate coding standards
run: vendor/bin/phpcs

View File

@@ -1,38 +1,45 @@
{ {
"name": "intervention/image", "name": "intervention/image",
"description": "PHP image manipulation", "description": "PHP image manipulation",
"homepage": "https://image.intervention.io/", "homepage": "https://image.intervention.io/",
"keywords": ["image", "gd", "imagick", "watermark", "thumbnail", "resize"], "keywords": [
"license": "MIT", "image",
"authors": [ "gd",
{ "imagick",
"name": "Oliver Vogel", "watermark",
"email": "oliver@intervention.io", "thumbnail",
"homepage": "https://intervention.io/" "resize"
} ],
], "license": "MIT",
"require": { "authors": [
"php": "^8.1", {
"ext-mbstring": "*", "name": "Oliver Vogel",
"intervention/gif": "^4" "email": "oliver@intervention.io",
}, "homepage": "https://intervention.io/"
"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"
}
} }
],
"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"
}
}
} }

View File

@@ -1,6 +1,6 @@
version: '3' version: '3'
services: services:
tests: tests:
build: ./ build: ./
working_dir: /project working_dir: /project
@@ -21,3 +21,9 @@ services:
command: bash -c "composer install && ./vendor/bin/phpstan analyze --memory-limit=512M --level=4 ./src" command: bash -c "composer install && ./vendor/bin/phpstan analyze --memory-limit=512M --level=4 ./src"
volumes: volumes:
- ./:/project - ./:/project
standards:
build: ./
working_dir: /project
command: bash -c "composer install && ./vendor/bin/phpcs"
volumes:
- ./:/project

8
phpcs.xml Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset name="Intervention/image">
<rule ref="PSR12"/>
<file>src/</file>
<file>tests/</file>
</ruleset>

View File

@@ -21,11 +21,12 @@ class StringColorDecoder extends AbstractDecoder implements DecoderInterface
*/ */
public function decode(mixed $input): ImageInterface|ColorInterface public function decode(mixed $input): ImageInterface|ColorInterface
{ {
if (! is_string($input)) { if (!is_string($input)) {
throw new DecoderException('Unable to decode input'); throw new DecoderException('Unable to decode input');
} }
$pattern = '/^s?rgba?\((?P<r>[0-9\.]+%?), ?(?P<g>[0-9\.]+%?), ?(?P<b>[0-9\.]+%?)(?:, ?(?P<a>(?:1)|(?:1\.0*)|(?:0)|(?:0?\.\d+%?)|(?:\d{1,3}%)))?\)$/i'; $pattern = '/^s?rgba?\((?P<r>[0-9\.]+%?), ?(?P<g>[0-9\.]+%?), ?(?P<b>[0-9\.]+%?)' .
'(?:, ?(?P<a>(?:1)|(?:1\.0*)|(?:0)|(?:0?\.\d+%?)|(?:\d{1,3}%)))?\)$/i';
if (preg_match($pattern, $input, $matches) != 1) { if (preg_match($pattern, $input, $matches) != 1) {
throw new DecoderException('Unable to decode input'); throw new DecoderException('Unable to decode input');
} }

View File

@@ -61,7 +61,8 @@ class GdInputHandlerTest extends TestCase
public function testHandleDataUriImage(): void public function testHandleDataUriImage(): void
{ {
$handler = new InputHandler(); $handler = new InputHandler();
$input = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; $input = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNb' .
'yblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
$result = $handler->handle($input); $result = $handler->handle($input);
$this->assertInstanceOf(Image::class, $result); $this->assertInstanceOf(Image::class, $result);
} }

View File

@@ -61,7 +61,8 @@ class InputHandlerTest extends TestCase
public function testHandleDataUriImage(): void public function testHandleDataUriImage(): void
{ {
$handler = new InputHandler(); $handler = new InputHandler();
$input = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; $input = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACN' .
'byblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
$result = $handler->handle($input); $result = $handler->handle($input);
$this->assertInstanceOf(Image::class, $result); $this->assertInstanceOf(Image::class, $result);
} }