Skip to content

StrContainsRector PHP7.4 => PHP8.0 upgrade #9886

Description

@raphaelincert

Bug Report

Subject Details
Rector version 2.6.6

Hi,
the rule StrContainsRector does not work for PHP7.4 => PHP8.0 upgrades.
The fix is missing a check for an empty string - have a look at the symfony polyfill implementation:

Image

your rule StrContainsRector should be changed pretty much the same as the polyfill implementation - you need to add a check for empty string.

Best regards

Minimal PHP Code Causing Issue

https://getrector.com/demo/25e6222a-ae1d-4503-8098-c15ca53b2d1b

Expected Behaviour

do it like symfony implementation and check for empty needle aswell:

 public static function str_contains(string $haystack, string $needle): bool
 {
     return '' === $needle || false !== strpos($haystack, $needle);
 }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions