feat: Add stripos to modernize_strpos rule #9691
Annotations
10 warnings
PHP 8.3 mutation tests:
src/Fixer/Alias/ModernizeStrposFixer.php#L97
Escaped Mutant for Mutator "ArrayItemRemoval":
--- Original
+++ New
@@ @@
if (stripos($haystack, $needle) !== 0) {}
if (stripos($haystack, $needle) !== false) {}
if (stripos($haystack, $needle) === false) {}
-', ['modernize_stripos' => true])], null, 'Risky if `strpos`, `stripos`, `str_starts_with`, `str_contains` or `strtolower` functions are overridden.');
+', [])], null, 'Risky if `strpos`, `stripos`, `str_starts_with`, `str_contains` or `strtolower` functions are overridden.');
}
/**
* {@inheritdoc}
|
PHP 8.3 mutation tests:
src/Fixer/Alias/ModernizeStrposFixer.php#L97
Escaped Mutant for Mutator "TrueValue":
--- Original
+++ New
@@ @@
if (stripos($haystack, $needle) !== 0) {}
if (stripos($haystack, $needle) !== false) {}
if (stripos($haystack, $needle) === false) {}
-', ['modernize_stripos' => true])], null, 'Risky if `strpos`, `stripos`, `str_starts_with`, `str_contains` or `strtolower` functions are overridden.');
+', ['modernize_stripos' => false])], null, 'Risky if `strpos`, `stripos`, `str_starts_with`, `str_contains` or `strtolower` functions are overridden.');
}
/**
* {@inheritdoc}
|
PHP 8.3 mutation tests:
src/Fixer/Alias/ModernizeStrposFixer.php#L130
Escaped Mutant for Mutator "ArrayItemRemoval":
--- Original
+++ New
@@ @@
}
protected function createConfigurationDefinition() : FixerConfigurationResolverInterface
{
- return new FixerConfigurationResolver([(new FixerOptionBuilder('modernize_stripos', 'Whether to modernize `stripos` calls as well.'))->setAllowedTypes(['bool'])->setDefault(false)->getOption()]);
+ return new FixerConfigurationResolver([(new FixerOptionBuilder('modernize_stripos', 'Whether to modernize `stripos` calls as well.'))->setAllowedTypes([])->setDefault(false)->getOption()]);
}
protected function applyFix(\SplFileInfo $file, Tokens $tokens) : void
{
|
PHP 8.3 mutation tests:
src/Fixer/Alias/ModernizeStrposFixer.php#L236
Escaped Mutant for Mutator "IncrementInteger":
--- Original
+++ New
@@ @@
$secondArgumentIndexStart = array_key_last($arguments);
}
$secondArgumentIndexStart += 3 + ($shouldAddNamespace ? 1 : 0);
- $secondArgumentIndexEnd = $arguments[array_key_last($arguments)] + 6 + ($shouldAddNamespace ? 1 : 0) + ($isSecondArgumentTokenWhiteSpace ? 1 : 0);
+ $secondArgumentIndexEnd = $arguments[array_key_last($arguments)] + 6 + ($shouldAddNamespace ? 2 : 0) + ($isSecondArgumentTokenWhiteSpace ? 1 : 0);
if ($shouldAddNamespace) {
$tokens->insertAt($firstArgumentIndexStart, new Token([T_NS_SEPARATOR, '\\']));
++$firstArgumentIndexStart;
|
PHP 8.3 mutation tests:
src/Fixer/Alias/ModernizeStrposFixer.php#L236
Escaped Mutant for Mutator "IncrementInteger":
--- Original
+++ New
@@ @@
$secondArgumentIndexStart = array_key_last($arguments);
}
$secondArgumentIndexStart += 3 + ($shouldAddNamespace ? 1 : 0);
- $secondArgumentIndexEnd = $arguments[array_key_last($arguments)] + 6 + ($shouldAddNamespace ? 1 : 0) + ($isSecondArgumentTokenWhiteSpace ? 1 : 0);
+ $secondArgumentIndexEnd = $arguments[array_key_last($arguments)] + 6 + ($shouldAddNamespace ? 1 : 0) + ($isSecondArgumentTokenWhiteSpace ? 1 : 1);
if ($shouldAddNamespace) {
$tokens->insertAt($firstArgumentIndexStart, new Token([T_NS_SEPARATOR, '\\']));
++$firstArgumentIndexStart;
|
PHP 8.3 mutation tests:
src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php#L109
Escaped Mutant for Mutator "UnwrapStrToLower":
--- Original
+++ New
@@ @@
continue;
}
$tokenContent = $token->getContent();
- if (str_contains(strtolower($tokenContent), strtolower('inheritdoc'))) {
+ if (str_contains(strtolower($tokenContent), 'inheritdoc')) {
continue;
}
// ignore one-line phpdocs like `/** foo */`, as there is no place to put new annotations
|
PHP 8.3 mutation tests:
src/Fixer/Phpdoc/PhpdocSummaryFixer.php#L93
Escaped Mutant for Mutator "UnwrapStrToLower":
--- Original
+++ New
@@ @@
*/
private function isCorrectlyFormatted(string $content) : bool
{
- if (str_contains(strtolower($content), strtolower('{@inheritdoc}'))) {
+ if (str_contains($content, strtolower('{@inheritdoc}'))) {
return true;
}
return $content !== rtrim($content, '.:。!?¡¿!?');
}
}
|
PHP 8.3 mutation tests:
src/Fixer/Phpdoc/PhpdocSummaryFixer.php#L93
Escaped Mutant for Mutator "UnwrapStrToLower":
--- Original
+++ New
@@ @@
*/
private function isCorrectlyFormatted(string $content) : bool
{
- if (str_contains(strtolower($content), strtolower('{@inheritdoc}'))) {
+ if (str_contains(strtolower($content), '{@inheritdoc}')) {
return true;
}
return $content !== rtrim($content, '.:。!?¡¿!?');
}
}
|
PHP 8.3 mutation tests:
src/Fixer/Phpdoc/PhpdocVarAnnotationCorrectOrderFixer.php#L64
Escaped Mutant for Mutator "UnwrapStrToLower":
--- Original
+++ New
@@ @@
if (!$token->isGivenKind(T_DOC_COMMENT)) {
continue;
}
- if (!str_contains(strtolower($token->getContent()), strtolower('@var')) && !str_contains(strtolower($token->getContent()), strtolower('@type'))) {
+ if (!str_contains(strtolower($token->getContent()), '@var') && !str_contains(strtolower($token->getContent()), strtolower('@type'))) {
continue;
}
$newContent = Preg::replace('/(@(?:type|var)\\s*)(\\$\\S+)(\\h+)([^\\$](?:[^<\\s]|<[^>]*>)*)(\\s|\\*)/i', '$1$4$3$2$5', $token->getContent());
|
PHP 8.3 mutation tests:
src/Fixer/Phpdoc/PhpdocVarAnnotationCorrectOrderFixer.php#L64
Escaped Mutant for Mutator "UnwrapStrToLower":
--- Original
+++ New
@@ @@
if (!$token->isGivenKind(T_DOC_COMMENT)) {
continue;
}
- if (!str_contains(strtolower($token->getContent()), strtolower('@var')) && !str_contains(strtolower($token->getContent()), strtolower('@type'))) {
+ if (!str_contains(strtolower($token->getContent()), strtolower('@var')) && !str_contains($token->getContent(), strtolower('@type'))) {
continue;
}
$newContent = Preg::replace('/(@(?:type|var)\\s*)(\\$\\S+)(\\h+)([^\\$](?:[^<\\s]|<[^>]*>)*)(\\s|\\*)/i', '$1$4$3$2$5', $token->getContent());
|