| @@ 8-53 (lines=46) @@ | ||
| 5 | use Coduo\PHPMatcher\Parser; |
|
| 6 | use Coduo\ToString\StringConverter; |
|
| 7 | ||
| 8 | final class DoubleMatcher extends Matcher |
|
| 9 | { |
|
| 10 | /** |
|
| 11 | * @var Parser |
|
| 12 | */ |
|
| 13 | private $parser; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @param Parser $parser |
|
| 17 | */ |
|
| 18 | public function __construct(Parser $parser) |
|
| 19 | { |
|
| 20 | $this->parser = $parser; |
|
| 21 | } |
|
| 22 | ||
| 23 | /** |
|
| 24 | * {@inheritDoc} |
|
| 25 | */ |
|
| 26 | public function match($value, $pattern) |
|
| 27 | { |
|
| 28 | if (!is_double($value)) { |
|
| 29 | $this->error = sprintf("%s \"%s\" is not a valid double.", gettype($value), new StringConverter($value)); |
|
| 30 | return false; |
|
| 31 | } |
|
| 32 | ||
| 33 | $typePattern = $this->parser->parse($pattern); |
|
| 34 | if (!$typePattern->matchExpanders($value)) { |
|
| 35 | $this->error = $typePattern->getError(); |
|
| 36 | return false; |
|
| 37 | } |
|
| 38 | ||
| 39 | return true; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * {@inheritDoc} |
|
| 44 | */ |
|
| 45 | public function canMatch($pattern) |
|
| 46 | { |
|
| 47 | if (!is_string($pattern)) { |
|
| 48 | return false; |
|
| 49 | } |
|
| 50 | ||
| 51 | return $this->parser->hasValidSyntax($pattern) && $this->parser->parse($pattern)->is('double'); |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| @@ 8-53 (lines=46) @@ | ||
| 5 | use Coduo\PHPMatcher\Parser; |
|
| 6 | use Coduo\ToString\StringConverter; |
|
| 7 | ||
| 8 | final class IntegerMatcher extends Matcher |
|
| 9 | { |
|
| 10 | /** |
|
| 11 | * @var Parser |
|
| 12 | */ |
|
| 13 | private $parser; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @param Parser $parser |
|
| 17 | */ |
|
| 18 | public function __construct(Parser $parser) |
|
| 19 | { |
|
| 20 | $this->parser = $parser; |
|
| 21 | } |
|
| 22 | ||
| 23 | /** |
|
| 24 | * {@inheritDoc} |
|
| 25 | */ |
|
| 26 | public function match($value, $pattern) |
|
| 27 | { |
|
| 28 | if (!is_integer($value)) { |
|
| 29 | $this->error = sprintf("%s \"%s\" is not a valid integer.", gettype($value), new StringConverter($value)); |
|
| 30 | return false; |
|
| 31 | } |
|
| 32 | ||
| 33 | $typePattern = $this->parser->parse($pattern); |
|
| 34 | if (!$typePattern->matchExpanders($value)) { |
|
| 35 | $this->error = $typePattern->getError(); |
|
| 36 | return false; |
|
| 37 | } |
|
| 38 | ||
| 39 | return true; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * {@inheritDoc} |
|
| 44 | */ |
|
| 45 | public function canMatch($pattern) |
|
| 46 | { |
|
| 47 | if (!is_string($pattern)) { |
|
| 48 | return false; |
|
| 49 | } |
|
| 50 | ||
| 51 | return $this->parser->hasValidSyntax($pattern) && $this->parser->parse($pattern)->is('integer'); |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| @@ 8-53 (lines=46) @@ | ||
| 5 | use Coduo\PHPMatcher\Parser; |
|
| 6 | use Coduo\ToString\StringConverter; |
|
| 7 | ||
| 8 | final class StringMatcher extends Matcher |
|
| 9 | { |
|
| 10 | /** |
|
| 11 | * @var Parser |
|
| 12 | */ |
|
| 13 | private $parser; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @param Parser $parser |
|
| 17 | */ |
|
| 18 | public function __construct(Parser $parser) |
|
| 19 | { |
|
| 20 | $this->parser = $parser; |
|
| 21 | } |
|
| 22 | ||
| 23 | /** |
|
| 24 | * {@inheritDoc} |
|
| 25 | */ |
|
| 26 | public function match($value, $pattern) |
|
| 27 | { |
|
| 28 | if (!is_string($value)) { |
|
| 29 | $this->error = sprintf("%s \"%s\" is not a valid string.", gettype($value), new StringConverter($value)); |
|
| 30 | return false; |
|
| 31 | } |
|
| 32 | ||
| 33 | $typePattern = $this->parser->parse($pattern); |
|
| 34 | if (!$typePattern->matchExpanders($value)) { |
|
| 35 | $this->error = $typePattern->getError(); |
|
| 36 | return false; |
|
| 37 | } |
|
| 38 | ||
| 39 | return true; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * {@inheritDoc} |
|
| 44 | */ |
|
| 45 | public function canMatch($pattern) |
|
| 46 | { |
|
| 47 | if (!is_string($pattern)) { |
|
| 48 | return false; |
|
| 49 | } |
|
| 50 | ||
| 51 | return $this->parser->hasValidSyntax($pattern) && $this->parser->parse($pattern)->is('string'); |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||