This commit is contained in:
Antonio Spinelli
2014-04-16 17:59:03 -03:00
parent da35c96b90
commit fc3b6a1608
25 changed files with 65 additions and 64 deletions

View File

@@ -8,18 +8,18 @@ abstract class AbstractSpecification implements SpecificationInterface
{
/**
* Checks if given item meets all criteria
*
*
* @param Item $item
*
*
* @return bool
*/
abstract public function isSatisfiedBy(Item $item);
/**
* Creates a new logical AND specification
*
*
* @param SpecificationInterface $spec
*
*
* @return SpecificationInterface
*/
public function plus(SpecificationInterface $spec)
@@ -29,9 +29,9 @@ abstract class AbstractSpecification implements SpecificationInterface
/**
* Creates a new logical OR composite specification
*
*
* @param SpecificationInterface $spec
*
*
* @return SpecificationInterface
*/
public function either(SpecificationInterface $spec)
@@ -41,11 +41,11 @@ abstract class AbstractSpecification implements SpecificationInterface
/**
* Creates a new logical NOT specification
*
*
* @return SpecificationInterface
*/
public function not()
{
return new Not($this);
}
}
}

View File

@@ -31,4 +31,4 @@ class Not extends AbstractSpecification
{
return !$this->spec->isSatisfiedBy($item);
}
}
}

View File

@@ -12,10 +12,9 @@ class Plus extends AbstractSpecification
/**
* Creation of a locical AND of two specifications
*
*
* @param SpecificationInterface $left
* @param SpecificationInterface $right
*/
public function __construct(SpecificationInterface $left, SpecificationInterface $right)
{
@@ -25,13 +24,13 @@ class Plus extends AbstractSpecification
/**
* Checks if the composite AND of specifications passes
*
*
* @param Item $item
*
*
* @return bool
*/
public function isSatisfiedBy(Item $item)
{
return $this->left->isSatisfiedBy($item) && $this->right->isSatisfiedBy($item);
}
}
}

View File

@@ -31,17 +31,17 @@ class PriceSpecification extends AbstractSpecification
/**
* Checks if Item price falls between bounds
*
*
* @param Item $item
*
*
* @return bool
*/
public function isSatisfiedBy(Item $item)
{
if ( !empty($this->maxPrice) && $item->getPrice() > $this->maxPrice) {
if (!empty($this->maxPrice) && $item->getPrice() > $this->maxPrice) {
return false;
}
if ( !empty($this->minPrice) && $item->getPrice() < $this->minPrice) {
if (!empty($this->minPrice) && $item->getPrice() < $this->minPrice) {
return false;
}

View File

@@ -8,26 +8,24 @@ interface SpecificationInterface
{
/**
* A boolean evaluation indicating if the object meets the specification
*
*
* @param Item $item
*
*
* @return bool
*/
public function isSatisfiedBy(Item $item);
/**
* Creates a logical AND specification
*
*
* @param SpecificationInterface $spec
*/
public function plus(SpecificationInterface $spec);
/**
* Creates a logical OR specification
*
*
* @param SpecificationInterface $spec
*/
public function either(SpecificationInterface $spec);
@@ -35,4 +33,4 @@ interface SpecificationInterface
* Creates a logical not specification
*/
public function not();
}
}