From 0c91ec8eddb22fdae8dcd3ad7408edee8632a48a Mon Sep 17 00:00:00 2001 From: Yuta Nagamiya Date: Mon, 1 Aug 2022 03:10:21 +0900 Subject: [PATCH] Add static factory methods for true and false specifications --- src/AbstractSpecification.php | 16 ++++++++++++++++ src/SpecificationInterface.php | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/AbstractSpecification.php b/src/AbstractSpecification.php index 87ec504..3b31d5a 100644 --- a/src/AbstractSpecification.php +++ b/src/AbstractSpecification.php @@ -24,6 +24,22 @@ abstract class AbstractSpecification implements SpecificationInterface */ abstract public function isSatisfiedBy($candidate): bool; + /** + * {@inheritdoc} + */ + public static function true(): SpecificationInterface + { + return TrueSpecification::getInstance(); + } + + /** + * {@inheritdoc} + */ + public static function false(): SpecificationInterface + { + return FalseSpecification::getInstance(); + } + /** * {@inheritdoc} */ diff --git a/src/SpecificationInterface.php b/src/SpecificationInterface.php index 2e171b4..d950c45 100644 --- a/src/SpecificationInterface.php +++ b/src/SpecificationInterface.php @@ -26,6 +26,20 @@ interface SpecificationInterface */ public function isSatisfiedBy($candidate): bool; + /** + * Create a new specification that is always true. + * + * @return SpecificationInterface a new specification + */ + public static function true(): SpecificationInterface; + + /** + * Create a new specification that is always false. + * + * @return SpecificationInterface a new specification + */ + public static function false(): SpecificationInterface; + /** * Create a new specification that is the AND operation of this specification and another specification. *