Skip to content

Latest commit

 

History

History
48 lines (35 loc) · 1.1 KB

modernize_strpos.rst

File metadata and controls

48 lines (35 loc) · 1.1 KB

Rule modernize_strpos

Replace strpos() calls with str_starts_with() or str_contains() if possible.

Warning

Using this rule is risky

Risky if strpos, str_starts_with or str_contains functions are overridden.

Examples

Example #1

--- Original
+++ New
 <?php
-if (strpos($haystack, $needle) === 0) {}
-if (strpos($haystack, $needle) !== 0) {}
-if (strpos($haystack, $needle) !== false) {}
-if (strpos($haystack, $needle) === false) {}
+if (str_starts_with($haystack, $needle)  ) {}
+if (!str_starts_with($haystack, $needle)  ) {}
+if (str_contains($haystack, $needle)  ) {}
+if (!str_contains($haystack, $needle)  ) {}

Rule sets

The rule is part of the following rule sets:

Source class

PhpCsFixer\Fixer\Alias\ModernizeStrposFixer