From 978a49091f7e1b1bc9e6f5adff4cb0dff9657fe9 Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Tue, 27 Oct 2026 22:59:06 +0100 Subject: [PATCH] fix negated predicate decorated callable --- phpstan-baseline.neon | 6 ---- src/Predicate/NegatedPredicate.php | 2 +- tests/Collections/LibraryCallablesTest.php | 40 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 tests/Collections/LibraryCallablesTest.php diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 9a0bb93..b6c9f81 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -108,12 +108,6 @@ parameters: count: 2 path: src/Predicate/ConstantPredicate.php - - - message: '#^Expression "\$this\-\>negated" on a separate line does not do anything\.$#' - identifier: expr.resultUnused - count: 1 - path: src/Predicate/NegatedPredicate.php - - message: '#^Method Kadet\\Functional\\Predicate\\NegatedPredicate\:\:__invoke\(\) has parameter \$args with no type specified\.$#' identifier: missingType.parameter diff --git a/src/Predicate/NegatedPredicate.php b/src/Predicate/NegatedPredicate.php index 9bde7f4..82cba24 100644 --- a/src/Predicate/NegatedPredicate.php +++ b/src/Predicate/NegatedPredicate.php @@ -39,6 +39,6 @@ class NegatedPredicate extends AbstractPredicate implements Decorator public function getDecorated() { - $this->negated; + return $this->negated; } } \ No newline at end of file diff --git a/tests/Collections/LibraryCallablesTest.php b/tests/Collections/LibraryCallablesTest.php new file mode 100644 index 0000000..72d1c2f --- /dev/null +++ b/tests/Collections/LibraryCallablesTest.php @@ -0,0 +1,40 @@ + + * + * Full license available in separate LICENSE file + */ + +use Kadet\Functional as f; +use Kadet\Functional\Collections as c; +use Kadet\Functional\Predicates as p; + +/** + * The library's own callables (predicates, pipes, decorators) used as collection callbacks. + */ +class LibraryCallablesTest extends \PHPUnit\Framework\TestCase +{ + // negated predicates + + public function testFilterWithNegatedInternalFunction() + { + $this->assertSame([1 => 'x'], c\filter(f\not(is_numeric(...)))(['1', 'x'])); + } + + public function testFilterWithNegatedClosure() + { + $this->assertSame([1], c\filter(f\not(fn ($x) => $x > 1))([1, 2])); + } + + public function testFilterWithNegatedPredicateMethod() + { + $this->assertSame([1], c\filter(p\gt(1)->not())([1, 2])); + } + + public function testRejectWithNegatedPredicate() + { + $this->assertSame([1 => 2], c\reject(p\gt(1)->not())([1, 2])); + } +}