From 5a4d0b91fb8c30759c492f9b4cdaf249c2dc244d Mon Sep 17 00:00:00 2001 From: Brooke Bryan Date: Wed, 11 Dec 2019 22:16:04 +0000 Subject: [PATCH] Add static constructor --- src/FuncCondition.php | 5 +++++ tests/FuncConditionTest.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/FuncCondition.php b/src/FuncCondition.php index 64387a5..d857f94 100644 --- a/src/FuncCondition.php +++ b/src/FuncCondition.php @@ -13,6 +13,11 @@ public function __construct(callable $func) $this->_func = $func; } + public static function i(callable $func) + { + return new static($func); + } + public function match(Context $context): bool { return ($this->_func)($context); diff --git a/tests/FuncConditionTest.php b/tests/FuncConditionTest.php index 6731533..429ca91 100644 --- a/tests/FuncConditionTest.php +++ b/tests/FuncConditionTest.php @@ -30,6 +30,6 @@ public function testInstance() { $c = $this->_makeContext(); self::assertTrue((new FuncCondition(function (Context $ctx) { return $ctx->meta()->has('a'); }))->match($c)); - self::assertFalse((new FuncCondition(function (Context $ctx) { return $ctx->meta()->has('b'); }))->match($c)); + self::assertFalse((FuncCondition::i(function (Context $ctx) { return $ctx->meta()->has('b'); }))->match($c)); } }