diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..929a87c0 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,38 @@ +# 2.0 + +* Added support for PHP7 +* Updated dependencies to support Symfony3 components +* Added ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\MatchRegexTest`` expander - benjamin.lazarecki@gmail.com +* Added ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\IsEmpty`` expander - benjamin.lazarecki@gmail.com +* Added PHPMatcher facade in order to improve developers experience + + +# 1.1 + +* Added pattern expanders mechanism with following expanders: + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\Contains`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\EndsWith`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\GreaterThan`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\InArray`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\IsDateTime`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\IsEmail`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\IsUrl`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\LowerThan`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\MatchRegex`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\OneOf`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\StartsWith`` + +# 1.0 + +* PHPMatcher initial release with following matchers: + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\ArrayMatcher`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\CallbackMatcher`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\CaptureMatcher`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\ChainMatcher`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\ExpressionMatcher`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\JsonMatcher`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\NullMatcher`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\ScalarMatcher`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\TypeMatcher`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\WildcardMatcher`` + * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\XmlMatcher`` \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..81a948a1 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,39 @@ +#A quick guide to contribute to the project: + +##Installing the dev environment + +1. Fork the repo +2. Clone the repo to local +3. Install dependencies: `composer update` (this assumes you have 'composer' aliased to whereever your composer.phar lives) +4. Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate: + `./bin/phpunit` + +##Coding Standards + +Try use similar coding standards to what you see in the project to keep things clear to the contributors. If you're unsure, it's always a safe bet to fall-back to the PSR standards. + +[PSR-1: Basic Coding Standard](http://www.php-fig.org/psr/psr-1/) + +[PSR-2: Coding Style Guide](http://www.php-fig.org/psr/psr-2/) + +##Adding new features + +Pull requests with new features needs to be created against master branch. + +If new feature require BC Breake please note that in your PR comment, it will added in next major version. +New features that does not have any BC Breakes are going to be added in next minor version. + +##Patches and bugfixes + +1. Check the oldest version that patch/bug fix can be applied. +2. Create PR against that version + +For example if you are fixing pattern expander that was introduced in version 1.1 make sure that PR with fix +is created against version 1.1, not master or 2.0 + +##The actual contribution + +1. Make the changes/additions to the code, committing often and making clear what you've done +2. Make sure you write tests for your code, located in the folder structure `tests/Coduo/PHPMatcher/...` +3. Run your tests (often and while coding): `./bin/phpunit` +4. Create Pull Request on github to against proper branch diff --git a/LICENCE b/LICENCE index 6773c8cf..dc6193b2 100644 --- a/LICENCE +++ b/LICENCE @@ -1,4 +1,4 @@ -Copyright (c) 2014 Michal Dabrowski, Norbert Orzechowicz +Copyright (c) 2014-2016 Michal Dabrowski, Norbert Orzechowicz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/README.md b/README.md index 50fc1214..314b0e01 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,8 @@ $match = $matcher->match("lorem ipsum dolor", "@string@") * ``isDateTime()`` * ``isEmail()`` * ``isUrl()`` -* ``notEmpty()`` * ``isEmpty()`` +* ``isNotEmpty()`` * ``lowerThan($boundry)`` * ``greaterThan($boundry)`` * ``inArray($value)`` diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 00000000..63941b71 --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,12 @@ +# Upgrade from 1.1 to 2.0 + +* All classes are now marked as final in order to close extra extension points +* ``Coduo\PHPMatcher\Matcher\CaptureMatcher`` was removed +* ``Coduo\PHPMatcher\Matcher\TypeMatcher`` was removed +* ``Coduo\PHPMatcher\Matcher\PropertyMatcher`` interface was remved +* Removed ``match`` function, use PHPMatcher facade instead +* Renamed ``@pattern@.notEmpty()`` expander into ``@pattern@.isNotEmpty()`` + +# Upgrade from 1.0 to 1.1 + +*No known BC Breakes* \ No newline at end of file diff --git a/composer.json b/composer.json index eccfed81..c4fcbffa 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "coduo/php-matcher", "type": "library", - "keywords": ["json", "matcher", "tests"], + "keywords": ["json", "matcher", "tests", "match"], "license": "MIT", "authors": [ { diff --git a/src/Coduo/PHPMatcher/AST/Expander.php b/src/Coduo/PHPMatcher/AST/Expander.php index 2f364bc9..26676553 100644 --- a/src/Coduo/PHPMatcher/AST/Expander.php +++ b/src/Coduo/PHPMatcher/AST/Expander.php @@ -2,7 +2,7 @@ namespace Coduo\PHPMatcher\AST; -class Expander implements Node +final class Expander implements Node { /** * @var diff --git a/src/Coduo/PHPMatcher/AST/Pattern.php b/src/Coduo/PHPMatcher/AST/Pattern.php index 9d804f85..07278678 100644 --- a/src/Coduo/PHPMatcher/AST/Pattern.php +++ b/src/Coduo/PHPMatcher/AST/Pattern.php @@ -2,7 +2,7 @@ namespace Coduo\PHPMatcher\AST; -class Pattern implements Node +final class Pattern implements Node { /** * @var Type diff --git a/src/Coduo/PHPMatcher/AST/Type.php b/src/Coduo/PHPMatcher/AST/Type.php index 1f85be5d..bfb44c6e 100644 --- a/src/Coduo/PHPMatcher/AST/Type.php +++ b/src/Coduo/PHPMatcher/AST/Type.php @@ -2,7 +2,7 @@ namespace Coduo\PHPMatcher\AST; -class Type implements Node +final class Type implements Node { /** * @var string diff --git a/src/Coduo/PHPMatcher/Lexer.php b/src/Coduo/PHPMatcher/Lexer.php index 4a16937b..333414a8 100644 --- a/src/Coduo/PHPMatcher/Lexer.php +++ b/src/Coduo/PHPMatcher/Lexer.php @@ -4,7 +4,7 @@ use Doctrine\Common\Lexer\AbstractLexer; -class Lexer extends AbstractLexer +final class Lexer extends AbstractLexer { const T_NONE = 1; const T_EXPANDER_NAME = 2; diff --git a/src/Coduo/PHPMatcher/Matcher.php b/src/Coduo/PHPMatcher/Matcher.php index 16d053f1..7c74eaa0 100644 --- a/src/Coduo/PHPMatcher/Matcher.php +++ b/src/Coduo/PHPMatcher/Matcher.php @@ -4,7 +4,7 @@ use Coduo\PHPMatcher\Matcher\ValueMatcher; -class Matcher +final class Matcher { /** * @var ValueMatcher diff --git a/src/Coduo/PHPMatcher/Matcher/ArrayMatcher.php b/src/Coduo/PHPMatcher/Matcher/ArrayMatcher.php index 73da5344..a4ecabc1 100644 --- a/src/Coduo/PHPMatcher/Matcher/ArrayMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/ArrayMatcher.php @@ -7,7 +7,7 @@ use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessor; -class ArrayMatcher extends Matcher +final class ArrayMatcher extends Matcher { const UNBOUNDED_PATTERN = '@...@'; diff --git a/src/Coduo/PHPMatcher/Matcher/BooleanMatcher.php b/src/Coduo/PHPMatcher/Matcher/BooleanMatcher.php index 52f0de0d..aaa9c2e2 100644 --- a/src/Coduo/PHPMatcher/Matcher/BooleanMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/BooleanMatcher.php @@ -4,7 +4,7 @@ use Coduo\ToString\StringConverter; -class BooleanMatcher extends Matcher +final class BooleanMatcher extends Matcher { const BOOLEAN_PATTERN = '/^@boolean@$/'; diff --git a/src/Coduo/PHPMatcher/Matcher/CallbackMatcher.php b/src/Coduo/PHPMatcher/Matcher/CallbackMatcher.php index 5d8f6403..9db48b98 100644 --- a/src/Coduo/PHPMatcher/Matcher/CallbackMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/CallbackMatcher.php @@ -2,7 +2,7 @@ namespace Coduo\PHPMatcher\Matcher; -class CallbackMatcher extends Matcher +final class CallbackMatcher extends Matcher { /** * {@inheritdoc} diff --git a/src/Coduo/PHPMatcher/Matcher/CaptureMatcher.php b/src/Coduo/PHPMatcher/Matcher/CaptureMatcher.php deleted file mode 100644 index 683b2a7c..00000000 --- a/src/Coduo/PHPMatcher/Matcher/CaptureMatcher.php +++ /dev/null @@ -1,56 +0,0 @@ -captures[$this->extractPattern($pattern)] = $value; - return true; - } - - /** - * {@inheritDoc} - */ - public function canMatch($pattern) - { - return is_string($pattern) && 0 !== preg_match(self::MATCH_PATTERN, $pattern); - } - - private function extractPattern($pattern) - { - return str_replace(":", "", $pattern); - } - - public function offsetSet($offset, $value) - { - if (is_null($offset)) { - $this->captures[] = $value; - } else { - $this->captures[$offset] = $value; - } - } - - public function offsetExists($offset) - { - return isset($this->captures[$offset]); - } - - public function offsetUnset($offset) - { - unset($this->captures[$offset]); - } - - public function offsetGet($offset) - { - return isset($this->captures[$offset]) ? $this->captures[$offset] : null; - } -} diff --git a/src/Coduo/PHPMatcher/Matcher/ChainMatcher.php b/src/Coduo/PHPMatcher/Matcher/ChainMatcher.php index 81e4f564..10365970 100644 --- a/src/Coduo/PHPMatcher/Matcher/ChainMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/ChainMatcher.php @@ -4,7 +4,7 @@ use Coduo\ToString\StringConverter; -class ChainMatcher extends Matcher +final class ChainMatcher extends Matcher { /** * @var array|ValueMatcher[] diff --git a/src/Coduo/PHPMatcher/Matcher/DoubleMatcher.php b/src/Coduo/PHPMatcher/Matcher/DoubleMatcher.php index 0b985a05..ec9b49da 100644 --- a/src/Coduo/PHPMatcher/Matcher/DoubleMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/DoubleMatcher.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Parser; use Coduo\ToString\StringConverter; -class DoubleMatcher extends Matcher +final class DoubleMatcher extends Matcher { /** * @var Parser diff --git a/src/Coduo/PHPMatcher/Matcher/ExpressionMatcher.php b/src/Coduo/PHPMatcher/Matcher/ExpressionMatcher.php index 4a63d9c0..3ea7e2b9 100644 --- a/src/Coduo/PHPMatcher/Matcher/ExpressionMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/ExpressionMatcher.php @@ -5,7 +5,7 @@ use Coduo\ToString\StringConverter; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -class ExpressionMatcher extends Matcher +final class ExpressionMatcher extends Matcher { const MATCH_PATTERN = "/^expr\((.*?)\)$/"; diff --git a/src/Coduo/PHPMatcher/Matcher/IntegerMatcher.php b/src/Coduo/PHPMatcher/Matcher/IntegerMatcher.php index b3a6b01c..66c4e790 100644 --- a/src/Coduo/PHPMatcher/Matcher/IntegerMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/IntegerMatcher.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Parser; use Coduo\ToString\StringConverter; -class IntegerMatcher extends Matcher +final class IntegerMatcher extends Matcher { /** * @var Parser diff --git a/src/Coduo/PHPMatcher/Matcher/JsonMatcher.php b/src/Coduo/PHPMatcher/Matcher/JsonMatcher.php index e033d649..aaea9428 100644 --- a/src/Coduo/PHPMatcher/Matcher/JsonMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/JsonMatcher.php @@ -4,7 +4,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\Assert\Json; -class JsonMatcher extends Matcher +final class JsonMatcher extends Matcher { /** * @var diff --git a/src/Coduo/PHPMatcher/Matcher/NullMatcher.php b/src/Coduo/PHPMatcher/Matcher/NullMatcher.php index ad78565c..f38d4c1b 100644 --- a/src/Coduo/PHPMatcher/Matcher/NullMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/NullMatcher.php @@ -4,7 +4,7 @@ use Coduo\ToString\StringConverter; -class NullMatcher extends Matcher +final class NullMatcher extends Matcher { const MATCH_PATTERN = "/^@null@$/"; diff --git a/src/Coduo/PHPMatcher/Matcher/NumberMatcher.php b/src/Coduo/PHPMatcher/Matcher/NumberMatcher.php index 7c322509..f3a93e1d 100644 --- a/src/Coduo/PHPMatcher/Matcher/NumberMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/NumberMatcher.php @@ -4,7 +4,7 @@ use Coduo\ToString\StringConverter; -class NumberMatcher extends Matcher +final class NumberMatcher extends Matcher { const NUMBER_PATTERN = '/^@number@$/'; diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Assert/Json.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Assert/Json.php index d9f6d45f..32ef6e1f 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Assert/Json.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Assert/Json.php @@ -2,7 +2,7 @@ namespace Coduo\PHPMatcher\Matcher\Pattern\Assert; -class Json +final class Json { const TRANSFORM_QUOTATION_PATTERN = '/([^"])@([a-zA-Z0-9\.]+)@([^"])/'; const TRANSFORM_QUOTATION_REPLACEMENT = '$1"@$2@"$3'; diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Assert/Xml.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Assert/Xml.php index 6ad08a91..fa91fa5e 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Assert/Xml.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Assert/Xml.php @@ -2,7 +2,7 @@ namespace Coduo\PHPMatcher\Matcher\Pattern\Assert; -class Xml +final class Xml { /** * @param $value diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/Contains.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/Contains.php index 05c1983d..2fb61173 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/Contains.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/Contains.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; use Coduo\ToString\StringConverter; -class Contains implements PatternExpander +final class Contains implements PatternExpander { /** * @var null|string diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/EndsWith.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/EndsWith.php index 1fc25a88..36a8682a 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/EndsWith.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/EndsWith.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; use Coduo\ToString\StringConverter; -class EndsWith implements PatternExpander +final class EndsWith implements PatternExpander { /** * @var diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/GreaterThan.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/GreaterThan.php index 8f7fc607..8acc4248 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/GreaterThan.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/GreaterThan.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; use Coduo\ToString\StringConverter; -class GreaterThan implements PatternExpander +final class GreaterThan implements PatternExpander { /** * @var @@ -22,7 +22,7 @@ class GreaterThan implements PatternExpander */ public function __construct($boundary) { - if (!is_float($boundary) && !is_integer($boundary) && !is_double($boundary)) { + if (!is_float($boundary) && !is_int($boundary)) { throw new \InvalidArgumentException(sprintf("Boundary value \"%s\" is not a valid number.", new StringConverter($boundary))); } @@ -35,7 +35,7 @@ public function __construct($boundary) */ public function match($value) { - if (!is_float($value) && !is_integer($value) && !is_double($value) && !is_numeric($value)) { + if (!is_float($value) && !is_int($value) && !is_numeric($value)) { $this->error = sprintf("Value \"%s\" is not a valid number.", new StringConverter($value)); return false; } diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/InArray.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/InArray.php index 084e240e..c7c10e61 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/InArray.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/InArray.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; use Coduo\ToString\StringConverter; -class InArray implements PatternExpander +final class InArray implements PatternExpander { /** * @var null|string diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsDateTime.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsDateTime.php index d20f8394..1612459f 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsDateTime.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsDateTime.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; use Coduo\ToString\StringConverter; -class IsDateTime implements PatternExpander +final class IsDateTime implements PatternExpander { /** * @var null|string diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsEmail.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsEmail.php index 5eb38656..337dcc0c 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsEmail.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsEmail.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; use Coduo\ToString\StringConverter; -class IsEmail implements PatternExpander +final class IsEmail implements PatternExpander { /** * @var null|string diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/isEmpty.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsEmpty.php similarity index 84% rename from src/Coduo/PHPMatcher/Matcher/Pattern/Expander/isEmpty.php rename to src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsEmpty.php index c06599ce..673a53e8 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/isEmpty.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsEmpty.php @@ -5,10 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; use Coduo\ToString\StringConverter; -/** - * @author Benjamin Lazarecki - */ -class isEmpty implements PatternExpander +final class IsEmpty implements PatternExpander { private $error; diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/NotEmpty.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsNotEmpty.php similarity index 92% rename from src/Coduo/PHPMatcher/Matcher/Pattern/Expander/NotEmpty.php rename to src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsNotEmpty.php index 0591d0de..65b7754c 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/NotEmpty.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsNotEmpty.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; use Coduo\ToString\StringConverter; -class NotEmpty implements PatternExpander +final class IsNotEmpty implements PatternExpander { private $error; diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsUrl.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsUrl.php index d76238a5..ca4ad5cf 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsUrl.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsUrl.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; use Coduo\ToString\StringConverter; -class IsUrl implements PatternExpander +final class IsUrl implements PatternExpander { /** * @var null|string diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/LowerThan.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/LowerThan.php index aa6806bf..e17a74f7 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/LowerThan.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/LowerThan.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; use Coduo\ToString\StringConverter; -class LowerThan implements PatternExpander +final class LowerThan implements PatternExpander { /** * @var diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/MatchRegex.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/MatchRegex.php index a62bc54f..73a83e89 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/MatchRegex.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/MatchRegex.php @@ -5,10 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; use Coduo\ToString\StringConverter; -/** - * @author Benjamin Lazarecki - */ -class MatchRegex implements PatternExpander +final class MatchRegex implements PatternExpander { /** * @var null|string diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/OneOf.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/OneOf.php index e299c9f1..7407e62e 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/OneOf.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/OneOf.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; use Coduo\ToString\StringConverter; -class OneOf implements PatternExpander +final class OneOf implements PatternExpander { /** * @var PatternExpander[] diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/StartsWith.php b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/StartsWith.php index 98eab054..e140bb7a 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/StartsWith.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/Expander/StartsWith.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; use Coduo\ToString\StringConverter; -class StartsWith implements PatternExpander +final class StartsWith implements PatternExpander { /** * @var diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/RegexConverter.php b/src/Coduo/PHPMatcher/Matcher/Pattern/RegexConverter.php index c42aa221..95b4704f 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/RegexConverter.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/RegexConverter.php @@ -4,7 +4,7 @@ use Coduo\PHPMatcher\Exception\UnknownTypeException; -class RegexConverter +final class RegexConverter { public function toRegex(TypePattern $typePattern) { diff --git a/src/Coduo/PHPMatcher/Matcher/Pattern/TypePattern.php b/src/Coduo/PHPMatcher/Matcher/Pattern/TypePattern.php index a0298da9..fcbc17ae 100644 --- a/src/Coduo/PHPMatcher/Matcher/Pattern/TypePattern.php +++ b/src/Coduo/PHPMatcher/Matcher/Pattern/TypePattern.php @@ -2,7 +2,7 @@ namespace Coduo\PHPMatcher\Matcher\Pattern; -class TypePattern implements Pattern +final class TypePattern implements Pattern { /** * @var string diff --git a/src/Coduo/PHPMatcher/Matcher/ScalarMatcher.php b/src/Coduo/PHPMatcher/Matcher/ScalarMatcher.php index cabddc5e..204b541a 100644 --- a/src/Coduo/PHPMatcher/Matcher/ScalarMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/ScalarMatcher.php @@ -4,7 +4,7 @@ use Coduo\ToString\StringConverter; -class ScalarMatcher extends Matcher +final class ScalarMatcher extends Matcher { /** * {@inheritDoc} diff --git a/src/Coduo/PHPMatcher/Matcher/StringMatcher.php b/src/Coduo/PHPMatcher/Matcher/StringMatcher.php index 4c3ec02b..98ed12df 100644 --- a/src/Coduo/PHPMatcher/Matcher/StringMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/StringMatcher.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Parser; use Coduo\ToString\StringConverter; -class StringMatcher extends Matcher +final class StringMatcher extends Matcher { /** * @var Parser diff --git a/src/Coduo/PHPMatcher/Matcher/TextMatcher.php b/src/Coduo/PHPMatcher/Matcher/TextMatcher.php index 786f4d7f..079663de 100644 --- a/src/Coduo/PHPMatcher/Matcher/TextMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/TextMatcher.php @@ -10,7 +10,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\RegexConverter; use Coduo\ToString\StringConverter; -class TextMatcher extends Matcher +final class TextMatcher extends Matcher { const PATTERN_REGEXP = "/@[a-zA-Z\\.]+@(\\.[a-zA-Z0-9_]+\\([a-zA-Z0-9{},:@\\.\"'\\(\\)]*\\))*/"; diff --git a/src/Coduo/PHPMatcher/Matcher/WildcardMatcher.php b/src/Coduo/PHPMatcher/Matcher/WildcardMatcher.php index dd52c922..4417498f 100644 --- a/src/Coduo/PHPMatcher/Matcher/WildcardMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/WildcardMatcher.php @@ -2,7 +2,7 @@ namespace Coduo\PHPMatcher\Matcher; -class WildcardMatcher extends Matcher +final class WildcardMatcher extends Matcher { const MATCH_PATTERN = "/^@(\*|wildcard)@$/"; diff --git a/src/Coduo/PHPMatcher/Matcher/XmlMatcher.php b/src/Coduo/PHPMatcher/Matcher/XmlMatcher.php index 2179bc81..2163eb2b 100644 --- a/src/Coduo/PHPMatcher/Matcher/XmlMatcher.php +++ b/src/Coduo/PHPMatcher/Matcher/XmlMatcher.php @@ -5,7 +5,7 @@ use Coduo\PHPMatcher\Matcher\Pattern\Assert\Xml; use LSS\XML2Array; -class XmlMatcher extends Matcher +final class XmlMatcher extends Matcher { /** * @var diff --git a/src/Coduo/PHPMatcher/Parser.php b/src/Coduo/PHPMatcher/Parser.php index 9c9848ba..4513ce13 100644 --- a/src/Coduo/PHPMatcher/Parser.php +++ b/src/Coduo/PHPMatcher/Parser.php @@ -9,7 +9,7 @@ use Coduo\PHPMatcher\Matcher\Pattern; use Coduo\PHPMatcher\Parser\ExpanderInitializer; -class Parser +final class Parser { const NULL_VALUE = 'null'; diff --git a/src/Coduo/PHPMatcher/Parser/ExpanderInitializer.php b/src/Coduo/PHPMatcher/Parser/ExpanderInitializer.php index bfdb1594..bdc4db49 100644 --- a/src/Coduo/PHPMatcher/Parser/ExpanderInitializer.php +++ b/src/Coduo/PHPMatcher/Parser/ExpanderInitializer.php @@ -9,7 +9,7 @@ use Coduo\PHPMatcher\Exception\UnknownExpanderException; use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander; -class ExpanderInitializer +final class ExpanderInitializer { /** * @var array @@ -17,7 +17,7 @@ class ExpanderInitializer private $expanderDefinitions = array( "startsWith" => "Coduo\\PHPMatcher\\Matcher\\Pattern\\Expander\\StartsWith", "endsWith" => "Coduo\\PHPMatcher\\Matcher\\Pattern\\Expander\\EndsWith", - "notEmpty" => "Coduo\\PHPMatcher\\Matcher\\Pattern\\Expander\\NotEmpty", + "isNotEmpty" => "Coduo\\PHPMatcher\\Matcher\\Pattern\\Expander\\IsNotEmpty", "isEmpty" => "Coduo\\PHPMatcher\\Matcher\\Pattern\\Expander\\IsEmpty", "isDateTime" => "Coduo\\PHPMatcher\\Matcher\\Pattern\\Expander\\IsDateTime", "isEmail" => "Coduo\\PHPMatcher\\Matcher\\Pattern\\Expander\\IsEmail", @@ -26,7 +26,7 @@ class ExpanderInitializer "greaterThan" => "Coduo\\PHPMatcher\\Matcher\\Pattern\\Expander\\GreaterThan", "inArray" => "Coduo\\PHPMatcher\\Matcher\\Pattern\\Expander\\InArray", "contains" => "Coduo\\PHPMatcher\\Matcher\\Pattern\\Expander\\Contains", - "match" => "Coduo\\PHPMatcher\\Matcher\\Pattern\\Expander\\MatchRegex", + "matchRegex" => "Coduo\\PHPMatcher\\Matcher\\Pattern\\Expander\\MatchRegex", "oneOf" => "Coduo\\PHPMatcher\\Matcher\\Pattern\\Expander\\OneOf" ); diff --git a/tests/Coduo/PHPMatcher/Matcher/CaptureMatcherTest.php b/tests/Coduo/PHPMatcher/Matcher/CaptureMatcherTest.php deleted file mode 100644 index ad969a81..00000000 --- a/tests/Coduo/PHPMatcher/Matcher/CaptureMatcherTest.php +++ /dev/null @@ -1,57 +0,0 @@ -assertTrue($matcher->canMatch($pattern)); - } - - /** - * @dataProvider negativeCanMatchData - */ - public function test_negative_can_matches($pattern) - { - $matcher = new CaptureMatcher(); - $this->assertFalse($matcher->canMatch($pattern)); - } - - public function test_capturing() - { - $matcher = new CaptureMatcher(); - - $matcher->match(50, ':userId:'); - $matcher->match('1111-qqqq-eeee-xxxx', ':token:'); - $this->assertEquals($matcher['userId'], 50); - $this->assertEquals($matcher['token'], '1111-qqqq-eeee-xxxx'); - } - - public static function positiveCanMatchData() - { - return array( - array(":id:"), - array(":user_id:"), - array(":foobar:") - ); - } - - public static function negativeCanMatchData() - { - return array( - array(":user_id"), - array("foobar"), - array(1), - array("user_id:"), - array(new \stdClass), - array(array("foobar")) - ); - } - -} diff --git a/tests/Coduo/PHPMatcher/Matcher/Pattern/Expander/isEmptyTest.php b/tests/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsEmptyTest.php similarity index 85% rename from tests/Coduo/PHPMatcher/Matcher/Pattern/Expander/isEmptyTest.php rename to tests/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsEmptyTest.php index bef5c662..fc13e6a0 100644 --- a/tests/Coduo/PHPMatcher/Matcher/Pattern/Expander/isEmptyTest.php +++ b/tests/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsEmptyTest.php @@ -2,12 +2,12 @@ namespace Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander; -use Coduo\PHPMatcher\Matcher\Pattern\Expander\isEmpty; +use Coduo\PHPMatcher\Matcher\Pattern\Expander\IsEmpty; /** * @author Benjamin Lazarecki */ -class isEmptyTest extends \PHPUnit_Framework_TestCase +class IsEmptyTest extends \PHPUnit_Framework_TestCase { /** * @dataProvider examplesProvider diff --git a/tests/Coduo/PHPMatcher/Matcher/Pattern/Expander/NotEmptyTest.php b/tests/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsNotEmptyTest.php similarity index 79% rename from tests/Coduo/PHPMatcher/Matcher/Pattern/Expander/NotEmptyTest.php rename to tests/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsNotEmptyTest.php index 1cc8b902..507ca8fd 100644 --- a/tests/Coduo/PHPMatcher/Matcher/Pattern/Expander/NotEmptyTest.php +++ b/tests/Coduo/PHPMatcher/Matcher/Pattern/Expander/IsNotEmptyTest.php @@ -3,16 +3,16 @@ namespace Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander; use Coduo\PHPMatcher\Matcher; -use Coduo\PHPMatcher\Matcher\Pattern\Expander\NotEmpty; +use Coduo\PHPMatcher\Matcher\Pattern\Expander\IsNotEmpty; -class NotEmptyTest extends \PHPUnit_Framework_TestCase +class IsNotEmptyTest extends \PHPUnit_Framework_TestCase { /** * @dataProvider examplesProvider */ public function test_examples_not_ignoring_case($value, $expectedResult) { - $expander = new NotEmpty(); + $expander = new IsNotEmpty(); $this->assertEquals($expectedResult, $expander->match($value)); } diff --git a/tests/Coduo/PHPMatcher/Matcher/StringMatcherTest.php b/tests/Coduo/PHPMatcher/Matcher/StringMatcherTest.php index df0b678a..81d90dc0 100644 --- a/tests/Coduo/PHPMatcher/Matcher/StringMatcherTest.php +++ b/tests/Coduo/PHPMatcher/Matcher/StringMatcherTest.php @@ -70,7 +70,7 @@ public static function positiveMatchData() { return array( array("lorem ipsum", "@string@"), - array("lorem ipsum", "@string@.notEmpty()"), + array("lorem ipsum", "@string@.isNotEmpty()"), array("lorem ipsum", "@string@.startsWith('lorem')"), array("lorem ipsum", "@string@.endsWith('ipsum')"), array("lorem ipsum dolor", "@string@.startsWith('lorem').contains('ipsum').endsWith('dolor')"), diff --git a/tests/Coduo/PHPMatcher/MatcherTest.php b/tests/Coduo/PHPMatcher/MatcherTest.php index a8282b75..7e70ff46 100644 --- a/tests/Coduo/PHPMatcher/MatcherTest.php +++ b/tests/Coduo/PHPMatcher/MatcherTest.php @@ -15,14 +15,10 @@ class MatcherTest extends \PHPUnit_Framework_TestCase protected $arrayValue; - protected $captureMatcher; - public function setUp() { - $this->captureMatcher = new Matcher\CaptureMatcher(); $parser = new Parser(new Lexer(), new Parser\ExpanderInitializer()); $scalarMatchers = new Matcher\ChainMatcher(array( - $this->captureMatcher, new Matcher\CallbackMatcher(), new Matcher\ExpressionMatcher(), new Matcher\NullMatcher(), @@ -208,15 +204,6 @@ public function test_error_when_json_value_does_not_match_json_pattern() $this->assertSame('"5" does not match "4".', $this->matcher->getError()); } - public function test_matcher_with_captures() - { - $this->assertTrue($this->matcher->match( - array('foo' => 'bar', 'user' => array('id' => 5)), - array('foo' => 'bar', 'user' => array('id' => ':uid:')) - )); - $this->assertEquals($this->captureMatcher['uid'], 5); - } - public function test_matcher_with_callback() { $this->assertTrue($this->matcher->match('test', function($value) { return $value === 'test';})); @@ -251,16 +238,16 @@ public static function expanderExamples() array("lorem ipsum", "@string@.isUrl()", false), array("2014-08-19", "@string@.isDateTime()", true), array(100, "@integer@.lowerThan(101).greaterThan(10)", true), - array("", "@string@.notEmpty()", false), - array("lorem ipsum", "@string@.notEmpty()", true), + array("", "@string@.isNotEmpty()", false), + array("lorem ipsum", "@string@.isNotEmpty()", true), array("", "@string@.isEmpty()", true), array(array("foo", "bar"), "@array@.inArray(\"bar\")", true), array(array(), "@array@.isEmpty()", true), array(array('foo'), "@array@.isEmpty()", false), array("lorem ipsum", "@string@.oneOf(contains(\"lorem\"), contains(\"test\"))", true), array("lorem ipsum", "@string@.oneOf(contains(\"lorem\"), contains(\"test\")).endsWith(\"ipsum\")", true), - array("lorem ipsum", "@string@.match(\"/^lorem \\w+$/\")", true), - array("lorem ipsum", "@string@.match(\"/^foo/\")", false), + array("lorem ipsum", "@string@.matchRegex(\"/^lorem \\w+$/\")", true), + array("lorem ipsum", "@string@.matchRegex(\"/^foo/\")", false), ); } }