Skip to content

Commit 2f2f4d9

Browse files
authored
Use Preg class instead of direct preg_ call
1 parent 2cc0c83 commit 2f2f4d9

18 files changed

+92
-22
lines changed

src/Fixer/AbstractFixer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
namespace PhpCsFixerCustomFixers\Fixer;
66

77
use PhpCsFixer\Fixer\DefinedFixerInterface;
8+
use PhpCsFixer\Preg;
89

910
abstract class AbstractFixer implements DefinedFixerInterface
1011
{
1112
final public static function name(): string
1213
{
13-
return 'PhpCsFixerCustomFixers/' . \preg_replace_callback(
14+
return 'PhpCsFixerCustomFixers/' . Preg::replaceCallback(
1415
'/(^|[a-z0-9])([A-Z])/',
1516
static function (array $matches): string {
1617
return \strtolower($matches[1] !== '' ? $matches[1] . '_' . $matches[2] : $matches[2]);
1718
},
18-
\preg_replace('/^.*\\\\([a-zA-Z0-1]+)Fixer$/', '$1', static::class)
19+
Preg::replace('/^.*\\\\([a-zA-Z0-1]+)Fixer$/', '$1', static::class)
1920
);
2021
}
2122

src/Fixer/NoImportFromGlobalNamespaceFixer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpCsFixer\FixerDefinition\CodeSample;
88
use PhpCsFixer\FixerDefinition\FixerDefinition;
9+
use PhpCsFixer\Preg;
910
use PhpCsFixer\Tokenizer\CT;
1011
use PhpCsFixer\Tokenizer\Token;
1112
use PhpCsFixer\Tokenizer\Tokens;
@@ -68,7 +69,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
6869
if ($token->isGivenKind(T_DOC_COMMENT)) {
6970
$content = $token->getContent();
7071
foreach ($imports as $import) {
71-
$content = \preg_replace(\sprintf('/\b(?<!\\\\)%s\b/', $import), '\\' . $import, $content);
72+
$content = Preg::replace(\sprintf('/\b(?<!\\\\)%s\b/', $import), '\\' . $import, $content);
7273
}
7374
if ($content !== $token->getContent()) {
7475
$tokens[$index] = new Token([T_DOC_COMMENT, $content]);

src/Fixer/NoPhpStormGeneratedCommentFixer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpCsFixer\FixerDefinition\CodeSample;
88
use PhpCsFixer\FixerDefinition\FixerDefinition;
9+
use PhpCsFixer\Preg;
910
use PhpCsFixer\Tokenizer\Tokens;
1011
use PhpCsFixerCustomFixers\TokenRemover;
1112

@@ -44,7 +45,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
4445
continue;
4546
}
4647

47-
if (\preg_match('/\*\h+Created by PhpStorm/i', $token->getContent(), $matches) !== 1) {
48+
if (Preg::match('/\*\h+Created by PhpStorm/i', $token->getContent(), $matches) !== 1) {
4849
continue;
4950
}
5051

src/Fixer/NoUnneededConcatenationFixer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpCsFixer\FixerDefinition\CodeSample;
88
use PhpCsFixer\FixerDefinition\FixerDefinition;
9+
use PhpCsFixer\Preg;
910
use PhpCsFixer\Tokenizer\Token;
1011
use PhpCsFixer\Tokenizer\Tokens;
1112

@@ -36,11 +37,11 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
3637
continue;
3738
}
3839

39-
if ($tokens[$index - 1]->isGivenKind(T_WHITESPACE) && \preg_match('/\R/u', $tokens[$index - 1]->getContent()) === 1) {
40+
if ($tokens[$index - 1]->isGivenKind(T_WHITESPACE) && Preg::match('/\R/', $tokens[$index - 1]->getContent()) === 1) {
4041
continue;
4142
}
4243

43-
if ($tokens[$index + 1]->isGivenKind(T_WHITESPACE) && \preg_match('/\R/u', $tokens[$index + 1]->getContent()) === 1) {
44+
if ($tokens[$index + 1]->isGivenKind(T_WHITESPACE) && Preg::match('/\R/', $tokens[$index + 1]->getContent()) === 1) {
4445
continue;
4546
}
4647

src/Fixer/NoUselessClassCommentFixer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpCsFixer\FixerDefinition\CodeSample;
88
use PhpCsFixer\FixerDefinition\FixerDefinition;
9+
use PhpCsFixer\Preg;
910
use PhpCsFixer\Tokenizer\Token;
1011
use PhpCsFixer\Tokenizer\Tokens;
1112

@@ -51,7 +52,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
5152
continue;
5253
}
5354

54-
$newContent = \preg_replace(
55+
$newContent = Preg::replace(
5556
'/(\*)?\h*Class\h+[A-Za-z0-1\\\\_]+\.?(\h*\R\h*|\h*$)/i',
5657
'',
5758
$token->getContent()

src/Fixer/NoUselessConstructorCommentFixer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpCsFixer\FixerDefinition\CodeSample;
88
use PhpCsFixer\FixerDefinition\FixerDefinition;
9+
use PhpCsFixer\Preg;
910
use PhpCsFixer\Tokenizer\Token;
1011
use PhpCsFixer\Tokenizer\Tokens;
1112

@@ -47,7 +48,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
4748
continue;
4849
}
4950

50-
$newContent = \preg_replace(
51+
$newContent = Preg::replace(
5152
'/(\*|\/\/)\h*(\h+[A-Za-z0-1\\\\_]+\h*)?\hconstructor\.?(\h*\R\h*\*|\h*$)/i',
5253
'$1',
5354
$token->getContent()

src/Fixer/OperatorLinebreakFixer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
1010
use PhpCsFixer\FixerDefinition\CodeSample;
1111
use PhpCsFixer\FixerDefinition\FixerDefinition;
12+
use PhpCsFixer\Preg;
1213
use PhpCsFixer\Tokenizer\Token;
1314
use PhpCsFixer\Tokenizer\Tokens;
1415

@@ -147,7 +148,7 @@ private function fixMoveToTheBeginning(Tokens $tokens): void
147148

148149
$nextIndex = $tokens->getNextMeaningfulToken($index);
149150
for ($i = $nextIndex - 1; $i > $index; $i--) {
150-
if ($tokens[$i]->isWhitespace() && \preg_match('/\R/u', $tokens[$i]->getContent()) === 1) {
151+
if ($tokens[$i]->isWhitespace() && Preg::match('/\R/', $tokens[$i]->getContent()) === 1) {
151152
$operator = clone $tokens[$index];
152153
$tokens->clearAt($index);
153154
if ($tokens[$index - 1]->isWhitespace()) {
@@ -172,7 +173,7 @@ private function fixMoveToTheEnd(Tokens $tokens): void
172173

173174
$prevIndex = $tokens->getPrevMeaningfulToken($index);
174175
for ($i = $prevIndex + 1; $i < $index; $i++) {
175-
if ($tokens[$i]->isWhitespace() && \preg_match('/\R/u', $tokens[$i]->getContent()) === 1) {
176+
if ($tokens[$i]->isWhitespace() && Preg::match('/\R/', $tokens[$i]->getContent()) === 1) {
176177
$operator = clone $tokens[$index];
177178
$tokens->clearAt($index);
178179
if ($tokens[$index + 1]->isWhitespace()) {

src/Fixer/PhpdocNoIncorrectVarAnnotationFixer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpCsFixer\DocBlock\DocBlock;
88
use PhpCsFixer\FixerDefinition\CodeSample;
99
use PhpCsFixer\FixerDefinition\FixerDefinition;
10+
use PhpCsFixer\Preg;
1011
use PhpCsFixer\Tokenizer\Token;
1112
use PhpCsFixer\Tokenizer\Tokens;
1213
use PhpCsFixerCustomFixers\TokenRemover;
@@ -120,7 +121,7 @@ private function removeVarAnnotationNotMatchingPattern(Tokens $tokens, int $inde
120121
$doc = new DocBlock($tokens[$index]->getContent());
121122

122123
foreach ($doc->getAnnotationsOfType(['var']) as $annotation) {
123-
if ($pattern === null || \preg_match($pattern, $annotation->getContent()) !== 1) {
124+
if ($pattern === null || Preg::match($pattern, $annotation->getContent()) !== 1) {
124125
$annotation->remove();
125126
}
126127
}

src/Fixer/PhpdocNoSuperfluousParamFixer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpCsFixer\DocBlock\DocBlock;
88
use PhpCsFixer\FixerDefinition\CodeSample;
99
use PhpCsFixer\FixerDefinition\FixerDefinition;
10+
use PhpCsFixer\Preg;
1011
use PhpCsFixer\Tokenizer\Token;
1112
use PhpCsFixer\Tokenizer\Tokens;
1213

@@ -99,7 +100,7 @@ private function getFilteredDocComment(string $comment, array $paramNames): stri
99100
return \preg_quote($paramName, '/');
100101
}, $paramNames));
101102

102-
if (\preg_match(\sprintf('/@param\s+(?:[^\$](?:[^<\s]|<[^>]*>)*\s+)?(?:&|\.\.\.)?\s*(%s)\b/u', $regexParamNamesPattern), $annotation->getContent(), $matches) === 1 && !isset($foundParamNames[$matches[1]])) {
103+
if (Preg::match(\sprintf('/@param\s+(?:[^\$](?:[^<\s]|<[^>]*>)*\s+)?(?:&|\.\.\.)?\s*(%s)\b/', $regexParamNamesPattern), $annotation->getContent(), $matches) === 1 && !isset($foundParamNames[$matches[1]])) {
103104
$foundParamNames[$matches[1]] = true;
104105
continue;
105106
}

src/Fixer/PhpdocParamOrderFixer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpCsFixer\DocBlock\DocBlock;
88
use PhpCsFixer\FixerDefinition\CodeSample;
99
use PhpCsFixer\FixerDefinition\FixerDefinition;
10+
use PhpCsFixer\Preg;
1011
use PhpCsFixer\Tokenizer\Token;
1112
use PhpCsFixer\Tokenizer\Tokens;
1213

@@ -104,7 +105,7 @@ private function getSortedDocComment(string $comment, array $paramNames): string
104105

105106
if ($annotation->getTag()->getName() === 'param') {
106107
foreach ($paramNames as $paramName) {
107-
if (\preg_match(\sprintf('/@param\s+(?:[^\$](?:[^<\s]|<[^>]*>)*\s+)?(?:&|\.\.\.)?\s*(%s)\b/u', \preg_quote($paramName, '/')), $annotation->getContent(), $matches) === 1 && !isset($paramsByName[$matches[1]])) {
108+
if (Preg::match(\sprintf('/@param\s+(?:[^\$](?:[^<\s]|<[^>]*>)*\s+)?(?:&|\.\.\.)?\s*(%s)\b/', \preg_quote($paramName, '/')), $annotation->getContent(), $matches) === 1 && !isset($paramsByName[$matches[1]])) {
108109
$paramsByName[$matches[1]] = $annotation->getContent();
109110
continue 2;
110111
}

0 commit comments

Comments
 (0)