forked from DesignPatternsPHP/DesignPatternsPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPriceSpecification.php
More file actions
39 lines (32 loc) · 782 Bytes
/
PriceSpecification.php
File metadata and controls
39 lines (32 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?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;
}
}