| @@ 7-31 (lines=25) @@ | ||
| 4 | ||
| 5 | use Coduo\ToString\StringConverter; |
|
| 6 | ||
| 7 | final class BooleanMatcher extends Matcher |
|
| 8 | { |
|
| 9 | const BOOLEAN_PATTERN = '/^@boolean@$/'; |
|
| 10 | ||
| 11 | /** |
|
| 12 | * {@inheritDoc} |
|
| 13 | */ |
|
| 14 | public function match($value, $pattern) |
|
| 15 | { |
|
| 16 | if (!is_bool($value)) { |
|
| 17 | $this->error = sprintf("%s \"%s\" is not a valid boolean.", gettype($value), new StringConverter($value)); |
|
| 18 | return false; |
|
| 19 | } |
|
| 20 | ||
| 21 | return true; |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * {@inheritDoc} |
|
| 26 | */ |
|
| 27 | public function canMatch($pattern) |
|
| 28 | { |
|
| 29 | return is_string($pattern) && 0 !== preg_match(self::BOOLEAN_PATTERN, $pattern); |
|
| 30 | } |
|
| 31 | } |
|
| 32 | ||
| @@ 7-31 (lines=25) @@ | ||
| 4 | ||
| 5 | use Coduo\ToString\StringConverter; |
|
| 6 | ||
| 7 | final class NumberMatcher extends Matcher |
|
| 8 | { |
|
| 9 | const NUMBER_PATTERN = '/^@number@$/'; |
|
| 10 | ||
| 11 | /** |
|
| 12 | * {@inheritDoc} |
|
| 13 | */ |
|
| 14 | public function match($value, $pattern) |
|
| 15 | { |
|
| 16 | if (!is_numeric($value)) { |
|
| 17 | $this->error = sprintf("%s \"%s\" is not a valid number.", gettype($value), new StringConverter($value)); |
|
| 18 | return false; |
|
| 19 | } |
|
| 20 | ||
| 21 | return true; |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * {@inheritDoc} |
|
| 26 | */ |
|
| 27 | public function canMatch($pattern) |
|
| 28 | { |
|
| 29 | return is_string($pattern) && 0 !== preg_match(self::NUMBER_PATTERN, $pattern); |
|
| 30 | } |
|
| 31 | } |
|
| 32 | ||
| @@ 7-31 (lines=25) @@ | ||
| 4 | ||
| 5 | use Coduo\ToString\StringConverter; |
|
| 6 | ||
| 7 | final class NullMatcher extends Matcher |
|
| 8 | { |
|
| 9 | const MATCH_PATTERN = "/^@null@$/"; |
|
| 10 | ||
| 11 | /** |
|
| 12 | * {@inheritDoc} |
|
| 13 | */ |
|
| 14 | public function match($value, $pattern) |
|
| 15 | { |
|
| 16 | if (null !== $value) { |
|
| 17 | $this->error = sprintf("%s \"%s\" does not match null.", gettype($value), new StringConverter($value)); |
|
| 18 | return false; |
|
| 19 | } |
|
| 20 | ||
| 21 | return true; |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * {@inheritDoc} |
|
| 26 | */ |
|
| 27 | public function canMatch($pattern) |
|
| 28 | { |
|
| 29 | return is_null($pattern) || (is_string($pattern) && 0 !== preg_match(self::MATCH_PATTERN, $pattern)); |
|
| 30 | } |
|
| 31 | } |
|
| 32 | ||