Skip to content

Commit

Permalink
Add static factory methods for true and false specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ngmy committed Jul 31, 2022
1 parent aff1530 commit 0c91ec8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/AbstractSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
14 changes: 14 additions & 0 deletions src/SpecificationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ interface SpecificationInterface
*/
public function isSatisfiedBy($candidate): bool;

/**
* Create a new specification that is always true.
*
* @return SpecificationInterface<T> a new specification
*/
public static function true(): SpecificationInterface;

/**
* Create a new specification that is always false.
*
* @return SpecificationInterface<T> a new specification
*/
public static function false(): SpecificationInterface;

/**
* Create a new specification that is the AND operation of this specification and another specification.
*
Expand Down

0 comments on commit 0c91ec8

Please sign in to comment.