mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-06-04 04:55:41 +02:00
40 lines
782 B
PHP
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;
|
|
}
|
|
}
|