Skip to content

Commit df73c82

Browse files
committed
Added backslash before native functions
1 parent fb88c73 commit df73c82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+191
-190
lines changed

.php_cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ return PhpCsFixer\Config::create()
77
'blank_line_after_opening_tag' => true,
88
'single_blank_line_before_namespace' => true,
99
'no_unused_imports' => true,
10-
'single_quote' => true
10+
'single_quote' => true,
11+
'native_function_invocation' => true
1112
])
1213
->setFinder(
1314
PhpCsFixer\Finder::create()

src/AST/Expander.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function addArgument($argument)
2828

2929
public function hasArguments() : bool
3030
{
31-
return (boolean) count($this->arguments);
31+
return (boolean) \count($this->arguments);
3232
}
3333

3434
public function getArguments() : array

src/AST/Pattern.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function getType() : Type
2323

2424
public function hasExpanders() : bool
2525
{
26-
return (boolean) count($this->expanders);
26+
return (boolean) \count($this->expanders);
2727
}
2828

2929
/**

src/Exception/UnknownTypeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class UnknownTypeException extends Exception
1111
public function __construct(string $type)
1212
{
1313
$this->type = '@' . $type . '@';
14-
parent::__construct(sprintf('Type pattern "%s" is not supported.', $this->type), 0, null);
14+
parent::__construct(\sprintf('Type pattern "%s" is not supported.', $this->type), 0, null);
1515
}
1616

1717
public function getType() : string

src/Lexer.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected function getType(&$value) : int
7070
}
7171

7272
if ($this->isTypePatternToken($value)) {
73-
$value = trim($value, '@');
73+
$value = \trim($value, '@');
7474
return self::T_TYPE_PATTERN;
7575
}
7676

@@ -80,7 +80,7 @@ protected function getType(&$value) : int
8080
}
8181

8282
if ($this->isBooleanToken($value)) {
83-
$value = (strtolower($value) === 'true') ? true : false;
83+
$value = (\strtolower($value) === 'true') ? true : false;
8484
return self::T_BOOLEAN;
8585
}
8686

@@ -89,16 +89,16 @@ protected function getType(&$value) : int
8989
return self::T_NULL;
9090
}
9191

92-
if (is_numeric($value)) {
93-
if (is_string($value)) {
94-
$value = (strpos($value, '.') === false) ? (int) $value : (float) $value;
92+
if (\is_numeric($value)) {
93+
if (\is_string($value)) {
94+
$value = (\strpos($value, '.') === false) ? (int) $value : (float) $value;
9595
}
9696

9797
return self::T_NUMBER;
9898
}
9999

100100
if ($this->isExpanderNameToken($value)) {
101-
$value = rtrim(ltrim($value, '.'), '(');
101+
$value = \rtrim(\ltrim($value, '.'), '(');
102102
return self::T_EXPANDER_NAME;
103103
}
104104

@@ -107,31 +107,31 @@ protected function getType(&$value) : int
107107

108108
protected function isStringToken(string $value) : bool
109109
{
110-
return in_array(substr($value, 0, 1), ['"', "'"]);
110+
return \in_array(\substr($value, 0, 1), ['"', "'"]);
111111
}
112112

113113
protected function isBooleanToken(string $value) : bool
114114
{
115-
return in_array(strtolower($value), ['true', 'false'], true);
115+
return \in_array(\strtolower($value), ['true', 'false'], true);
116116
}
117117

118118
protected function isNullToken(string $value) : bool
119119
{
120-
return strtolower($value) === 'null';
120+
return \strtolower($value) === 'null';
121121
}
122122

123123
protected function extractStringValue(string $value) : string
124124
{
125-
return trim(trim($value, "'"), '"');
125+
return \trim(\trim($value, "'"), '"');
126126
}
127127

128128
protected function isExpanderNameToken(string $value) : bool
129129
{
130-
return substr($value, -1) === '(' && strlen($value) > 1;
130+
return \substr($value, -1) === '(' && \strlen($value) > 1;
131131
}
132132

133133
protected function isTypePatternToken(string $value) : bool
134134
{
135-
return substr($value, 0, 1) === '@' && substr($value, strlen($value) - 1, 1) === '@' && strlen($value) > 1;
135+
return \substr($value, 0, 1) === '@' && \substr($value, \strlen($value) - 1, 1) === '@' && \strlen($value) > 1;
136136
}
137137
}

src/Matcher/ArrayMatcher.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public function match($value, $pattern) : bool
3434
return true;
3535
}
3636

37-
if (!is_array($value)) {
38-
$this->error = sprintf('%s "%s" is not a valid array.', gettype($value), new StringConverter($value));
37+
if (!\is_array($value)) {
38+
$this->error = \sprintf('%s "%s" is not a valid array.', \gettype($value), new StringConverter($value));
3939
return false;
4040
}
4141

@@ -52,12 +52,12 @@ public function match($value, $pattern) : bool
5252

5353
public function canMatch($pattern) : bool
5454
{
55-
return is_array($pattern) || $this->isArrayPattern($pattern);
55+
return \is_array($pattern) || $this->isArrayPattern($pattern);
5656
}
5757

5858
private function isArrayPattern($pattern) : bool
5959
{
60-
if (!is_string($pattern)) {
60+
if (!\is_string($pattern)) {
6161
return false;
6262
}
6363

@@ -89,7 +89,7 @@ private function iterateMatch(array $values, array $patterns, string $parentPath
8989
continue;
9090
}
9191

92-
if (!is_array($value) || !$this->canMatch($pattern)) {
92+
if (!\is_array($value) || !$this->canMatch($pattern)) {
9393
return false;
9494
}
9595

@@ -115,19 +115,19 @@ private function iterateMatch(array $values, array $patterns, string $parentPath
115115

116116
private function isPatternValid(array $pattern, array $values, string $parentPath) : bool
117117
{
118-
if (is_array($pattern)) {
118+
if (\is_array($pattern)) {
119119
$skipPattern = static::UNBOUNDED_PATTERN;
120120

121-
$pattern = array_filter(
121+
$pattern = \array_filter(
122122
$pattern,
123123
function ($item) use ($skipPattern) {
124124
return $item !== $skipPattern;
125125
}
126126
);
127127

128128
$notExistingKeys = $this->findNotExistingKeys($pattern, $values);
129-
if (count($notExistingKeys) > 0) {
130-
$keyNames = array_keys($notExistingKeys);
129+
if (\count($notExistingKeys) > 0) {
130+
$keyNames = \array_keys($notExistingKeys);
131131
$path = $this->formatFullPath($parentPath, $this->formatAccessPath($keyNames[0]));
132132
$this->setMissingElementInError('value', $path);
133133

@@ -140,10 +140,10 @@ function ($item) use ($skipPattern) {
140140

141141
private function findNotExistingKeys(array $pattern, array $values) : array
142142
{
143-
$notExistingKeys = array_diff_key($pattern, $values);
143+
$notExistingKeys = \array_diff_key($pattern, $values);
144144

145-
return array_filter($notExistingKeys, function ($pattern) use ($values) {
146-
if (is_array($pattern)) {
145+
return \array_filter($notExistingKeys, function ($pattern) use ($values) {
146+
if (\is_array($pattern)) {
147147
return !$this->match($values, $pattern);
148148
}
149149

@@ -195,7 +195,7 @@ private function valueExist(string $path, array $haystack) : bool
195195
private function arrayPropertyExists(string $property, array $objectOrArray) : bool
196196
{
197197
return ($objectOrArray instanceof \ArrayAccess && isset($objectOrArray[$property])) ||
198-
(is_array($objectOrArray) && array_key_exists($property, $objectOrArray));
198+
(\is_array($objectOrArray) && \array_key_exists($property, $objectOrArray));
199199
}
200200

201201
private function getValueByPath(array $array, string $path)
@@ -217,17 +217,17 @@ private function getPropertyAccessor() : PropertyAccessorInterface
217217

218218
private function setMissingElementInError(string $place, string $path)
219219
{
220-
$this->error = sprintf('There is no element under path %s in %s.', $path, $place);
220+
$this->error = \sprintf('There is no element under path %s in %s.', $path, $place);
221221
}
222222

223223
private function formatAccessPath($key) : string
224224
{
225-
return sprintf('[%s]', $key);
225+
return \sprintf('[%s]', $key);
226226
}
227227

228228
private function formatFullPath(string $parentPath, string $path) : string
229229
{
230-
return sprintf('%s%s', $parentPath, $path);
230+
return \sprintf('%s%s', $parentPath, $path);
231231
}
232232

233233
private function shouldSkippValueMatchingFor($lastPattern) : bool

src/Matcher/BooleanMatcher.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public function __construct(Parser $parser)
2020

2121
public function match($value, $pattern) : bool
2222
{
23-
if (!is_bool($value)) {
24-
$this->error = sprintf('%s "%s" is not a valid boolean.', gettype($value), new StringConverter($value));
23+
if (!\is_bool($value)) {
24+
$this->error = \sprintf('%s "%s" is not a valid boolean.', \gettype($value), new StringConverter($value));
2525
return false;
2626
}
2727

@@ -30,7 +30,7 @@ public function match($value, $pattern) : bool
3030

3131
public function canMatch($pattern) : bool
3232
{
33-
if (!is_string($pattern)) {
33+
if (!\is_string($pattern)) {
3434
return false;
3535
}
3636

src/Matcher/CallbackMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public function match($value, $pattern) : bool
1313

1414
public function canMatch($pattern) : bool
1515
{
16-
return is_object($pattern) && is_callable($pattern);
16+
return \is_object($pattern) && \is_callable($pattern);
1717
}
1818
}

src/Matcher/ChainMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function match($value, $pattern) : bool
3939
}
4040

4141
if (!isset($this->error)) {
42-
$this->error = sprintf(
42+
$this->error = \sprintf(
4343
'Any matcher from chain can\'t match value "%s" to pattern "%s"',
4444
new StringConverter($value),
4545
new StringConverter($pattern)

src/Matcher/DoubleMatcher.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public function __construct(Parser $parser)
2020

2121
public function match($value, $pattern) : bool
2222
{
23-
if (!is_double($value)) {
24-
$this->error = sprintf('%s "%s" is not a valid double.', gettype($value), new StringConverter($value));
23+
if (!\is_double($value)) {
24+
$this->error = \sprintf('%s "%s" is not a valid double.', \gettype($value), new StringConverter($value));
2525
return false;
2626
}
2727

@@ -36,7 +36,7 @@ public function match($value, $pattern) : bool
3636

3737
public function canMatch($pattern) : bool
3838
{
39-
if (!is_string($pattern)) {
39+
if (!\is_string($pattern)) {
4040
return false;
4141
}
4242

src/Matcher/ExpressionMatcher.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ final class ExpressionMatcher extends Matcher
1414
public function match($value, $pattern) : bool
1515
{
1616
$language = new ExpressionLanguage();
17-
preg_match(self::MATCH_PATTERN, $pattern, $matches);
17+
\preg_match(self::MATCH_PATTERN, $pattern, $matches);
1818
$expressionResult = $language->evaluate($matches[1], ['value' => $value]);
1919

2020
if (!$expressionResult) {
21-
$this->error = sprintf('"%s" expression fails for value "%s".', $pattern, new StringConverter($value));
21+
$this->error = \sprintf('"%s" expression fails for value "%s".', $pattern, new StringConverter($value));
2222
}
2323

2424
return (bool) $expressionResult;
2525
}
2626

2727
public function canMatch($pattern) : bool
2828
{
29-
return is_string($pattern) && 0 !== preg_match(self::MATCH_PATTERN, $pattern);
29+
return \is_string($pattern) && 0 !== \preg_match(self::MATCH_PATTERN, $pattern);
3030
}
3131
}

src/Matcher/IntegerMatcher.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public function __construct(Parser $parser)
2020

2121
public function match($value, $pattern) : bool
2222
{
23-
if (!is_integer($value)) {
24-
$this->error = sprintf('%s "%s" is not a valid integer.', gettype($value), new StringConverter($value));
23+
if (!\is_integer($value)) {
24+
$this->error = \sprintf('%s "%s" is not a valid integer.', \gettype($value), new StringConverter($value));
2525
return false;
2626
}
2727

@@ -36,7 +36,7 @@ public function match($value, $pattern) : bool
3636

3737
public function canMatch($pattern) : bool
3838
{
39-
if (!is_string($pattern)) {
39+
if (!\is_string($pattern)) {
4040
return false;
4141
}
4242

src/Matcher/JsonMatcher.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ public function match($value, $pattern) : bool
2222
}
2323

2424
if (!Json::isValid($value)) {
25-
$this->error = sprintf('Invalid given JSON of value. %s', $this->getErrorMessage());
25+
$this->error = \sprintf('Invalid given JSON of value. %s', $this->getErrorMessage());
2626
return false;
2727
}
2828

2929
if (!Json::isValidPattern($pattern)) {
30-
$this->error = sprintf('Invalid given JSON of pattern. %s', $this->getErrorMessage());
30+
$this->error = \sprintf('Invalid given JSON of pattern. %s', $this->getErrorMessage());
3131
return false;
3232
}
3333

3434
$transformedPattern = Json::transformPattern($pattern);
35-
$match = $this->matcher->match(json_decode($value, true), json_decode($transformedPattern, true));
35+
$match = $this->matcher->match(\json_decode($value, true), \json_decode($transformedPattern, true));
3636
if (!$match) {
3737
$this->error = $this->matcher->getError();
3838
return false;
@@ -48,7 +48,7 @@ public function canMatch($pattern) : bool
4848

4949
private function getErrorMessage()
5050
{
51-
switch (json_last_error()) {
51+
switch (\json_last_error()) {
5252
case JSON_ERROR_DEPTH:
5353
return 'Maximum stack depth exceeded';
5454
case JSON_ERROR_STATE_MISMATCH:

src/Matcher/NullMatcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class NullMatcher extends Matcher
1616
public function match($value, $pattern) : bool
1717
{
1818
if (null !== $value) {
19-
$this->error = sprintf('%s "%s" does not match null.', gettype($value), new StringConverter($value));
19+
$this->error = \sprintf('%s "%s" does not match null.', \gettype($value), new StringConverter($value));
2020
return false;
2121
}
2222

@@ -28,6 +28,6 @@ public function match($value, $pattern) : bool
2828
*/
2929
public function canMatch($pattern) : bool
3030
{
31-
return is_null($pattern) || (is_string($pattern) && 0 !== preg_match(self::MATCH_PATTERN, $pattern));
31+
return \is_null($pattern) || (\is_string($pattern) && 0 !== \preg_match(self::MATCH_PATTERN, $pattern));
3232
}
3333
}

src/Matcher/NumberMatcher.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public function __construct(Parser $parser)
2020

2121
public function match($value, $pattern) : bool
2222
{
23-
if (!is_numeric($value)) {
24-
$this->error = sprintf('%s "%s" is not a valid number.', gettype($value), new StringConverter($value));
23+
if (!\is_numeric($value)) {
24+
$this->error = \sprintf('%s "%s" is not a valid number.', \gettype($value), new StringConverter($value));
2525
return false;
2626
}
2727

@@ -30,7 +30,7 @@ public function match($value, $pattern) : bool
3030

3131
public function canMatch($pattern) : bool
3232
{
33-
if (!is_string($pattern)) {
33+
if (!\is_string($pattern)) {
3434
return false;
3535
}
3636

src/Matcher/OrMatcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(ChainMatcher $chainMatcher)
1717

1818
public function match($value, $pattern) : bool
1919
{
20-
$patterns = explode('||', $pattern);
20+
$patterns = \explode('||', $pattern);
2121
foreach ($patterns as $childPattern) {
2222
if ($this->matchChild($value, $childPattern)) {
2323
return true;
@@ -42,6 +42,6 @@ private function matchChild($value, $pattern) : bool
4242

4343
public function canMatch($pattern): bool
4444
{
45-
return is_string($pattern) && 0 !== preg_match_all(self::MATCH_PATTERN, $pattern, $matches);
45+
return \is_string($pattern) && 0 !== \preg_match_all(self::MATCH_PATTERN, $pattern, $matches);
4646
}
4747
}

0 commit comments

Comments
 (0)