DesignPatternsPHP/Behavioral/Specification/PriceSpecification.php
2016-09-22 12:54:03 +02:00

40 lines
782 B
PHP

<?php
namespace DesignPatterns\Behavioral\Specification;
class PriceSpecification implements SpecificationInterface
{
/**
* @var float|null
*/
private $maxPrice;
/**
* @var float|null
*/
private $minPrice;
/**
* @param float $minPrice
* @param float $maxPrice
*/
public function __construct($minPrice, $maxPrice)
{
$this->minPrice = $minPrice;
$this->maxPrice = $maxPrice;
}
public function isSatisfiedBy(Item $item): bool
{
if ($this->maxPrice !== null && $item->getPrice() > $this->maxPrice) {
return false;
}
if ($this->minPrice !== null && $item->getPrice() < $this->minPrice) {
return false;
}
return true;
}
}