@@ 8-58 (lines=51) @@ | ||
5 | use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; |
|
6 | use Coduo\ToString\StringConverter; |
|
7 | ||
8 | final class GreaterThan implements PatternExpander |
|
9 | { |
|
10 | /** |
|
11 | * @var |
|
12 | */ |
|
13 | private $boundary; |
|
14 | ||
15 | /** |
|
16 | * @var null|string |
|
17 | */ |
|
18 | private $error; |
|
19 | ||
20 | /** |
|
21 | * @param $boundary |
|
22 | */ |
|
23 | public function __construct($boundary) |
|
24 | { |
|
25 | if (!is_float($boundary) && !is_int($boundary)) { |
|
26 | throw new \InvalidArgumentException(sprintf("Boundary value \"%s\" is not a valid number.", new StringConverter($boundary))); |
|
27 | } |
|
28 | ||
29 | $this->boundary = $boundary; |
|
30 | } |
|
31 | ||
32 | /** |
|
33 | * @param $value |
|
34 | * @return boolean |
|
35 | */ |
|
36 | public function match($value) |
|
37 | { |
|
38 | if (!is_float($value) && !is_int($value) && !is_numeric($value)) { |
|
39 | $this->error = sprintf("Value \"%s\" is not a valid number.", new StringConverter($value)); |
|
40 | return false; |
|
41 | } |
|
42 | ||
43 | if ($value <= $this->boundary) { |
|
44 | $this->error = sprintf("Value \"%s\" is not greater than \"%s\".", new StringConverter($value), new StringConverter($this->boundary)); |
|
45 | return false; |
|
46 | } |
|
47 | ||
48 | return $value > $this->boundary; |
|
49 | } |
|
50 | ||
51 | /** |
|
52 | * @return string|null |
|
53 | */ |
|
54 | public function getError() |
|
55 | { |
|
56 | return $this->error; |
|
57 | } |
|
58 | } |
|
59 |
@@ 8-58 (lines=51) @@ | ||
5 | use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; |
|
6 | use Coduo\ToString\StringConverter; |
|
7 | ||
8 | final class LowerThan implements PatternExpander |
|
9 | { |
|
10 | /** |
|
11 | * @var |
|
12 | */ |
|
13 | private $boundary; |
|
14 | ||
15 | /** |
|
16 | * @var null|string |
|
17 | */ |
|
18 | private $error; |
|
19 | ||
20 | /** |
|
21 | * @param $boundary |
|
22 | */ |
|
23 | public function __construct($boundary) |
|
24 | { |
|
25 | if (!is_float($boundary) && !is_integer($boundary) && !is_double($boundary)) { |
|
26 | throw new \InvalidArgumentException(sprintf("Boundary value \"%s\" is not a valid number.", new StringConverter($boundary))); |
|
27 | } |
|
28 | ||
29 | $this->boundary = $boundary; |
|
30 | } |
|
31 | ||
32 | /** |
|
33 | * @param $value |
|
34 | * @return boolean |
|
35 | */ |
|
36 | public function match($value) |
|
37 | { |
|
38 | if (!is_float($value) && !is_integer($value) && !is_double($value)) { |
|
39 | $this->error = sprintf("Value \"%s\" is not a valid number.", new StringConverter($value)); |
|
40 | return false; |
|
41 | } |
|
42 | ||
43 | if ($value >= $this->boundary) { |
|
44 | $this->error = sprintf("Value \"%s\" is not lower than \"%s\".", new StringConverter($value), new StringConverter($this->boundary)); |
|
45 | return false; |
|
46 | } |
|
47 | ||
48 | return $value < $this->boundary; |
|
49 | } |
|
50 | ||
51 | /** |
|
52 | * @return string|null |
|
53 | */ |
|
54 | public function getError() |
|
55 | { |
|
56 | return $this->error; |
|
57 | } |
|
58 | } |
|
59 |