From de845b23ccdcfdd31d21cbe3ca6097af97e2aa0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Felix=20=C5=A0ulc?= Date: Tue, 2 Jan 2024 15:14:04 +0100 Subject: [PATCH] Code: apply phpstan --- phpstan-baseline.neon | 146 +++++++++++++++++++++++++++++++ phpstan.neon | 1 + src/DI/ImageStorageExtension.php | 11 ++- src/ImageNameScript.php | 2 +- src/Latte/LatteExtension.php | 2 +- 5 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 phpstan-baseline.neon diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..829fb07 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,146 @@ +parameters: + ignoreErrors: + - + message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" + count: 1 + path: src/Image.php + + - + message: "#^Variable property access on \\$this\\(Contributte\\\\ImageStorage\\\\Image\\)\\.$#" + count: 1 + path: src/Image.php + + - + message: "#^Only booleans are allowed in &&, array\\ given on the left side\\.$#" + count: 1 + path: src/ImageNameScript.php + + - + message: "#^Only booleans are allowed in &&, int given on the right side\\.$#" + count: 2 + path: src/ImageNameScript.php + + - + message: "#^Only booleans are allowed in &&, string given on the left side\\.$#" + count: 1 + path: src/ImageNameScript.php + + - + message: "#^Only booleans are allowed in &&, string given on the right side\\.$#" + count: 3 + path: src/ImageNameScript.php + + - + message: "#^Only booleans are allowed in an if condition, array\\ given\\.$#" + count: 1 + path: src/ImageNameScript.php + + - + message: "#^Only booleans are allowed in an if condition, int given\\.$#" + count: 2 + path: src/ImageNameScript.php + + - + message: "#^Only booleans are allowed in an if condition, int\\<0, max\\> given\\.$#" + count: 2 + path: src/ImageNameScript.php + + - + message: "#^Parameter \\#1 \\$pattern of function preg_match expects string, string\\|null given\\.$#" + count: 1 + path: src/ImageNameScript.php + + - + message: "#^Cannot use array destructuring on array\\\\|Contributte\\\\ImageStorage\\\\Image\\.$#" + count: 2 + path: src/ImageStorage.php + + - + message: "#^Method Contributte\\\\ImageStorage\\\\ImageStorage\\:\\:fromIdentifier\\(\\) should return Contributte\\\\ImageStorage\\\\Image but returns array\\\\|Contributte\\\\ImageStorage\\\\Image\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Only booleans are allowed in &&, int given on the right side\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Only booleans are allowed in a negated boolean, int given\\.$#" + count: 2 + path: src/ImageStorage.php + + - + message: "#^Only booleans are allowed in a negated boolean, int\\|false given\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Only booleans are allowed in a negated boolean, string given\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Only booleans are allowed in a negated boolean, string\\|null given\\.$#" + count: 2 + path: src/ImageStorage.php + + - + message: "#^Parameter \\#1 \\$name of static method Contributte\\\\ImageStorage\\\\ImageNameScript\\:\\:fromName\\(\\) expects string, mixed given\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Parameter \\#1 \\$pattern of function preg_match expects string, string\\|null given\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Parameter \\#1 \\$s of static method Nette\\\\Utils\\\\Image\\:\\:fromString\\(\\) expects string, string\\|false given\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Parameter \\#3 \\$checksum of method Contributte\\\\ImageStorage\\\\ImageStorage\\:\\:getSavePath\\(\\) expects string, mixed given\\.$#" + count: 2 + path: src/ImageStorage.php + + - + message: "#^Parameter \\#3 \\$mode of method Nette\\\\Utils\\\\Image\\:\\:resize\\(\\) expects int\\<0, 15\\>, int given\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Parameter \\#5 \\$props of class Contributte\\\\ImageStorage\\\\Image constructor expects array\\, array\\ given\\.$#" + count: 2 + path: src/ImageStorage.php + + - + message: "#^Right side of && is always true\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Undefined variable\\: \\$i$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Variable \\$i might not be defined\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Variable \\$path might not be defined\\.$#" + count: 1 + path: src/ImageStorage.php + + - + message: "#^Return type \\(array\\) of method Contributte\\\\ImageStorage\\\\Latte\\\\LatteExtension\\:\\:getTags\\(\\) should be covariant with return type \\(array\\\\) of method Latte\\\\Extension\\:\\:getTags\\(\\)$#" + count: 1 + path: src/Latte/LatteExtension.php diff --git a/phpstan.neon b/phpstan.neon index 562ab05..d0fc1d3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ includes: - vendor/contributte/phpstan/phpstan.neon + - phpstan-baseline.neon parameters: level: 9 diff --git a/src/DI/ImageStorageExtension.php b/src/DI/ImageStorageExtension.php index 4e741eb..0d0d406 100644 --- a/src/DI/ImageStorageExtension.php +++ b/src/DI/ImageStorageExtension.php @@ -8,7 +8,11 @@ use Nette\DI\Definitions\FactoryDefinition; use Nette\Schema\Expect; use Nette\Schema\Schema; +use stdClass; +/** + * @method stdClass getConfig() + */ class ImageStorageExtension extends CompilerExtension { @@ -30,12 +34,13 @@ public function getConfigSchema(): Schema public function loadConfiguration(): void { $builder = $this->getContainerBuilder(); - $this->config->orig_path ??= $this->config->data_path; - $config = (array) $this->config; + $config = $this->getConfig(); + $config->orig_path ??= $config->data_path; + $builder->addDefinition($this->prefix('storage')) ->setType(ImageStorage::class) ->setFactory(ImageStorage::class) - ->setArguments($config); + ->setArguments((array) $config); } public function beforeCompile(): void diff --git a/src/ImageNameScript.php b/src/ImageNameScript.php index 4d6a84c..b375b07 100644 --- a/src/ImageNameScript.php +++ b/src/ImageNameScript.php @@ -58,7 +58,7 @@ public static function fromName(string $name): ImageNameScript $script->name = $matches[3]; $script->size = [(int) $matches[5], (int) $matches[6]]; $script->flag = $matches[12]; - $script->quality = $matches[14]; + $script->quality = intval($matches[14]); $script->extension = $matches[15]; if ($matches[8] && $matches[9] && $matches[10] && $matches[11]) { diff --git a/src/Latte/LatteExtension.php b/src/Latte/LatteExtension.php index d4383b7..e22cb00 100644 --- a/src/Latte/LatteExtension.php +++ b/src/Latte/LatteExtension.php @@ -12,7 +12,7 @@ class LatteExtension extends Extension { /** - * @return array + * @return array */ public function getTags(): array {