From dbedc7a9365ceaa5d048d96b01e28d0a3c06e4f6 Mon Sep 17 00:00:00 2001 From: Romain Canon Date: Sun, 17 Nov 2024 18:51:14 +0100 Subject: [PATCH] misc: remove "pure" requirements from several methods Due to the current overhead required to make PHPStan and Psalm work with the pure feature, these requirements have been removed. Since PHPStan and Psalm are unfortunately unable to automatically detect whether callable values provided to `MapperBuilder` are pure, users are forced to manually add `@pure` annotations. This decision aims to strike a fair balance between the library's strictness and user experience. --- src/Mapper/ArgumentsMapper.php | 2 -- src/Mapper/Tree/Message/MessageBuilder.php | 5 ----- src/Mapper/TreeMapper.php | 2 -- src/Mapper/TypeArgumentsMapper.php | 1 - src/Mapper/TypeTreeMapper.php | 1 - src/MapperBuilder.php | 14 -------------- 6 files changed, 25 deletions(-) diff --git a/src/Mapper/ArgumentsMapper.php b/src/Mapper/ArgumentsMapper.php index e12011bb..8e1bde6f 100644 --- a/src/Mapper/ArgumentsMapper.php +++ b/src/Mapper/ArgumentsMapper.php @@ -8,8 +8,6 @@ interface ArgumentsMapper { /** - * @pure - * * @return array * * @throws MappingError diff --git a/src/Mapper/Tree/Message/MessageBuilder.php b/src/Mapper/Tree/Message/MessageBuilder.php index 943e1ed2..7a04810e 100644 --- a/src/Mapper/Tree/Message/MessageBuilder.php +++ b/src/Mapper/Tree/Message/MessageBuilder.php @@ -53,9 +53,6 @@ public static function newError(string $body): self return $instance; } - /** - * @psalm-pure - */ public static function from(Throwable $error): ErrorMessage { if ($error instanceof ErrorMessage) { @@ -119,8 +116,6 @@ public function parameters(): array } /** - * @psalm-pure - * * @return MessageType&HasCode&HasParameters */ public function build(): Message&HasCode&HasParameters diff --git a/src/Mapper/TreeMapper.php b/src/Mapper/TreeMapper.php index 8da44254..503de2d4 100644 --- a/src/Mapper/TreeMapper.php +++ b/src/Mapper/TreeMapper.php @@ -8,8 +8,6 @@ interface TreeMapper { /** - * @pure - * * @template T of object * * @param string|class-string $signature diff --git a/src/Mapper/TypeArgumentsMapper.php b/src/Mapper/TypeArgumentsMapper.php index 465ec624..d5b47646 100644 --- a/src/Mapper/TypeArgumentsMapper.php +++ b/src/Mapper/TypeArgumentsMapper.php @@ -24,7 +24,6 @@ public function __construct( private Settings $settings, ) {} - /** @pure */ public function mapArguments(callable $callable, mixed $source): array { $function = $this->functionDefinitionRepository->for($callable); diff --git a/src/Mapper/TypeTreeMapper.php b/src/Mapper/TypeTreeMapper.php index 6c0734ca..eb997694 100644 --- a/src/Mapper/TypeTreeMapper.php +++ b/src/Mapper/TypeTreeMapper.php @@ -23,7 +23,6 @@ public function __construct( private Settings $settings, ) {} - /** @pure */ public function map(string $signature, mixed $source): mixed { $node = $this->node($signature, $source); diff --git a/src/MapperBuilder.php b/src/MapperBuilder.php index 48ffecc2..ab89726d 100644 --- a/src/MapperBuilder.php +++ b/src/MapperBuilder.php @@ -36,9 +36,6 @@ public function __construct() * using the given source. These arguments can then be used to decide which * implementation should be used. * - * The callback *must* be pure, its output must be deterministic. - * @see https://en.wikipedia.org/wiki/Pure_function - * * Example: * * ```php @@ -57,7 +54,6 @@ public function __construct() * ``` * * @param interface-string|class-string $name - * @psalm-param pure-callable $callback */ public function infer(string $name, callable $callback): self { @@ -86,9 +82,6 @@ public function infer(string $name, callable $callback): self * needs to be handled as well, the name of the class must be given to this * method. * - * A constructor *must* be pure, its output must be deterministic. - * @see https://en.wikipedia.org/wiki/Pure_function - * * ```php * final class SomeClass * { @@ -200,7 +193,6 @@ public function infer(string $name, callable $callback): self * ]); * ``` * - * @psalm-param pure-callable|class-string ...$constructors * @param callable|class-string ...$constructors */ public function registerConstructor(callable|string ...$constructors): self @@ -298,7 +290,6 @@ public function withCache(CacheInterface $cache): self /** * @template T - * @psalm-param pure-callable(T): T $callback * @param callable(T): T $callback */ public function alter(callable $callback): self @@ -418,9 +409,6 @@ public function allowPermissiveTypes(): self * part of a query should never be allowed. Therefore, only an exhaustive * list of carefully chosen exceptions should be filtered. * - * The filter callback *must* be pure, its output must be deterministic. - * @see https://en.wikipedia.org/wiki/Pure_function - * * ```php * final class SomeClass * { @@ -446,7 +434,6 @@ public function allowPermissiveTypes(): self * ]); * ``` * - * @psalm-param pure-callable(Throwable): ErrorMessage $filter * @param callable(Throwable): ErrorMessage $filter */ public function filterExceptions(callable $filter): self @@ -514,7 +501,6 @@ public function filterExceptions(callable $filter): self * ->normalize('Hello world'); // HELLO WORLD?! * ``` * - * @psalm-param pure-callable|class-string $transformer * @param callable|class-string $transformer */ public function registerTransformer(callable|string $transformer, int $priority = 0): self