8000 styles: Leverage the PHP8 new str functions by theofidry · Pull Request #1933 · infection/infection · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

styles: Leverage the PHP8 new str functions #1933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@
'syntax' => 'short',
],
'logical_operators' => true,
// TODO: enable
'modernize_strpos' => false,
'modernize_strpos' => true,
'native_constant_invocation' => true,
'native_function_invocation' => [
'include' => ['@internal'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

use Infection\CannotBeInstantiated;
use function sprintf;
use function strpos;
use function str_contains;

final class EnvManipulatorCodeDetector
{
Expand All @@ -56,7 +56,7 @@ final class EnvManipulatorCodeDetector
public static function codeManipulatesEnvVariables(string $code): bool
{
foreach (self::getStatements() as $statement) {
if (strpos($code, $statement) !== false) {
if (str_contains($code, $statement)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use function sprintf;
use function strpos;
use function str_contains;

final class IntegrationGroupTest extends TestCase
{
Expand Down Expand Up @@ -69,7 +69,7 @@ public function test_the_test_cases_requiring_io_operations_belongs_to_the_integ
),
);

if (strpos($phpDoc, '@group integration') === false) {
if (!str_contains($phpDoc, '@group integration')) {
$this->fail(sprintf(
<<<'TXT'
Expected the test case "%s" to have the annotation `@group integration` as I/O operations have been
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/AutoReview/IntegrationGroup/IoCodeDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
use function Safe\file_get_contents;
use function Safe\preg_match_all;
use function sprintf;
use function strpos;
use function str_contains;

final class IoCodeDetector
{
Expand Down Expand Up @@ -148,7 +148,7 @@ final class IoCodeDetector
public static function codeContainsIoOperations(string $code): bool
{
foreach (self::getStatements() as $statement) {
if (strpos($code, $statement) !== false) {
if (str_contains($code, $statement)) {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/AutoReview/SourceTestClassNameScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
use Infection\CannotBeInstantiated;
use function Safe\preg_match;
use function Safe\preg_replace;
use function str_contains;
use function str_replace;
use function strpos;

final class SourceTestClassNameScheme
{
Expand All @@ -56,7 +56,7 @@ public static function getSourceClassName(string $testCaseClassName): string

public static function getTestClassName(string $sourceClassName): string
{
if (strpos($sourceClassName, 'Infection\\Tests') !== false) {
if (str_contains($sourceClassName, 'Infection\\Tests')) {
return $sourceClassName . 'Test';
}

Expand Down
9 changes: 5 additions & 4 deletions tests/phpunit/Console/E2ETest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@
use function Safe\getcwd;
use function Safe\ini_get;
use function sprintf;
use function str_contains;
use function str_replace;
use function strpos;
use function str_starts_with;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Finder\Finder;
Expand Down Expand Up @@ -105,7 +106,7 @@ protected function setUp(): void
}

// Without overcommit this test fails with `proc_open(): fork failed - Cannot allocate memory`
if (strpos(PHP_OS, 'Linux') === 0 &&
if (str_starts_with(PHP_OS, 'Linux') &&
is_readable('/proc/sys/vm/overcommit_memory') &&
(int) file_get_contents('/proc/sys/vm/overcommit_memory') === 2) {
$this->markTestSkipped('This test needs copious amounts of virtual memory. It will fail unless it is allowed to overcommit memory.');
Expand Down Expand Up @@ -281,7 +282,7 @@ private function installComposerDeps(): void

foreach ($map as $namespace => $paths) {
foreach ($paths as $path) {
if (strpos($path, $vendorDir) !== false) {
if (str_contains($path, $vendorDir)) {
// Skip known dependency from autoloading
continue 2;
}
Expand All @@ -294,7 +295,7 @@ private function installComposerDeps(): void

foreach ($mapPsr0 as $namespace => $paths) {
foreach ($paths as $path) {
if (strpos($path, $vendorDir) !== false) {
if (str_contains($path, $vendorDir)) {
// Skip known dependency from autoloading
continue 2;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/Process/Runner/InitialTestsRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
use const PHP_SAPI;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use function strpos;
use function str_contains;
use Symfony\Component\Process\Exception\RuntimeException;
use Symfony\Component\Process\InputStream;
use Symfony\Component\Process\PhpExecutableFinder;
Expand Down Expand Up @@ -154,7 +154,7 @@ public function test_it_stops_the_process_execution_on_the_first_error(): void
$this->runner->run($testFrameworkExtraOptions, $phpExtraOptions, $skipCoverage);
} catch (RuntimeException $e) {
// Signal 11, AKA "segmentation fault", is not something we can do anything about
if (extension_loaded('xdebug') && strpos($e->getMessage(), 'The process has been signaled with signal "11"') !== false) {
if (extension_loaded('xdebug') && str_contains($e->getMessage(), 'The process has been signaled with signal "11"')) {
$this->markTestIncomplete($e->getMessage());
}

Expand Down
0