diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/skip_new_line.php.inc b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/skip_new_line.php.inc new file mode 100644 index 00000000000..23e561fe8e9 --- /dev/null +++ b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/skip_new_line.php.inc @@ -0,0 +1,14 @@ +.*?)(?[imsxeADSUXJu]*)$#s'; + /** + * @var string + * @see https://regex101.com/r/nnuwUo/1 + * + * For modifiers see https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php + */ + private const INNER_UNICODE_REGEX = '#(?.*?)(?[imsxeADSUXJu]*)$#u'; + + /** + * @var string + * @see https://regex101.com/r/KpCzg6/1 + */ + private const NEW_LINE_REGEX = '#(\\r|\\n)#'; + /** * @var string * @see https://regex101.com/r/EyXsV6/6 @@ -169,6 +183,26 @@ private function refactorFuncCall(FuncCall $funcCall): ?FuncCall return null; } + private function hasNewLineWithUnicodeModifier(string $string): bool + { + $matchInnerRegex = Strings::match($string, self::INNER_REGEX); + $matchInnerUnionRegex = Strings::match($string, self::INNER_UNICODE_REGEX); + + if (! is_array($matchInnerRegex)) { + return false; + } + + if (! is_array($matchInnerUnionRegex)) { + return false; + } + + if ($matchInnerRegex === $matchInnerUnionRegex) { + return false; + } + + return StringUtils::isMatch($matchInnerUnionRegex['content'], self::NEW_LINE_REGEX); + } + private function refactorArgument(Arg $arg): void { if (! $arg->value instanceof String_) { @@ -177,6 +211,11 @@ private function refactorArgument(Arg $arg): void /** @var String_ $string */ $string = $arg->value; + + if ($this->hasNewLineWithUnicodeModifier($string->value)) { + return; + } + $string->value = Strings::replace($string->value, self::INNER_REGEX, function (array $match) use ( &$string ): string { diff --git a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php index 42f519db6b9..1fef3e31eb0 100644 --- a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php +++ b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php @@ -190,10 +190,12 @@ private function isStaticType(Type $type): bool /** * @param array> $excludedInferers */ - private function shouldSkipExcludedTypeInferer(ReturnTypeInfererInterface $return, array $excludedInferers): bool - { + private function shouldSkipExcludedTypeInferer( + ReturnTypeInfererInterface $returnTypeInferer, + array $excludedInferers + ): bool { foreach ($excludedInferers as $excludedInferer) { - if (is_a($return, $excludedInferer)) { + if (is_a($returnTypeInferer, $excludedInferer)) { return true; } }