Skip to content

Commit

Permalink
Code: apply phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jan 2, 2024
1 parent 293cfe6 commit de845b2
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 5 deletions.
146 changes: 146 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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\\<int\\> 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\\<int\\> 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\\<int, Contributte\\\\ImageStorage\\\\ImageNameScript\\|string\\>\\|Contributte\\\\ImageStorage\\\\Image\\.$#"
count: 2
path: src/ImageStorage.php

-
message: "#^Method Contributte\\\\ImageStorage\\\\ImageStorage\\:\\:fromIdentifier\\(\\) should return Contributte\\\\ImageStorage\\\\Image but returns array\\<int, Contributte\\\\ImageStorage\\\\ImageNameScript\\|string\\>\\|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\\<bool\\|Contributte\\\\ImageStorage\\\\ImageNameScript\\|string\\|null\\>, array\\<string, mixed\\> 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\\<string, \\(callable\\(Latte\\\\Compiler\\\\Tag, Latte\\\\Compiler\\\\TemplateParser\\)\\: \\(Generator\\|Latte\\\\Compiler\\\\Node\\|void\\)\\)\\|stdClass\\>\\) of method Latte\\\\Extension\\:\\:getTags\\(\\)$#"
count: 1
path: src/Latte/LatteExtension.php
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
includes:
- vendor/contributte/phpstan/phpstan.neon
- phpstan-baseline.neon

parameters:
level: 9
Expand Down
11 changes: 8 additions & 3 deletions src/DI/ImageStorageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ImageNameScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/LatteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LatteExtension extends Extension
{

/**
* @return array<string, callable>
* @return array<mixed>
*/
public function getTags(): array
{
Expand Down

0 comments on commit de845b2

Please sign in to comment.