Skip to content

Commit

Permalink
Add non-preg related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Mar 9, 2024
1 parent fdfd837 commit 3790f78
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 32 deletions.
25 changes: 0 additions & 25 deletions dev-tools/phpstan/baseline.php
Expand Up @@ -81,21 +81,11 @@
'count' => 1,
'path' => __DIR__ . '/../../src/Fixer/ListNotation/ListSyntaxFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, int\\|null given\\.$#',
'count' => 1,
'path' => __DIR__ . '/../../src/Fixer/Naming/NoHomoglyphNamesFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Variable method call on \\$this\\(PhpCsFixer\\\\Fixer\\\\Operator\\\\ConcatSpaceFixer\\)\\.$#',
'count' => 1,
'path' => __DIR__ . '/../../src/Fixer/Operator/ConcatSpaceFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a negated boolean, int\\|null given\\.$#',
'count' => 1,
'path' => __DIR__ . '/../../src/Fixer/PhpTag/FullOpeningTagFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Variable method call on \\$this\\(PhpCsFixer\\\\Fixer\\\\PhpUnit\\\\PhpUnitConstructFixer\\)\\.$#',
'count' => 1,
Expand All @@ -106,11 +96,6 @@
'count' => 1,
'path' => __DIR__ . '/../../src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, int\\|null given\\.$#',
'count' => 1,
'path' => __DIR__ . '/../../src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Argument of an invalid type string supplied for foreach, only iterables are supported\\.$#',
'count' => 1,
Expand All @@ -126,16 +111,6 @@
'count' => 1,
'path' => __DIR__ . '/../../src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a negated boolean, string given\\.$#',
'count' => 2,
'path' => __DIR__ . '/../../src/Fixer/Whitespace/HeredocIndentationFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an elseif condition, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/../../src/Fixer/Whitespace/HeredocIndentationFixer.php',
];
$ignoreErrors[] = [
'message' => '#^Variable \\$end might not be defined\\.$#',
'count' => 2,
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Naming/NoHomoglyphNamesFixer.php
Expand Up @@ -222,7 +222,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void

$replaced = Preg::replaceCallback('/[^[:ascii:]]/u', static fn (array $matches): string => self::$replacements[$matches[0]] ?? $matches[0], $token->getContent(), -1, $count);

if ($count) {
if ($count > 0) {
$tokens->offsetSet($index, new Token([$token->getId(), $replaced]));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/PhpTag/FullOpeningTagFixer.php
Expand Up @@ -62,7 +62,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
// replace all <? with <?php to replace all short open tags even without short_open_tag option enabled
$newContent = Preg::replace('/<\?(?:phP|pHp|pHP|Php|PhP|PHp|PHP)?(\s|$)/', '<?php$1', $content, -1, $count);

if (!$count) {
if (0 === $count) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php
Expand Up @@ -121,7 +121,7 @@ private function fixToken(Tokens $tokens, int $tokenIndex): void
$count
);

if ($count) {
if ($count > 0) {
$tokens[$tokenIndex] = new Token([T_DOC_COMMENT, $content]);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Fixer/Whitespace/HeredocIndentationFixer.php
Expand Up @@ -140,7 +140,7 @@ private function fixIndentation(Tokens $tokens, int $start, int $end): void
$content = Preg::replace('/(?<=\v)(?!'.$currentIndent.')\h+/', '', $content);
}

$regexEnd = $last && !$currentIndent ? '(?!\v|$)' : '(?!\v)';
$regexEnd = $last && '' === $currentIndent ? '(?!\v|$)' : '(?!\v)';
$content = Preg::replace('/(?<=\v)'.$currentIndent.$regexEnd.'/', $indent, $content);

$tokens[$index] = new Token([$tokens[$index]->getId(), $content]);
Expand All @@ -156,9 +156,9 @@ private function fixIndentation(Tokens $tokens, int $start, int $end): void

$content = $tokens[$index]->getContent();

if (!\in_array($content[0], ["\r", "\n"], true) && (!$currentIndent || str_starts_with($content, $currentIndent))) {
if (!\in_array($content[0], ["\r", "\n"], true) && ('' === $currentIndent || str_starts_with($content, $currentIndent))) {
$content = $indent.substr($content, $currentIndentLength);
} elseif ($currentIndent) {
} elseif ('' !== $currentIndent) {
$content = Preg::replace('/^(?!'.$currentIndent.')\h+/', '', $content);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/AutoReview/ProjectCodeTest.php
Expand Up @@ -305,7 +305,7 @@ public function testThatTestClassCoversAreCorrect(string $testClassName): void
$doc = $reflectionClass->getDocComment();
self::assertNotFalse($doc);

if (Preg::match('/@coversNothing/', $doc, $matches)) {
if (Preg::match('/@coversNothing/', $doc)) {
return;
}

Expand Down

0 comments on commit 3790f78

Please sign in to comment.