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