Files
DesignPatternsPHP/Behavioral/Specification/PriceSpecification.php
2019-08-19 18:11:49 +02:00

40 lines
798 B
PHP

<?php declare(strict_types=1);
namespace DesignPatterns\Behavioral\Specification;
class PriceSpecification implements Specification
{
/**
* @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;
}
}