Skip to content

Commit

Permalink
misc: remove "pure" requirements from several methods
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
romm committed Nov 17, 2024
1 parent 12033fc commit b15d1a5
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 25 deletions.
2 changes: 0 additions & 2 deletions src/Mapper/ArgumentsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
interface ArgumentsMapper
{
/**
* @pure
*
* @return array<string, mixed>
*
* @throws MappingError
Expand Down
5 changes: 0 additions & 5 deletions src/Mapper/Tree/Message/MessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -119,8 +116,6 @@ public function parameters(): array
}

/**
* @psalm-pure
*
* @return MessageType&HasCode&HasParameters
*/
public function build(): Message&HasCode&HasParameters
Expand Down
2 changes: 0 additions & 2 deletions src/Mapper/TreeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
interface TreeMapper
{
/**
* @pure
*
* @template T of object
*
* @param string|class-string<T> $signature
Expand Down
1 change: 0 additions & 1 deletion src/Mapper/TypeArgumentsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function __construct(
private Settings $settings,
) {}

/** @pure */
public function mapArguments(callable $callable, mixed $source): array
{
$function = $this->functionDefinitionRepository->for($callable);
Expand Down
1 change: 0 additions & 1 deletion src/Mapper/TypeTreeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function __construct(
private Settings $settings,
) {}

/** @pure */
public function map(string $signature, mixed $source): mixed
{
$node = $this->node($signature, $source);
Expand Down
14 changes: 0 additions & 14 deletions src/MapperBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand Down Expand Up @@ -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
* {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
* {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b15d1a5

Please sign in to comment.