From df73c82e0275e389adb133f1ecdb0bb26ccc394c Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Sun, 4 Feb 2018 22:11:35 +0100 Subject: [PATCH] Added backslash before native functions --- .php_cs | 3 +- src/AST/Expander.php | 2 +- src/AST/Pattern.php | 2 +- src/Exception/UnknownTypeException.php | 2 +- src/Lexer.php | 24 +++++++-------- src/Matcher/ArrayMatcher.php | 32 ++++++++++---------- src/Matcher/BooleanMatcher.php | 6 ++-- src/Matcher/CallbackMatcher.php | 2 +- src/Matcher/ChainMatcher.php | 2 +- src/Matcher/DoubleMatcher.php | 6 ++-- src/Matcher/ExpressionMatcher.php | 6 ++-- src/Matcher/IntegerMatcher.php | 6 ++-- src/Matcher/JsonMatcher.php | 8 ++--- src/Matcher/NullMatcher.php | 4 +-- src/Matcher/NumberMatcher.php | 6 ++-- src/Matcher/OrMatcher.php | 4 +-- src/Matcher/Pattern/Assert/Json.php | 8 ++--- src/Matcher/Pattern/Assert/Xml.php | 4 +-- src/Matcher/Pattern/Expander/Contains.php | 10 +++--- src/Matcher/Pattern/Expander/Count.php | 8 ++--- src/Matcher/Pattern/Expander/EndsWith.php | 12 ++++---- src/Matcher/Pattern/Expander/GreaterThan.php | 10 +++--- src/Matcher/Pattern/Expander/InArray.php | 8 ++--- src/Matcher/Pattern/Expander/IsDateTime.php | 6 ++-- src/Matcher/Pattern/Expander/IsEmail.php | 8 ++--- src/Matcher/Pattern/Expander/IsEmpty.php | 2 +- src/Matcher/Pattern/Expander/IsNotEmpty.php | 2 +- src/Matcher/Pattern/Expander/IsUrl.php | 8 ++--- src/Matcher/Pattern/Expander/LowerThan.php | 10 +++--- src/Matcher/Pattern/Expander/MatchRegex.php | 12 ++++---- src/Matcher/Pattern/Expander/OneOf.php | 6 ++-- src/Matcher/Pattern/Expander/Repeat.php | 28 ++++++++--------- src/Matcher/Pattern/Expander/StartsWith.php | 12 ++++---- src/Matcher/Pattern/TypePattern.php | 4 +-- src/Matcher/ScalarMatcher.php | 4 +-- src/Matcher/StringMatcher.php | 6 ++-- src/Matcher/TextMatcher.php | 28 ++++++++--------- src/Matcher/UuidMatcher.php | 14 ++++----- src/Matcher/WildcardMatcher.php | 2 +- src/Parser.php | 14 ++++----- src/Parser/ExpanderInitializer.php | 12 ++++---- tests/LexerTest.php | 4 +-- tests/Matcher/JsonMatcherTest.php | 18 +++++------ tests/Matcher/TextMatcherTest.php | 2 +- tests/PHPUnit/PHPMatcherAssertionsTest.php | 2 +- tests/PHPUnit/PHPMatcherTestCaseTest.php | 2 +- 46 files changed, 191 insertions(+), 190 deletions(-) diff --git a/.php_cs b/.php_cs index 01c6a900..5983888b 100644 --- a/.php_cs +++ b/.php_cs @@ -7,7 +7,8 @@ return PhpCsFixer\Config::create() 'blank_line_after_opening_tag' => true, 'single_blank_line_before_namespace' => true, 'no_unused_imports' => true, - 'single_quote' => true + 'single_quote' => true, + 'native_function_invocation' => true ]) ->setFinder( PhpCsFixer\Finder::create() diff --git a/src/AST/Expander.php b/src/AST/Expander.php index e77e45a2..42e3066b 100644 --- a/src/AST/Expander.php +++ b/src/AST/Expander.php @@ -28,7 +28,7 @@ public function addArgument($argument) public function hasArguments() : bool { - return (boolean) count($this->arguments); + return (boolean) \count($this->arguments); } public function getArguments() : array diff --git a/src/AST/Pattern.php b/src/AST/Pattern.php index ee3587b6..0d54e706 100644 --- a/src/AST/Pattern.php +++ b/src/AST/Pattern.php @@ -23,7 +23,7 @@ public function getType() : Type public function hasExpanders() : bool { - return (boolean) count($this->expanders); + return (boolean) \count($this->expanders); } /** diff --git a/src/Exception/UnknownTypeException.php b/src/Exception/UnknownTypeException.php index 619fcab3..61f54d4a 100644 --- a/src/Exception/UnknownTypeException.php +++ b/src/Exception/UnknownTypeException.php @@ -11,7 +11,7 @@ class UnknownTypeException extends Exception public function __construct(string $type) { $this->type = '@' . $type . '@'; - parent::__construct(sprintf('Type pattern "%s" is not supported.', $this->type), 0, null); + parent::__construct(\sprintf('Type pattern "%s" is not supported.', $this->type), 0, null); } public function getType() : string diff --git a/src/Lexer.php b/src/Lexer.php index c2d70631..5d8877a4 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -70,7 +70,7 @@ protected function getType(&$value) : int } if ($this->isTypePatternToken($value)) { - $value = trim($value, '@'); + $value = \trim($value, '@'); return self::T_TYPE_PATTERN; } @@ -80,7 +80,7 @@ protected function getType(&$value) : int } if ($this->isBooleanToken($value)) { - $value = (strtolower($value) === 'true') ? true : false; + $value = (\strtolower($value) === 'true') ? true : false; return self::T_BOOLEAN; } @@ -89,16 +89,16 @@ protected function getType(&$value) : int return self::T_NULL; } - if (is_numeric($value)) { - if (is_string($value)) { - $value = (strpos($value, '.') === false) ? (int) $value : (float) $value; + if (\is_numeric($value)) { + if (\is_string($value)) { + $value = (\strpos($value, '.') === false) ? (int) $value : (float) $value; } return self::T_NUMBER; } if ($this->isExpanderNameToken($value)) { - $value = rtrim(ltrim($value, '.'), '('); + $value = \rtrim(\ltrim($value, '.'), '('); return self::T_EXPANDER_NAME; } @@ -107,31 +107,31 @@ protected function getType(&$value) : int protected function isStringToken(string $value) : bool { - return in_array(substr($value, 0, 1), ['"', "'"]); + return \in_array(\substr($value, 0, 1), ['"', "'"]); } protected function isBooleanToken(string $value) : bool { - return in_array(strtolower($value), ['true', 'false'], true); + return \in_array(\strtolower($value), ['true', 'false'], true); } protected function isNullToken(string $value) : bool { - return strtolower($value) === 'null'; + return \strtolower($value) === 'null'; } protected function extractStringValue(string $value) : string { - return trim(trim($value, "'"), '"'); + return \trim(\trim($value, "'"), '"'); } protected function isExpanderNameToken(string $value) : bool { - return substr($value, -1) === '(' && strlen($value) > 1; + return \substr($value, -1) === '(' && \strlen($value) > 1; } protected function isTypePatternToken(string $value) : bool { - return substr($value, 0, 1) === '@' && substr($value, strlen($value) - 1, 1) === '@' && strlen($value) > 1; + return \substr($value, 0, 1) === '@' && \substr($value, \strlen($value) - 1, 1) === '@' && \strlen($value) > 1; } } diff --git a/src/Matcher/ArrayMatcher.php b/src/Matcher/ArrayMatcher.php index 63d25596..bbb9fbd4 100644 --- a/src/Matcher/ArrayMatcher.php +++ b/src/Matcher/ArrayMatcher.php @@ -34,8 +34,8 @@ public function match($value, $pattern) : bool return true; } - if (!is_array($value)) { - $this->error = sprintf('%s "%s" is not a valid array.', gettype($value), new StringConverter($value)); + if (!\is_array($value)) { + $this->error = \sprintf('%s "%s" is not a valid array.', \gettype($value), new StringConverter($value)); return false; } @@ -52,12 +52,12 @@ public function match($value, $pattern) : bool public function canMatch($pattern) : bool { - return is_array($pattern) || $this->isArrayPattern($pattern); + return \is_array($pattern) || $this->isArrayPattern($pattern); } private function isArrayPattern($pattern) : bool { - if (!is_string($pattern)) { + if (!\is_string($pattern)) { return false; } @@ -89,7 +89,7 @@ private function iterateMatch(array $values, array $patterns, string $parentPath continue; } - if (!is_array($value) || !$this->canMatch($pattern)) { + if (!\is_array($value) || !$this->canMatch($pattern)) { return false; } @@ -115,10 +115,10 @@ private function iterateMatch(array $values, array $patterns, string $parentPath private function isPatternValid(array $pattern, array $values, string $parentPath) : bool { - if (is_array($pattern)) { + if (\is_array($pattern)) { $skipPattern = static::UNBOUNDED_PATTERN; - $pattern = array_filter( + $pattern = \array_filter( $pattern, function ($item) use ($skipPattern) { return $item !== $skipPattern; @@ -126,8 +126,8 @@ function ($item) use ($skipPattern) { ); $notExistingKeys = $this->findNotExistingKeys($pattern, $values); - if (count($notExistingKeys) > 0) { - $keyNames = array_keys($notExistingKeys); + if (\count($notExistingKeys) > 0) { + $keyNames = \array_keys($notExistingKeys); $path = $this->formatFullPath($parentPath, $this->formatAccessPath($keyNames[0])); $this->setMissingElementInError('value', $path); @@ -140,10 +140,10 @@ function ($item) use ($skipPattern) { private function findNotExistingKeys(array $pattern, array $values) : array { - $notExistingKeys = array_diff_key($pattern, $values); + $notExistingKeys = \array_diff_key($pattern, $values); - return array_filter($notExistingKeys, function ($pattern) use ($values) { - if (is_array($pattern)) { + return \array_filter($notExistingKeys, function ($pattern) use ($values) { + if (\is_array($pattern)) { return !$this->match($values, $pattern); } @@ -195,7 +195,7 @@ private function valueExist(string $path, array $haystack) : bool private function arrayPropertyExists(string $property, array $objectOrArray) : bool { return ($objectOrArray instanceof \ArrayAccess && isset($objectOrArray[$property])) || - (is_array($objectOrArray) && array_key_exists($property, $objectOrArray)); + (\is_array($objectOrArray) && \array_key_exists($property, $objectOrArray)); } private function getValueByPath(array $array, string $path) @@ -217,17 +217,17 @@ private function getPropertyAccessor() : PropertyAccessorInterface private function setMissingElementInError(string $place, string $path) { - $this->error = sprintf('There is no element under path %s in %s.', $path, $place); + $this->error = \sprintf('There is no element under path %s in %s.', $path, $place); } private function formatAccessPath($key) : string { - return sprintf('[%s]', $key); + return \sprintf('[%s]', $key); } private function formatFullPath(string $parentPath, string $path) : string { - return sprintf('%s%s', $parentPath, $path); + return \sprintf('%s%s', $parentPath, $path); } private function shouldSkippValueMatchingFor($lastPattern) : bool diff --git a/src/Matcher/BooleanMatcher.php b/src/Matcher/BooleanMatcher.php index 3d9f5065..a5bd54b3 100644 --- a/src/Matcher/BooleanMatcher.php +++ b/src/Matcher/BooleanMatcher.php @@ -20,8 +20,8 @@ public function __construct(Parser $parser) public function match($value, $pattern) : bool { - if (!is_bool($value)) { - $this->error = sprintf('%s "%s" is not a valid boolean.', gettype($value), new StringConverter($value)); + if (!\is_bool($value)) { + $this->error = \sprintf('%s "%s" is not a valid boolean.', \gettype($value), new StringConverter($value)); return false; } @@ -30,7 +30,7 @@ public function match($value, $pattern) : bool public function canMatch($pattern) : bool { - if (!is_string($pattern)) { + if (!\is_string($pattern)) { return false; } diff --git a/src/Matcher/CallbackMatcher.php b/src/Matcher/CallbackMatcher.php index 0985fdd0..91a1f00d 100644 --- a/src/Matcher/CallbackMatcher.php +++ b/src/Matcher/CallbackMatcher.php @@ -13,6 +13,6 @@ public function match($value, $pattern) : bool public function canMatch($pattern) : bool { - return is_object($pattern) && is_callable($pattern); + return \is_object($pattern) && \is_callable($pattern); } } diff --git a/src/Matcher/ChainMatcher.php b/src/Matcher/ChainMatcher.php index 6347faa8..52280116 100644 --- a/src/Matcher/ChainMatcher.php +++ b/src/Matcher/ChainMatcher.php @@ -39,7 +39,7 @@ public function match($value, $pattern) : bool } if (!isset($this->error)) { - $this->error = sprintf( + $this->error = \sprintf( 'Any matcher from chain can\'t match value "%s" to pattern "%s"', new StringConverter($value), new StringConverter($pattern) diff --git a/src/Matcher/DoubleMatcher.php b/src/Matcher/DoubleMatcher.php index 6d639e02..4837a769 100644 --- a/src/Matcher/DoubleMatcher.php +++ b/src/Matcher/DoubleMatcher.php @@ -20,8 +20,8 @@ public function __construct(Parser $parser) public function match($value, $pattern) : bool { - if (!is_double($value)) { - $this->error = sprintf('%s "%s" is not a valid double.', gettype($value), new StringConverter($value)); + if (!\is_double($value)) { + $this->error = \sprintf('%s "%s" is not a valid double.', \gettype($value), new StringConverter($value)); return false; } @@ -36,7 +36,7 @@ public function match($value, $pattern) : bool public function canMatch($pattern) : bool { - if (!is_string($pattern)) { + if (!\is_string($pattern)) { return false; } diff --git a/src/Matcher/ExpressionMatcher.php b/src/Matcher/ExpressionMatcher.php index 3b6c99f7..a7ba9747 100644 --- a/src/Matcher/ExpressionMatcher.php +++ b/src/Matcher/ExpressionMatcher.php @@ -14,11 +14,11 @@ final class ExpressionMatcher extends Matcher public function match($value, $pattern) : bool { $language = new ExpressionLanguage(); - preg_match(self::MATCH_PATTERN, $pattern, $matches); + \preg_match(self::MATCH_PATTERN, $pattern, $matches); $expressionResult = $language->evaluate($matches[1], ['value' => $value]); if (!$expressionResult) { - $this->error = sprintf('"%s" expression fails for value "%s".', $pattern, new StringConverter($value)); + $this->error = \sprintf('"%s" expression fails for value "%s".', $pattern, new StringConverter($value)); } return (bool) $expressionResult; @@ -26,6 +26,6 @@ public function match($value, $pattern) : bool public function canMatch($pattern) : bool { - return is_string($pattern) && 0 !== preg_match(self::MATCH_PATTERN, $pattern); + return \is_string($pattern) && 0 !== \preg_match(self::MATCH_PATTERN, $pattern); } } diff --git a/src/Matcher/IntegerMatcher.php b/src/Matcher/IntegerMatcher.php index 14656920..bbb56630 100644 --- a/src/Matcher/IntegerMatcher.php +++ b/src/Matcher/IntegerMatcher.php @@ -20,8 +20,8 @@ public function __construct(Parser $parser) public function match($value, $pattern) : bool { - if (!is_integer($value)) { - $this->error = sprintf('%s "%s" is not a valid integer.', gettype($value), new StringConverter($value)); + if (!\is_integer($value)) { + $this->error = \sprintf('%s "%s" is not a valid integer.', \gettype($value), new StringConverter($value)); return false; } @@ -36,7 +36,7 @@ public function match($value, $pattern) : bool public function canMatch($pattern) : bool { - if (!is_string($pattern)) { + if (!\is_string($pattern)) { return false; } diff --git a/src/Matcher/JsonMatcher.php b/src/Matcher/JsonMatcher.php index f208b297..93267045 100644 --- a/src/Matcher/JsonMatcher.php +++ b/src/Matcher/JsonMatcher.php @@ -22,17 +22,17 @@ public function match($value, $pattern) : bool } if (!Json::isValid($value)) { - $this->error = sprintf('Invalid given JSON of value. %s', $this->getErrorMessage()); + $this->error = \sprintf('Invalid given JSON of value. %s', $this->getErrorMessage()); return false; } if (!Json::isValidPattern($pattern)) { - $this->error = sprintf('Invalid given JSON of pattern. %s', $this->getErrorMessage()); + $this->error = \sprintf('Invalid given JSON of pattern. %s', $this->getErrorMessage()); return false; } $transformedPattern = Json::transformPattern($pattern); - $match = $this->matcher->match(json_decode($value, true), json_decode($transformedPattern, true)); + $match = $this->matcher->match(\json_decode($value, true), \json_decode($transformedPattern, true)); if (!$match) { $this->error = $this->matcher->getError(); return false; @@ -48,7 +48,7 @@ public function canMatch($pattern) : bool private function getErrorMessage() { - switch (json_last_error()) { + switch (\json_last_error()) { case JSON_ERROR_DEPTH: return 'Maximum stack depth exceeded'; case JSON_ERROR_STATE_MISMATCH: diff --git a/src/Matcher/NullMatcher.php b/src/Matcher/NullMatcher.php index 381f8f81..eee6569c 100644 --- a/src/Matcher/NullMatcher.php +++ b/src/Matcher/NullMatcher.php @@ -16,7 +16,7 @@ final class NullMatcher extends Matcher public function match($value, $pattern) : bool { if (null !== $value) { - $this->error = sprintf('%s "%s" does not match null.', gettype($value), new StringConverter($value)); + $this->error = \sprintf('%s "%s" does not match null.', \gettype($value), new StringConverter($value)); return false; } @@ -28,6 +28,6 @@ public function match($value, $pattern) : bool */ public function canMatch($pattern) : bool { - return is_null($pattern) || (is_string($pattern) && 0 !== preg_match(self::MATCH_PATTERN, $pattern)); + return \is_null($pattern) || (\is_string($pattern) && 0 !== \preg_match(self::MATCH_PATTERN, $pattern)); } } diff --git a/src/Matcher/NumberMatcher.php b/src/Matcher/NumberMatcher.php index b1d8ee2f..5606c29f 100644 --- a/src/Matcher/NumberMatcher.php +++ b/src/Matcher/NumberMatcher.php @@ -20,8 +20,8 @@ public function __construct(Parser $parser) public function match($value, $pattern) : bool { - if (!is_numeric($value)) { - $this->error = sprintf('%s "%s" is not a valid number.', gettype($value), new StringConverter($value)); + if (!\is_numeric($value)) { + $this->error = \sprintf('%s "%s" is not a valid number.', \gettype($value), new StringConverter($value)); return false; } @@ -30,7 +30,7 @@ public function match($value, $pattern) : bool public function canMatch($pattern) : bool { - if (!is_string($pattern)) { + if (!\is_string($pattern)) { return false; } diff --git a/src/Matcher/OrMatcher.php b/src/Matcher/OrMatcher.php index 08337230..620a0f32 100644 --- a/src/Matcher/OrMatcher.php +++ b/src/Matcher/OrMatcher.php @@ -17,7 +17,7 @@ public function __construct(ChainMatcher $chainMatcher) public function match($value, $pattern) : bool { - $patterns = explode('||', $pattern); + $patterns = \explode('||', $pattern); foreach ($patterns as $childPattern) { if ($this->matchChild($value, $childPattern)) { return true; @@ -42,6 +42,6 @@ private function matchChild($value, $pattern) : bool public function canMatch($pattern): bool { - return is_string($pattern) && 0 !== preg_match_all(self::MATCH_PATTERN, $pattern, $matches); + return \is_string($pattern) && 0 !== \preg_match_all(self::MATCH_PATTERN, $pattern, $matches); } } diff --git a/src/Matcher/Pattern/Assert/Json.php b/src/Matcher/Pattern/Assert/Json.php index 0dd33f7d..5df2c903 100644 --- a/src/Matcher/Pattern/Assert/Json.php +++ b/src/Matcher/Pattern/Assert/Json.php @@ -11,11 +11,11 @@ final class Json public static function isValid($value) : bool { - if (!is_string($value)) { + if (!\is_string($value)) { return false; } - if (null === json_decode($value) && JSON_ERROR_NONE !== json_last_error()) { + if (null === \json_decode($value) && JSON_ERROR_NONE !== \json_last_error()) { return false; } @@ -24,7 +24,7 @@ public static function isValid($value) : bool public static function isValidPattern($value) : bool { - if (!is_string($value)) { + if (!\is_string($value)) { return false; } @@ -33,6 +33,6 @@ public static function isValidPattern($value) : bool public static function transformPattern(string $pattern) : string { - return preg_replace(self::TRANSFORM_QUOTATION_PATTERN, self::TRANSFORM_QUOTATION_REPLACEMENT, $pattern); + return \preg_replace(self::TRANSFORM_QUOTATION_PATTERN, self::TRANSFORM_QUOTATION_REPLACEMENT, $pattern); } } diff --git a/src/Matcher/Pattern/Assert/Xml.php b/src/Matcher/Pattern/Assert/Xml.php index cf179731..1687e035 100644 --- a/src/Matcher/Pattern/Assert/Xml.php +++ b/src/Matcher/Pattern/Assert/Xml.php @@ -8,10 +8,10 @@ final class Xml { public static function isValid($value) : bool { - if (!is_string($value)) { + if (!\is_string($value)) { return false; } - $xml = @simplexml_load_string($value); + $xml = @\simplexml_load_string($value); if (!$xml instanceof \SimpleXMLElement) { return false; } diff --git a/src/Matcher/Pattern/Expander/Contains.php b/src/Matcher/Pattern/Expander/Contains.php index 4bad1d78..8fe63442 100644 --- a/src/Matcher/Pattern/Expander/Contains.php +++ b/src/Matcher/Pattern/Expander/Contains.php @@ -42,17 +42,17 @@ public function __construct(string $string, $ignoreCase = false) public function match($value) : bool { - if (!is_string($value)) { - $this->error = sprintf('Contains expander require "string", got "%s".', new StringConverter($value)); + if (!\is_string($value)) { + $this->error = \sprintf('Contains expander require "string", got "%s".', new StringConverter($value)); return false; } $contains = $this->ignoreCase - ? mb_strpos(mb_strtolower($value), mb_strtolower($this->string)) - : mb_strpos($value, $this->string); + ? \mb_strpos(\mb_strtolower($value), \mb_strtolower($this->string)) + : \mb_strpos($value, $this->string); if ($contains === false) { - $this->error = sprintf("String \"%s\" doesn't contains \"%s\".", $value, $this->string); + $this->error = \sprintf("String \"%s\" doesn't contains \"%s\".", $value, $this->string); return false; } diff --git a/src/Matcher/Pattern/Expander/Count.php b/src/Matcher/Pattern/Expander/Count.php index 3f3b9f48..9ea04307 100644 --- a/src/Matcher/Pattern/Expander/Count.php +++ b/src/Matcher/Pattern/Expander/Count.php @@ -27,13 +27,13 @@ public function __construct(int $value) public function match($value) :bool { - if (!is_array($value)) { - $this->error = sprintf('Count expander require "array", got "%s".', new StringConverter($value)); + if (!\is_array($value)) { + $this->error = \sprintf('Count expander require "array", got "%s".', new StringConverter($value)); return false; } - if (count($value) !== $this->value) { - $this->error = sprintf('Expected count of %s is %s.', new StringConverter($value), new StringConverter($this->value)); + if (\count($value) !== $this->value) { + $this->error = \sprintf('Expected count of %s is %s.', new StringConverter($value), new StringConverter($this->value)); return false; } diff --git a/src/Matcher/Pattern/Expander/EndsWith.php b/src/Matcher/Pattern/Expander/EndsWith.php index 6b28866c..221dcbe5 100644 --- a/src/Matcher/Pattern/Expander/EndsWith.php +++ b/src/Matcher/Pattern/Expander/EndsWith.php @@ -19,7 +19,7 @@ final class EndsWith implements PatternExpander public function __construct(string $stringEnding, bool $ignoreCase = false) { - if (!is_string($stringEnding)) { + if (!\is_string($stringEnding)) { throw new \InvalidArgumentException('String ending must be a valid string.'); } @@ -34,8 +34,8 @@ public static function is(string $name) : bool public function match($value) : bool { - if (!is_string($value)) { - $this->error = sprintf('EndsWith expander require "string", got "%s".', new StringConverter($value)); + if (!\is_string($value)) { + $this->error = \sprintf('EndsWith expander require "string", got "%s".', new StringConverter($value)); return false; } @@ -44,7 +44,7 @@ public function match($value) : bool } if (!$this->matchValue($value)) { - $this->error = sprintf("string \"%s\" doesn't ends with string \"%s\".", $value, $this->stringEnding); + $this->error = \sprintf("string \"%s\" doesn't ends with string \"%s\".", $value, $this->stringEnding); return false; } @@ -59,7 +59,7 @@ public function getError() protected function matchValue(string $value) : bool { return $this->ignoreCase - ? mb_substr(mb_strtolower($value), -mb_strlen(mb_strtolower($this->stringEnding))) === mb_strtolower($this->stringEnding) - : mb_substr($value, -mb_strlen($this->stringEnding)) === $this->stringEnding; + ? \mb_substr(\mb_strtolower($value), -\mb_strlen(\mb_strtolower($this->stringEnding))) === \mb_strtolower($this->stringEnding) + : \mb_substr($value, -\mb_strlen($this->stringEnding)) === $this->stringEnding; } } diff --git a/src/Matcher/Pattern/Expander/GreaterThan.php b/src/Matcher/Pattern/Expander/GreaterThan.php index 5bd3fe2c..38707d36 100644 --- a/src/Matcher/Pattern/Expander/GreaterThan.php +++ b/src/Matcher/Pattern/Expander/GreaterThan.php @@ -17,8 +17,8 @@ final class GreaterThan implements PatternExpander public function __construct($boundary) { - if (!is_float($boundary) && !is_int($boundary)) { - throw new \InvalidArgumentException(sprintf('Boundary value "%s" is not a valid number.', new StringConverter($boundary))); + if (!\is_float($boundary) && !\is_int($boundary)) { + throw new \InvalidArgumentException(\sprintf('Boundary value "%s" is not a valid number.', new StringConverter($boundary))); } $this->boundary = $boundary; @@ -31,13 +31,13 @@ public static function is(string $name) : bool public function match($value) : bool { - if (!is_float($value) && !is_int($value) && !is_numeric($value)) { - $this->error = sprintf('Value "%s" is not a valid number.', new StringConverter($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; } if ($value <= $this->boundary) { - $this->error = sprintf('Value "%s" is not greater than "%s".', new StringConverter($value), new StringConverter($this->boundary)); + $this->error = \sprintf('Value "%s" is not greater than "%s".', new StringConverter($value), new StringConverter($this->boundary)); return false; } diff --git a/src/Matcher/Pattern/Expander/InArray.php b/src/Matcher/Pattern/Expander/InArray.php index c226f9a7..b9935411 100644 --- a/src/Matcher/Pattern/Expander/InArray.php +++ b/src/Matcher/Pattern/Expander/InArray.php @@ -27,13 +27,13 @@ public static function is(string $name) : bool public function match($value) : bool { - if (!is_array($value)) { - $this->error = sprintf('InArray expander require "array", got "%s".', new StringConverter($value)); + if (!\is_array($value)) { + $this->error = \sprintf('InArray expander require "array", got "%s".', new StringConverter($value)); return false; } - if (!in_array($this->value, $value, true)) { - $this->error = sprintf("%s doesn't have \"%s\" element.", new StringConverter($value), new StringConverter($this->value)); + if (!\in_array($this->value, $value, true)) { + $this->error = \sprintf("%s doesn't have \"%s\" element.", new StringConverter($value), new StringConverter($this->value)); return false; } diff --git a/src/Matcher/Pattern/Expander/IsDateTime.php b/src/Matcher/Pattern/Expander/IsDateTime.php index 19ae7d29..d6d0ec62 100644 --- a/src/Matcher/Pattern/Expander/IsDateTime.php +++ b/src/Matcher/Pattern/Expander/IsDateTime.php @@ -20,13 +20,13 @@ public static function is(string $name) : bool public function match($value) : bool { - if (false === is_string($value)) { - $this->error = sprintf('IsDateTime expander require "string", got "%s".', new StringConverter($value)); + if (false === \is_string($value)) { + $this->error = \sprintf('IsDateTime expander require "string", got "%s".', new StringConverter($value)); return false; } if (false === $this->matchValue($value)) { - $this->error = sprintf('string "%s" is not a valid date.', $value); + $this->error = \sprintf('string "%s" is not a valid date.', $value); return false; } diff --git a/src/Matcher/Pattern/Expander/IsEmail.php b/src/Matcher/Pattern/Expander/IsEmail.php index d1de7616..b5cf7733 100644 --- a/src/Matcher/Pattern/Expander/IsEmail.php +++ b/src/Matcher/Pattern/Expander/IsEmail.php @@ -20,13 +20,13 @@ public static function is(string $name) : bool public function match($value) : bool { - if (false === is_string($value)) { - $this->error = sprintf('IsEmail expander require "string", got "%s".', new StringConverter($value)); + if (false === \is_string($value)) { + $this->error = \sprintf('IsEmail expander require "string", got "%s".', new StringConverter($value)); return false; } if (false === $this->matchValue($value)) { - $this->error = sprintf('string "%s" is not a valid e-mail address.', $value); + $this->error = \sprintf('string "%s" is not a valid e-mail address.', $value); return false; } @@ -41,7 +41,7 @@ public function getError() protected function matchValue(string $value) : bool { try { - return false !== filter_var($value, FILTER_VALIDATE_EMAIL); + return false !== \filter_var($value, FILTER_VALIDATE_EMAIL); } catch (\Exception $e) { return false; } diff --git a/src/Matcher/Pattern/Expander/IsEmpty.php b/src/Matcher/Pattern/Expander/IsEmpty.php index 41ab5578..eb19a036 100644 --- a/src/Matcher/Pattern/Expander/IsEmpty.php +++ b/src/Matcher/Pattern/Expander/IsEmpty.php @@ -21,7 +21,7 @@ public static function is(string $name) : bool public function match($value) : bool { if (!empty($value)) { - $this->error = sprintf('Value %s is not empty.', new StringConverter($value)); + $this->error = \sprintf('Value %s is not empty.', new StringConverter($value)); return false; } diff --git a/src/Matcher/Pattern/Expander/IsNotEmpty.php b/src/Matcher/Pattern/Expander/IsNotEmpty.php index 69215752..2c2879f1 100644 --- a/src/Matcher/Pattern/Expander/IsNotEmpty.php +++ b/src/Matcher/Pattern/Expander/IsNotEmpty.php @@ -21,7 +21,7 @@ public static function is(string $name) : bool public function match($value) : bool { if (false === $value || (empty($value) && '0' != $value)) { - $this->error = sprintf('Value %s is not blank.', new StringConverter($value)); + $this->error = \sprintf('Value %s is not blank.', new StringConverter($value)); return false; } diff --git a/src/Matcher/Pattern/Expander/IsUrl.php b/src/Matcher/Pattern/Expander/IsUrl.php index 257aed0b..8f3497cb 100644 --- a/src/Matcher/Pattern/Expander/IsUrl.php +++ b/src/Matcher/Pattern/Expander/IsUrl.php @@ -20,13 +20,13 @@ public static function is(string $name) : bool public function match($value) : bool { - if (false === is_string($value)) { - $this->error = sprintf('IsUrl expander require "string", got "%s".', new StringConverter($value)); + if (false === \is_string($value)) { + $this->error = \sprintf('IsUrl expander require "string", got "%s".', new StringConverter($value)); return false; } if (false === $this->matchValue($value)) { - $this->error = sprintf('string "%s" is not a valid URL.', $value); + $this->error = \sprintf('string "%s" is not a valid URL.', $value); return false; } @@ -41,7 +41,7 @@ public function getError() protected function matchValue(string $value) : bool { try { - return false !== filter_var($value, FILTER_VALIDATE_URL); + return false !== \filter_var($value, FILTER_VALIDATE_URL); } catch (\Exception $e) { return false; } diff --git a/src/Matcher/Pattern/Expander/LowerThan.php b/src/Matcher/Pattern/Expander/LowerThan.php index d752e9ea..d00d8b13 100644 --- a/src/Matcher/Pattern/Expander/LowerThan.php +++ b/src/Matcher/Pattern/Expander/LowerThan.php @@ -18,8 +18,8 @@ final class LowerThan implements PatternExpander public function __construct($boundary) { - if (!is_float($boundary) && !is_integer($boundary) && !is_double($boundary)) { - throw new \InvalidArgumentException(sprintf('Boundary value "%s" is not a valid number.', new StringConverter($boundary))); + if (!\is_float($boundary) && !\is_integer($boundary) && !\is_double($boundary)) { + throw new \InvalidArgumentException(\sprintf('Boundary value "%s" is not a valid number.', new StringConverter($boundary))); } $this->boundary = $boundary; @@ -32,13 +32,13 @@ public static function is(string $name) : bool public function match($value) : bool { - if (!is_float($value) && !is_integer($value) && !is_double($value)) { - $this->error = sprintf('Value "%s" is not a valid number.', new StringConverter($value)); + if (!\is_float($value) && !\is_integer($value) && !\is_double($value)) { + $this->error = \sprintf('Value "%s" is not a valid number.', new StringConverter($value)); return false; } if ($value >= $this->boundary) { - $this->error = sprintf('Value "%s" is not lower than "%s".', new StringConverter($value), new StringConverter($this->boundary)); + $this->error = \sprintf('Value "%s" is not lower than "%s".', new StringConverter($value), new StringConverter($this->boundary)); return false; } diff --git a/src/Matcher/Pattern/Expander/MatchRegex.php b/src/Matcher/Pattern/Expander/MatchRegex.php index f82e33a2..3144be2f 100644 --- a/src/Matcher/Pattern/Expander/MatchRegex.php +++ b/src/Matcher/Pattern/Expander/MatchRegex.php @@ -17,11 +17,11 @@ final class MatchRegex implements PatternExpander public function __construct($pattern) { - if (!is_string($pattern)) { + if (!\is_string($pattern)) { throw new \InvalidArgumentException('Regex pattern must be a string.'); } - if (!is_string($pattern) || @preg_match($pattern, '') === false) { + if (!\is_string($pattern) || @\preg_match($pattern, '') === false) { throw new \InvalidArgumentException('Regex pattern must be a valid one.'); } @@ -35,14 +35,14 @@ public static function is(string $name) : bool public function match($value) : bool { - if (false === is_string($value)) { - $this->error = sprintf('Match expander require "string", got "%s".', new StringConverter($value)); + if (false === \is_string($value)) { + $this->error = \sprintf('Match expander require "string", got "%s".', new StringConverter($value)); return false; } - if (1 !== preg_match($this->pattern, $value)) { - $this->error = sprintf("string \"%s\" don't match pattern %s.", $value, $this->pattern); + if (1 !== \preg_match($this->pattern, $value)) { + $this->error = \sprintf("string \"%s\" don't match pattern %s.", $value, $this->pattern); return false; } diff --git a/src/Matcher/Pattern/Expander/OneOf.php b/src/Matcher/Pattern/Expander/OneOf.php index 23195328..2174706e 100644 --- a/src/Matcher/Pattern/Expander/OneOf.php +++ b/src/Matcher/Pattern/Expander/OneOf.php @@ -20,10 +20,10 @@ final class OneOf implements PatternExpander public function __construct() { - if (func_num_args() < 2) { + if (\func_num_args() < 2) { throw new \InvalidArgumentException('OneOf expander require at least two expanders.'); } - foreach (func_get_args() as $argument) { + foreach (\func_get_args() as $argument) { if (!$argument instanceof PatternExpander) { throw new \InvalidArgumentException('OneOf expander require each argument to be a valid PatternExpander.'); } @@ -45,7 +45,7 @@ public function match($value) : bool } } - $this->error = sprintf('Any expander available in OneOf expander does not match "%s".', new StringConverter($value)); + $this->error = \sprintf('Any expander available in OneOf expander does not match "%s".', new StringConverter($value)); return false; } diff --git a/src/Matcher/Pattern/Expander/Repeat.php b/src/Matcher/Pattern/Expander/Repeat.php index dc2b26a7..27d8cb07 100644 --- a/src/Matcher/Pattern/Expander/Repeat.php +++ b/src/Matcher/Pattern/Expander/Repeat.php @@ -46,7 +46,7 @@ public static function is(string $name) : bool */ public function __construct(string $pattern, bool $isStrict = true) { - if (!is_string($pattern)) { + if (!\is_string($pattern)) { throw new \InvalidArgumentException('Repeat pattern must be a string.'); } @@ -54,9 +54,9 @@ public function __construct(string $pattern, bool $isStrict = true) $this->isStrict = $isStrict; $this->isScalar = true; - $json = json_decode($pattern, true); + $json = \json_decode($pattern, true); - if ($json !== null && json_last_error() === JSON_ERROR_NONE) { + if ($json !== null && \json_last_error() === JSON_ERROR_NONE) { $this->pattern = $json; $this->isScalar = false; } @@ -68,8 +68,8 @@ public function __construct(string $pattern, bool $isStrict = true) */ public function match($values) : bool { - if (!is_array($values)) { - $this->error = sprintf('Repeat expander require "array", got "%s".', new StringConverter($values)); + if (!\is_array($values)) { + $this->error = \sprintf('Repeat expander require "array", got "%s".', new StringConverter($values)); return false; } @@ -102,7 +102,7 @@ private function matchScalar(array $values, Matcher $matcher) : bool $match = $matcher->match($value, $this->pattern); if (!$match) { - $this->error = sprintf('Repeat expander, entry n°%d, find error : %s', $index, $matcher->getError()); + $this->error = \sprintf('Repeat expander, entry n°%d, find error : %s', $index, $matcher->getError()); return false; } } @@ -117,28 +117,28 @@ private function matchScalar(array $values, Matcher $matcher) : bool */ private function matchJson(array $values, Matcher $matcher) : bool { - $patternKeys = array_keys($this->pattern); - $patternKeysLength = count($patternKeys); + $patternKeys = \array_keys($this->pattern); + $patternKeysLength = \count($patternKeys); foreach ($values as $index => $value) { - $valueKeys = array_keys($value); - $valueKeysLength = count($valueKeys); + $valueKeys = \array_keys($value); + $valueKeysLength = \count($valueKeys); if ($this->isStrict && $patternKeysLength !== $valueKeysLength) { - $this->error = sprintf('Repeat expander expect to have %d keys in array but get : %d', $patternKeysLength, $valueKeysLength); + $this->error = \sprintf('Repeat expander expect to have %d keys in array but get : %d', $patternKeysLength, $valueKeysLength); return false; } foreach ($patternKeys as $key) { - if (!array_key_exists($key, $value)) { - $this->error = sprintf('Repeat expander, entry n°%d, require "array" to have key "%s".', $index, $key); + if (!\array_key_exists($key, $value)) { + $this->error = \sprintf('Repeat expander, entry n°%d, require "array" to have key "%s".', $index, $key); return false; } $match = $matcher->match($value[$key], $this->pattern[$key]); if (!$match) { - $this->error = sprintf('Repeat expander, entry n°%d, key "%s", find error : %s', $index, $key, $matcher->getError()); + $this->error = \sprintf('Repeat expander, entry n°%d, key "%s", find error : %s', $index, $key, $matcher->getError()); return false; } } diff --git a/src/Matcher/Pattern/Expander/StartsWith.php b/src/Matcher/Pattern/Expander/StartsWith.php index 8fb95138..01e01719 100644 --- a/src/Matcher/Pattern/Expander/StartsWith.php +++ b/src/Matcher/Pattern/Expander/StartsWith.php @@ -19,7 +19,7 @@ final class StartsWith implements PatternExpander public function __construct(string $stringBeginning, bool $ignoreCase = false) { - if (!is_string($stringBeginning)) { + if (!\is_string($stringBeginning)) { throw new \InvalidArgumentException('String beginning must be a valid string.'); } @@ -35,8 +35,8 @@ public static function is(string $name) : bool public function match($value) : bool { - if (!is_string($value)) { - $this->error = sprintf('StartsWith expander require "string", got "%s".', new StringConverter($value)); + if (!\is_string($value)) { + $this->error = \sprintf('StartsWith expander require "string", got "%s".', new StringConverter($value)); return false; } @@ -45,7 +45,7 @@ public function match($value) : bool } if ($this->matchValue($value)) { - $this->error = sprintf("string \"%s\" doesn't starts with string \"%s\".", $value, $this->stringBeginning); + $this->error = \sprintf("string \"%s\" doesn't starts with string \"%s\".", $value, $this->stringBeginning); return false; } @@ -60,7 +60,7 @@ public function getError() protected function matchValue(string $value) : bool { return $this->ignoreCase - ? mb_strpos(mb_strtolower($value), mb_strtolower($this->stringBeginning)) !== 0 - : mb_strpos($value, $this->stringBeginning) !== 0; + ? \mb_strpos(\mb_strtolower($value), \mb_strtolower($this->stringBeginning)) !== 0 + : \mb_strpos($value, $this->stringBeginning) !== 0; } } diff --git a/src/Matcher/Pattern/TypePattern.php b/src/Matcher/Pattern/TypePattern.php index 97bf5af6..e9bb0b09 100644 --- a/src/Matcher/Pattern/TypePattern.php +++ b/src/Matcher/Pattern/TypePattern.php @@ -20,12 +20,12 @@ public function __construct(string $type) public function is(string $type) { - return strtolower($this->type) === strtolower($type); + return \strtolower($this->type) === \strtolower($type); } public function getType() : string { - return strtolower($this->type); + return \strtolower($this->type); } public function addExpander(PatternExpander $expander) diff --git a/src/Matcher/ScalarMatcher.php b/src/Matcher/ScalarMatcher.php index 6d28653d..31e3aafa 100644 --- a/src/Matcher/ScalarMatcher.php +++ b/src/Matcher/ScalarMatcher.php @@ -11,7 +11,7 @@ final class ScalarMatcher extends Matcher public function match($value, $pattern) : bool { if ($value !== $pattern) { - $this->error = sprintf('"%s" does not match "%s".', new StringConverter($value), new StringConverter($pattern)); + $this->error = \sprintf('"%s" does not match "%s".', new StringConverter($value), new StringConverter($pattern)); return false; } @@ -20,6 +20,6 @@ public function match($value, $pattern) : bool public function canMatch($pattern) : bool { - return is_scalar($pattern); + return \is_scalar($pattern); } } diff --git a/src/Matcher/StringMatcher.php b/src/Matcher/StringMatcher.php index eb23be0a..53fd8ca4 100644 --- a/src/Matcher/StringMatcher.php +++ b/src/Matcher/StringMatcher.php @@ -20,8 +20,8 @@ public function __construct(Parser $parser) public function match($value, $pattern) : bool { - if (!is_string($value)) { - $this->error = sprintf('%s "%s" is not a valid string.', gettype($value), new StringConverter($value)); + if (!\is_string($value)) { + $this->error = \sprintf('%s "%s" is not a valid string.', \gettype($value), new StringConverter($value)); return false; } @@ -36,7 +36,7 @@ public function match($value, $pattern) : bool public function canMatch($pattern) : bool { - if (!is_string($pattern)) { + if (!\is_string($pattern)) { return false; } diff --git a/src/Matcher/TextMatcher.php b/src/Matcher/TextMatcher.php index 93a335d2..09ab0cdc 100644 --- a/src/Matcher/TextMatcher.php +++ b/src/Matcher/TextMatcher.php @@ -43,8 +43,8 @@ public function __construct(ValueMatcher $matcher, Parser $parser) */ public function match($value, $pattern) : bool { - if (!is_string($value)) { - $this->error = sprintf('%s "%s" is not a valid string.', gettype($value), new StringConverter($value)); + if (!\is_string($value)) { + $this->error = \sprintf('%s "%s" is not a valid string.', \gettype($value), new StringConverter($value)); return false; } @@ -54,18 +54,18 @@ public function match($value, $pattern) : bool try { $patternRegex = $this->replacePlaceholderWithPatternRegexes($patternRegex, $patternsReplacedWithRegex); } catch (UnknownTypeException $exception) { - $this->error = sprintf(sprintf('Type pattern "%s" is not supported by TextMatcher.', $exception->getType())); + $this->error = \sprintf(\sprintf('Type pattern "%s" is not supported by TextMatcher.', $exception->getType())); return false; } - if (!preg_match($patternRegex, $value, $matchedValues)) { - $this->error = sprintf('"%s" does not match "%s" pattern', $value, $pattern); + if (!\preg_match($patternRegex, $value, $matchedValues)) { + $this->error = \sprintf('"%s" does not match "%s" pattern', $value, $pattern); return false; } - array_shift($matchedValues); // remove matched string + \array_shift($matchedValues); // remove matched string - if (count($patternsReplacedWithRegex) !== count($matchedValues)) { + if (\count($patternsReplacedWithRegex) !== \count($matchedValues)) { $this->error = 'Unexpected TextMatcher error.'; return false; } @@ -85,7 +85,7 @@ public function match($value, $pattern) : bool */ public function canMatch($pattern) : bool { - if (!is_string($pattern)) { + if (!\is_string($pattern)) { return false; } @@ -113,14 +113,14 @@ public function canMatch($pattern) : bool private function replaceTypePatternsWithPlaceholders(string &$patternRegex) : array { $patternsReplacedWithRegex = []; - preg_match_all(self::PATTERN_REGEXP, $patternRegex, $matches); + \preg_match_all(self::PATTERN_REGEXP, $patternRegex, $matches); foreach ($matches[0] as $index => $typePatternString) { $typePattern = $this->parser->parse($typePatternString); $patternsReplacedWithRegex[] = $typePattern; - $patternRegex = str_replace( + $patternRegex = \str_replace( $typePatternString, - sprintf(self::PATTERN_REGEXP_PLACEHOLDER_TEMPLATE, $index), + \sprintf(self::PATTERN_REGEXP_PLACEHOLDER_TEMPLATE, $index), $patternRegex ); } @@ -142,8 +142,8 @@ private function replacePlaceholderWithPatternRegexes(string $patternRegex, arra { $regexConverter = new RegexConverter(); foreach ($patternsReplacedWithRegex as $index => $typePattern) { - $patternRegex = str_replace( - sprintf(self::PATTERN_REGEXP_PLACEHOLDER_TEMPLATE, $index), + $patternRegex = \str_replace( + \sprintf(self::PATTERN_REGEXP_PLACEHOLDER_TEMPLATE, $index), $regexConverter->toRegex($typePattern), $patternRegex ); @@ -160,6 +160,6 @@ private function replacePlaceholderWithPatternRegexes(string $patternRegex, arra */ private function prepareRegex(string $patternRegex) : string { - return '/^' . preg_quote($patternRegex, '/') . '$/'; + return '/^' . \preg_quote($patternRegex, '/') . '$/'; } } diff --git a/src/Matcher/UuidMatcher.php b/src/Matcher/UuidMatcher.php index 1fc2097b..fdbf082f 100644 --- a/src/Matcher/UuidMatcher.php +++ b/src/Matcher/UuidMatcher.php @@ -21,19 +21,19 @@ public function __construct(Parser $parser) public function match($value, $pattern) : bool { - if (!is_string($value)) { - $this->error = sprintf( + if (!\is_string($value)) { + $this->error = \sprintf( '%s "%s" is not a valid UUID: not a string.', - gettype($value), + \gettype($value), new StringConverter($value) ); return false; } - if (1 !== preg_match(self::UUID_FORMAT_PATTERN, $value)) { - $this->error = sprintf( + if (1 !== \preg_match(self::UUID_FORMAT_PATTERN, $value)) { + $this->error = \sprintf( '%s "%s" is not a valid UUID: invalid format.', - gettype($value), + \gettype($value), $value ); return false; @@ -44,7 +44,7 @@ public function match($value, $pattern) : bool public function canMatch($pattern) : bool { - if (!is_string($pattern)) { + if (!\is_string($pattern)) { return false; } diff --git a/src/Matcher/WildcardMatcher.php b/src/Matcher/WildcardMatcher.php index e1d40f88..9582a70d 100644 --- a/src/Matcher/WildcardMatcher.php +++ b/src/Matcher/WildcardMatcher.php @@ -15,6 +15,6 @@ public function match($matcher, $pattern) : bool public function canMatch($pattern) : bool { - return is_string($pattern) && 0 !== preg_match(self::MATCH_PATTERN, $pattern); + return \is_string($pattern) && 0 !== \preg_match(self::MATCH_PATTERN, $pattern); } } diff --git a/src/Parser.php b/src/Parser.php index 0480c384..0aad6367 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -248,9 +248,9 @@ private function isNextCloseParenthesis() : bool private function unexpectedSyntaxError(array $unexpectedToken, string $expected = null) { $tokenPos = (isset($unexpectedToken['position'])) ? $unexpectedToken['position'] : '-1'; - $message = sprintf('line 0, col %d: Error: ', $tokenPos); - $message .= (isset($expected)) ? sprintf('Expected "%s", got ', $expected) : 'Unexpected'; - $message .= sprintf('"%s"', $unexpectedToken['value']); + $message = \sprintf('line 0, col %d: Error: ', $tokenPos); + $message .= (isset($expected)) ? \sprintf('Expected "%s", got ', $expected) : 'Unexpected'; + $message .= \sprintf('"%s"', $unexpectedToken['value']); throw PatternException::syntaxError($message); } @@ -261,9 +261,9 @@ private function unexpectedSyntaxError(array $unexpectedToken, string $expected */ private function unexpectedEndOfString(string $expected = null) { - $tokenPos = (isset($this->lexer->token['position'])) ? $this->lexer->token['position'] + strlen((string) $this->lexer->token['value']) : '-1'; - $message = sprintf('line 0, col %d: Error: ', $tokenPos); - $message .= (isset($expected)) ? sprintf('Expected "%s", got end of string.', $expected) : 'Unexpected'; + $tokenPos = (isset($this->lexer->token['position'])) ? $this->lexer->token['position'] + \strlen((string) $this->lexer->token['value']) : '-1'; + $message = \sprintf('line 0, col %d: Error: ', $tokenPos); + $message .= (isset($expected)) ? \sprintf('Expected "%s", got end of string.', $expected) : 'Unexpected'; $message .= 'end of string'; throw PatternException::syntaxError($message); @@ -271,6 +271,6 @@ private function unexpectedEndOfString(string $expected = null) private function endOfPattern() : bool { - return is_null($this->lexer->lookahead); + return \is_null($this->lexer->lookahead); } } diff --git a/src/Parser/ExpanderInitializer.php b/src/Parser/ExpanderInitializer.php index 84f49ad0..fdad3aba 100644 --- a/src/Parser/ExpanderInitializer.php +++ b/src/Parser/ExpanderInitializer.php @@ -35,8 +35,8 @@ final class ExpanderInitializer public function setExpanderDefinition(string $expanderName, string $expanderFQCN) { - if (!class_exists($expanderFQCN)) { - throw new UnknownExpanderClassException(sprintf('Class "%s" does not exists.', $expanderFQCN)); + if (!\class_exists($expanderFQCN)) { + throw new UnknownExpanderClassException(\sprintf('Class "%s" does not exists.', $expanderFQCN)); } $this->expanderDefinitions[$expanderName] = $expanderFQCN; @@ -44,13 +44,13 @@ public function setExpanderDefinition(string $expanderName, string $expanderFQCN public function hasExpanderDefinition(string $expanderName) : bool { - return array_key_exists($expanderName, $this->expanderDefinitions); + return \array_key_exists($expanderName, $this->expanderDefinitions); } public function getExpanderDefinition(string $expanderName) : string { if (!$this->hasExpanderDefinition($expanderName)) { - throw new InvalidArgumentException(sprintf('Definition for "%s" expander does not exists.', $expanderName)); + throw new InvalidArgumentException(\sprintf('Definition for "%s" expander does not exists.', $expanderName)); } return $this->expanderDefinitions[$expanderName]; @@ -58,8 +58,8 @@ public function getExpanderDefinition(string $expanderName) : string public function initialize(ExpanderNode $expanderNode) : PatternExpander { - if (!array_key_exists($expanderNode->getName(), $this->expanderDefinitions)) { - throw new UnknownExpanderException(sprintf('Unknown expander "%s"', $expanderNode->getName())); + if (!\array_key_exists($expanderNode->getName(), $this->expanderDefinitions)) { + throw new UnknownExpanderException(\sprintf('Unknown expander "%s"', $expanderNode->getName())); } $reflection = new \ReflectionClass($this->expanderDefinitions[$expanderNode->getName()]); diff --git a/tests/LexerTest.php b/tests/LexerTest.php index 17239ae4..3fca10d5 100644 --- a/tests/LexerTest.php +++ b/tests/LexerTest.php @@ -18,7 +18,7 @@ public function test_string_values(string $value) $lexer->setInput($value); $lexer->moveNext(); $this->assertEquals($lexer->lookahead['type'], Lexer::T_STRING); - $this->assertEquals($lexer->lookahead['value'], trim(trim($value, "'"), '"')); + $this->assertEquals($lexer->lookahead['value'], \trim(\trim($value, "'"), '"')); } public static function validStringValuesProvider() @@ -170,7 +170,7 @@ public function test_type_pattern($value) $lexer->setInput($value); $lexer->moveNext(); $this->assertEquals($lexer->lookahead['type'], Lexer::T_TYPE_PATTERN); - $this->assertEquals($lexer->lookahead['value'], trim($value, '@')); + $this->assertEquals($lexer->lookahead['value'], \trim($value, '@')); } public static function validMatcherTypePatterns() diff --git a/tests/Matcher/JsonMatcherTest.php b/tests/Matcher/JsonMatcherTest.php index e7397ebe..1c3031c5 100644 --- a/tests/Matcher/JsonMatcherTest.php +++ b/tests/Matcher/JsonMatcherTest.php @@ -79,13 +79,13 @@ public function test_negative_matches($value, $pattern) public function test_error_when_matching_fail() { - $value = json_encode([ + $value = \json_encode([ 'users' => [ ['name' => 'Norbert'], ['name' => 'Michał'] ] ]); - $pattern = json_encode([ + $pattern = \json_encode([ 'users' => [ ['name' => '@string@'], ['name' => '@boolean@'] @@ -98,8 +98,8 @@ public function test_error_when_matching_fail() public function test_error_when_path_in_nested_pattern_does_not_exist() { - $value = json_encode(['foo' => ['bar' => ['baz' => 'bar value']]]); - $pattern = json_encode(['foo' => ['bar' => ['faz' => 'faz value']]]); + $value = \json_encode(['foo' => ['bar' => ['baz' => 'bar value']]]); + $pattern = \json_encode(['foo' => ['bar' => ['faz' => 'faz value']]]); $this->assertFalse($this->matcher->match($value, $pattern)); @@ -108,8 +108,8 @@ public function test_error_when_path_in_nested_pattern_does_not_exist() public function test_error_when_path_in_nested_value_does_not_exist() { - $value = json_encode(['foo' => ['bar' => []]]); - $pattern = json_encode(['foo' => ['bar' => ['faz' => 'faz value']]]); + $value = \json_encode(['foo' => ['bar' => []]]); + $pattern = \json_encode(['foo' => ['bar' => ['faz' => 'faz value']]]); $this->assertFalse($this->matcher->match($value, $pattern)); @@ -139,9 +139,9 @@ public function test_error_when_json_value_is_invalid() public static function positivePatterns() { return [ - [json_encode(['Norbert', 'Michał'])], - [json_encode(['Norbert', '@string@'])], - [json_encode('test')], + [\json_encode(['Norbert', 'Michał'])], + [\json_encode(['Norbert', '@string@'])], + [\json_encode('test')], ]; } diff --git a/tests/Matcher/TextMatcherTest.php b/tests/Matcher/TextMatcherTest.php index 7318ec9b..ff2c62ba 100644 --- a/tests/Matcher/TextMatcherTest.php +++ b/tests/Matcher/TextMatcherTest.php @@ -50,7 +50,7 @@ public function test_positive_matches($value, $pattern, $expectedResult) public function test_ignore_valid_json_patterns() { - $jsonPattern = json_encode([ + $jsonPattern = \json_encode([ 'users' => [ ['id' => '@number@', 'name' => 'Norbert'], ['id' => '@number@', 'name' => 'Michal'] diff --git a/tests/PHPUnit/PHPMatcherAssertionsTest.php b/tests/PHPUnit/PHPMatcherAssertionsTest.php index 1d1de85a..9c629ab5 100644 --- a/tests/PHPUnit/PHPMatcherAssertionsTest.php +++ b/tests/PHPUnit/PHPMatcherAssertionsTest.php @@ -22,7 +22,7 @@ public function test_it_asserts_if_a_value_matches_the_pattern() */ public function test_it_throws_an_expectation_failed_exception_if_a_value_does_not_match_the_pattern() { - $this->assertMatchesPattern('{"foo": "@integer@"}', json_encode(['foo' => 'bar'])); + $this->assertMatchesPattern('{"foo": "@integer@"}', \json_encode(['foo' => 'bar'])); } /** diff --git a/tests/PHPUnit/PHPMatcherTestCaseTest.php b/tests/PHPUnit/PHPMatcherTestCaseTest.php index 4f6a2dae..5a34cf6b 100644 --- a/tests/PHPUnit/PHPMatcherTestCaseTest.php +++ b/tests/PHPUnit/PHPMatcherTestCaseTest.php @@ -19,7 +19,7 @@ public function test_it_asserts_if_a_value_matches_the_pattern() */ public function test_it_throws_an_expectation_failed_exception_if_a_value_does_not_match_the_pattern() { - $this->assertMatchesPattern('{"foo": "@integer@"}', json_encode(['foo' => 'bar'])); + $this->assertMatchesPattern('{"foo": "@integer@"}', \json_encode(['foo' => 'bar'])); } /**