diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6594e5d7..e618855e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: strategy: matrix: php-version: - - '7.4' + - '8.1' steps: - @@ -52,7 +52,7 @@ jobs: strategy: matrix: php-version: - - '7.4' + - '8.1' steps: - @@ -85,8 +85,10 @@ jobs: strategy: matrix: php-version: - - '7.4' - - '8.0' + - '8.1' + - '8.2' + - '8.3' + - '8.4' steps: - diff --git a/.gitignore b/.gitignore index e87ba04f..9844e1a0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ /tests/Assets/workspace /phpbench.json /composer.lock -/.php_cs.cache /stubs /.vscode -.php_cs.cache \ No newline at end of file +.phpunit.result.cache +.php-cs-fixer.cache diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 88% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index 2820b890..2c205486 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -8,7 +8,8 @@ ]) ; -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config()) + ->setRiskyAllowed(true) ->setRules([ '@PSR2' => true, 'no_unused_imports' => true, diff --git a/composer.json b/composer.json index 2f4e1cb9..d79d7583 100644 --- a/composer.json +++ b/composer.json @@ -10,15 +10,15 @@ } ], "require": { - "php": "^7.3 || ^8.0" + "php": "^8.1" }, "require-dev": { "ergebnis/composer-normalize": "^2.0", - "friendsofphp/php-cs-fixer": "^2.17", - "infection/infection": "^0.18.0", - "phpstan/phpstan": "~0.12.0", - "phpunit/phpunit": "^9.0", - "symfony/var-dumper": "^6.1" + "phpstan/phpstan": "^2.0", + "phpunit/phpunit": "^10.0", + "symfony/var-dumper": "^6.0|^7.1", + "infection/infection": "^0.29.0", + "friendsofphp/php-cs-fixer": "^3.91" }, "extra": { "branch-alias": { @@ -40,7 +40,7 @@ "scripts": { "integrate": [ "./vendor/bin/phpunit", - "./vendor/bin/phpstan analyze", + "./vendor/bin/phpstan analyze --memory-limit=-1", "./vendor/bin/php-cs-fixer fix --allow-risky=yes" ] }, diff --git a/lib/Resolver.php b/lib/Resolver.php index 73a68fc8..0be9c486 100644 --- a/lib/Resolver.php +++ b/lib/Resolver.php @@ -118,11 +118,7 @@ public function resolve(array $config): array if ($diff = array_diff(array_keys($config), $allowedKeys)) { $this->throwOrLogError( - new InvalidMap(sprintf( - 'Key(s) "%s" are not known, known keys: "%s"', - implode('", "', ($diff)), - implode('", "', $allowedKeys) - )) + UnknownKeys::fromKeysAndAllowedKeys(array_values($diff), $allowedKeys) ); $config = $this->removeKeys($config, $diff); @@ -227,12 +223,12 @@ public function errors(): ResolverErrors } /** - * @return array + * @return list */ private function resolveAllowedKeys(): array { $allowedKeys = array_merge(array_keys($this->defaults), $this->required); - return $allowedKeys; + return array_values($allowedKeys); } private function throwOrLogError(InvalidMap $error): void diff --git a/lib/UnknownKeys.php b/lib/UnknownKeys.php new file mode 100644 index 00000000..3078eae4 --- /dev/null +++ b/lib/UnknownKeys.php @@ -0,0 +1,44 @@ + $allowedKeys + * @param list $keys + */ + public function __construct(string $message, private array $keys, private array $allowedKeys) + { + parent::__construct($message); + } + + /** + * @return list + */ + public function additionalKeys(): array + { + return $this->keys; + } + + /** + * @return list + */ + public function allowedKeys(): array + { + return $this->allowedKeys; + } + + /** + * @param list $allowedKeys + * @param list $diff + */ + public static function fromKeysAndAllowedKeys(array $diff, array $allowedKeys): self + { + return new self(sprintf( + 'Key(s) "%s" are not known, known keys: "%s"', + implode('", "', ($diff)), + implode('", "', $allowedKeys), + ), $diff, $allowedKeys); + } +} diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index cb7f36fd..364905f7 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,7 +1,2 @@ parameters: ignoreErrors: - - - message: "#^Method Phpactor\\\\MapResolver\\\\Resolver\\:\\:resolveDescriptions\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: lib/Resolver.php - diff --git a/tests/Unit/ResolverTest.php b/tests/Unit/ResolverTest.php index 50e31dd1..65042e2f 100644 --- a/tests/Unit/ResolverTest.php +++ b/tests/Unit/ResolverTest.php @@ -5,6 +5,7 @@ use PHPUnit\Framework\TestCase; use Phpactor\MapResolver\Definition; use Phpactor\MapResolver\InvalidMap; +use Phpactor\MapResolver\UnknownKeys; use Phpactor\MapResolver\Resolver; use stdClass; @@ -25,12 +26,18 @@ public function testThrowsExceptionOnUnknownKey(): void $this->expectException(InvalidMap::class); $this->expectExceptionMessage('Key(s) "three" are not known'); - $resolver = new Resolver(); - $resolver->setDefaults([ - 'one' => 1, - 'two' => 2, - ]); - $resolver->resolve(['three' => 3]); + try { + $resolver = new Resolver(); + $resolver->setDefaults([ + 'one' => 1, + 'two' => 2, + ]); + $resolver->resolve(['three' => 3]); + } catch (UnknownKeys $e) { + self::assertEquals(['three'], $e->additionalKeys()); + self::assertEquals(['one', 'two'], $e->allowedKeys()); + throw $e; + } } public function testIgnoresUnknownKey(): void