Skip to content

Commit c3df089

Browse files
authored
Update Preg::match (#911)
1 parent 2d47fb9 commit c3df089

15 files changed

+27
-27
lines changed

src/Fixer/CommentedOutFunctionFixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private function canUseSingleLineComment(Tokens $tokens, int $startIndex, int $e
182182
return true;
183183
}
184184

185-
if (Preg::match('/^\R/', $tokens[$endIndex + 1]->getContent()) === 1) {
185+
if (Preg::match('/^\R/', $tokens[$endIndex + 1]->getContent())) {
186186
return true;
187187
}
188188

@@ -207,7 +207,7 @@ private function fixBlockWithSingleLineComments(Tokens $tokens, int $startIndex,
207207
$codeToCommentOut = $prefix . \str_replace("\n", "\n//", $codeToCommentOut);
208208

209209
if ($tokens->offsetExists($endIndex + 1)) {
210-
if (Preg::match('/^\R/', $tokens[$endIndex + 1]->getContent()) === 0) {
210+
if (!Preg::match('/^\R/', $tokens[$endIndex + 1]->getContent())) {
211211
$codeToCommentOut .= "\n";
212212
if ($tokens[$endIndex + 1]->isWhitespace()) {
213213
$endIndex++;

src/Fixer/MultilineCommentOpeningClosingAloneFixer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
5454
continue;
5555
}
5656

57-
if (Preg::match('/\R/', $tokens[$index]->getContent()) !== 1) {
57+
if (!Preg::match('/\R/', $tokens[$index]->getContent())) {
5858
continue;
5959
}
6060

@@ -65,7 +65,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
6565

6666
private function fixOpening(Tokens $tokens, int $index): void
6767
{
68-
if (Preg::match('#^/\*+\R#', $tokens[$index]->getContent()) === 1) {
68+
if (Preg::match('#^/\*+\R#', $tokens[$index]->getContent())) {
6969
return;
7070
}
7171

@@ -93,7 +93,7 @@ private function fixOpening(Tokens $tokens, int $index): void
9393
$indent .= ' ';
9494
}
9595

96-
if (Preg::match('#^\h+$#', $beforeNewline) === 1) {
96+
if (Preg::match('#^\h+$#', $beforeNewline)) {
9797
$insert = '';
9898
} else {
9999
$insert = $newline . $indent . $beforeNewline;
@@ -102,13 +102,13 @@ private function fixOpening(Tokens $tokens, int $index): void
102102
$newContent = $opening . $insert . $newline . $afterNewline;
103103

104104
if ($newContent !== $tokens[$index]->getContent()) {
105-
$tokens[$index] = new Token([Preg::match('~/\*{2}\s~', $newContent) === 1 ? \T_DOC_COMMENT : \T_COMMENT, $newContent]);
105+
$tokens[$index] = new Token([Preg::match('~/\*{2}\s~', $newContent) ? \T_DOC_COMMENT : \T_COMMENT, $newContent]);
106106
}
107107
}
108108

109109
private function fixClosing(Tokens $tokens, int $index): void
110110
{
111-
if (Preg::match('#\R\h*\*+/$#', $tokens[$index]->getContent()) === 1) {
111+
if (Preg::match('#\R\h*\*+/$#', $tokens[$index]->getContent())) {
112112
return;
113113
}
114114

src/Fixer/NoDuplicatedArrayKeyFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private function fixArray(Tokens $tokens, int $index): void
108108
$endIndex = $tokens->getNextMeaningfulToken($arrayElementAnalysis->getValueEndIndex());
109109
\assert(\is_int($endIndex));
110110

111-
if ($tokens[$endIndex + 1]->isWhitespace() && Preg::match('/^\h+$/', $tokens[$endIndex + 1]->getContent()) === 1) {
111+
if ($tokens[$endIndex + 1]->isWhitespace() && Preg::match('/^\h+$/', $tokens[$endIndex + 1]->getContent())) {
112112
$endIndex++;
113113
}
114114

src/Fixer/NoPhpStormGeneratedCommentFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
5959
continue;
6060
}
6161

62-
if (Preg::match('/\*\h+Created by PhpStorm/i', $tokens[$index]->getContent(), $matches) !== 1) {
62+
if (!Preg::match('/\*\h+Created by PhpStorm/i', $tokens[$index]->getContent(), $matches)) {
6363
continue;
6464
}
6565

src/Fixer/NoSuperfluousConcatenationFixer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private function areOnlyHorizontalWhitespacesBetween(Tokens $tokens, int $indexS
111111
if (!$tokens[$index]->isGivenKind(\T_WHITESPACE)) {
112112
return false;
113113
}
114-
if (Preg::match('/\R/', $tokens[$index]->getContent()) === 1) {
114+
if (Preg::match('/\R/', $tokens[$index]->getContent())) {
115115
return false;
116116
}
117117
}
@@ -127,8 +127,8 @@ private function fixConcat(Tokens $tokens, int $firstIndex, int $secondIndex): v
127127

128128
if (
129129
$this->allowPreventingTrailingSpaces
130-
&& Preg::match('/\h(\\\'|")$/', $firstContent) === 1
131-
&& Preg::match('/^(\\\'|")\R/', $secondContent) === 1
130+
&& Preg::match('/\h(\\\'|")$/', $firstContent)
131+
&& Preg::match('/^(\\\'|")\R/', $secondContent)
132132
) {
133133
return;
134134
}

src/Fixer/NumericLiteralSeparatorFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private function getNewContent(string $content): string
147147
return $this->updateContent($content, 'x', null, 2, $this->hexadecimalSeparator);
148148
}
149149

150-
if (Preg::match('/e-?[\d_]+$/i', $content) === 1) {
150+
if (Preg::match('/e-?[\d_]+$/i', $content)) {
151151
$content = $this->updateContent($content, null, 'e', 3, $this->floatSeparator);
152152

153153
return $this->updateContent($content, 'e', null, 3, $this->floatSeparator);

src/Fixer/PhpdocNoIncorrectVarAnnotationFixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private function removeForClassElement(Tokens $tokens, int $index, int $property
107107
return;
108108
}
109109

110-
if (Preg::match('/@var\h+(.+\h+)?\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $tokens[$index]->getContent()) === 1) {
110+
if (Preg::match('/@var\h+(.+\h+)?\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $tokens[$index]->getContent())) {
111111
$this->removeVarAnnotation($tokens, $index, [$tokens[$variableIndex]->getContent()]);
112112
}
113113
}
@@ -149,7 +149,7 @@ private function removeVarAnnotationNotMatchingPattern(Tokens $tokens, int $inde
149149
$doc = new DocBlock($tokens[$index]->getContent());
150150

151151
foreach ($doc->getAnnotationsOfType(['var']) as $annotation) {
152-
if ($pattern === null || Preg::match($pattern, $annotation->getContent()) !== 1) {
152+
if ($pattern === null || !Preg::match($pattern, $annotation->getContent())) {
153153
$annotation->remove();
154154
}
155155
}

src/Fixer/PhpdocNoSuperfluousParamFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private function getFilteredDocComment(string $comment, array $paramNames): stri
121121

122122
$foundParamNames = [];
123123
foreach ($doc->getAnnotationsOfType('param') as $annotation) {
124-
if (Preg::match(\sprintf('/@param\s+(?:[^\$](?:[^<.]|<[^>]*>)*\s*)?(?:&|\.\.\.)?\s*(?=\$)%s\b/', $regexParamNamesPattern), $annotation->getContent(), $matches) === 1 && !\in_array($matches[1], $foundParamNames, true)) {
124+
if (Preg::match(\sprintf('/@param\s+(?:[^\$](?:[^<.]|<[^>]*>)*\s*)?(?:&|\.\.\.)?\s*(?=\$)%s\b/', $regexParamNamesPattern), $annotation->getContent(), $matches) && !\in_array($matches[1], $foundParamNames, true)) {
125125
$foundParamNames[] = $matches[1];
126126
continue;
127127
}

src/Fixer/PhpdocOnlyAllowedAnnotationsFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
9898

9999
foreach ($docBlock->getAnnotations() as $annotation) {
100100
if (
101-
Preg::match('/@([a-zA-Z0-9_\\-\\\\]+)/', $annotation->getContent(), $matches) === 1
101+
Preg::match('/@([a-zA-Z0-9_\\-\\\\]+)/', $annotation->getContent(), $matches)
102102
&& \in_array($matches[1], $this->elements, true)
103103
) {
104104
continue;

src/Fixer/PhpdocSingleLineVarFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
6161
continue;
6262
}
6363

64-
if (Preg::match('#^/\*\*[\s\*]+(@var[^\r\n]+)[\s\*]*\*\/$#u', $tokens[$index]->getContent(), $matches) !== 1) {
64+
if (!Preg::match('#^/\*\*[\s\*]+(@var[^\r\n]+)[\s\*]*\*\/$#u', $tokens[$index]->getContent(), $matches)) {
6565
continue;
6666
}
6767

0 commit comments

Comments
 (0)