Skip to content

Commit

Permalink
Added backslash before native functions
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech committed Feb 4, 2018
1 parent fb88c73 commit df73c82
Show file tree
Hide file tree
Showing 46 changed files with 191 additions and 190 deletions.
3 changes: 2 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/AST/Expander.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/AST/Pattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getType() : Type

public function hasExpanders() : bool
{
return (boolean) count($this->expanders);
return (boolean) \count($this->expanders);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/UnknownTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function getType(&$value) : int
}

if ($this->isTypePatternToken($value)) {
$value = trim($value, '@');
$value = \trim($value, '@');
return self::T_TYPE_PATTERN;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}
}
32 changes: 16 additions & 16 deletions src/Matcher/ArrayMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -115,19 +115,19 @@ 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;
}
);

$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);

Expand All @@ -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);
}

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Matcher/BooleanMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Matcher/CallbackMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/Matcher/ChainMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/Matcher/DoubleMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Matcher/ExpressionMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ 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;
}

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);
}
}
6 changes: 3 additions & 3 deletions src/Matcher/IntegerMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Matcher/JsonMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/Matcher/NullMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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));
}
}
6 changes: 3 additions & 3 deletions src/Matcher/NumberMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Matcher/OrMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Loading

0 comments on commit df73c82

Please sign in to comment.