mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-28 10:40:17 +02:00
29 lines
671 B
PHP
29 lines
671 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Behavioral\Specification;
|
|
|
|
class PriceSpecification implements Specification
|
|
{
|
|
private ?float $maxPrice;
|
|
private ?float $minPrice;
|
|
|
|
public function __construct(?float $minPrice, ?float $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;
|
|
}
|
|
}
|