Menu

Error Identifier: pureMethod.redundantUnlessCallable

← Back to pureMethod.*

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

class Mapper
{

	/**
	 * @param pure-callable(int): int $f
	 * @param array<int> $arr
	 * @return array<int>
	 * @pure-unless-callable-is-impure $f
	 */
	public function map(callable $f, array $arr): array
	{
		$result = [];
		foreach ($arr as $i => $v) {
			$result[$i] = $f($v);
		}

		return $result;
	}

}

Why is it reported? #

The @pure-unless-callable-is-impure tag marks a method as pure except when the named callable parameter is impure — its purity depends on the callable passed in at each call site.

Here the parameter $f is typed as pure-callable, which guarantees it is always pure. Because the only condition that could make the method impure can never happen, the tag has no effect: the method is unconditionally pure. Marking it @pure-unless-callable-is-impure is misleading and hides the fact that the method can simply be declared @phpstan-pure.

How to fix it #

Replace @pure-unless-callable-is-impure with @phpstan-pure:

 	/**
 	 * @param pure-callable(int): int $f
 	 * @param array<int> $arr
 	 * @return array<int>
-	 * @pure-unless-callable-is-impure $f
+	 * @phpstan-pure
 	 */
 	public function map(callable $f, array $arr): array

If the method is actually meant to accept impure callables, widen the parameter type from pure-callable to callable so that the @pure-unless-callable-is-impure tag becomes meaningful again:

 	/**
-	 * @param pure-callable(int): int $f
+	 * @param callable(int): int $f
 	 * @param array<int> $arr
 	 * @return array<int>
 	 * @pure-unless-callable-is-impure $f
 	 */
 	public function map(callable $f, array $arr): array

How to ignore this error #

You can use the identifier pureMethod.redundantUnlessCallable to ignore this error using a comment:

// @phpstan-ignore pureMethod.redundantUnlessCallable
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: pureMethod.redundantUnlessCallable

Rules that report this error #

  • PHPStan\Rules\Pure\PureFunctionRule [1]
  • PHPStan\Rules\Pure\PureMethodRule [1]
Theme
A
© 2026 PHPStan s.r.o.