mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-16 08:02:23 +00:00
[CodeQuality] Handle colon in arg value for create variable or MoveOutMethodCallInsideIfConditionRector (#6025)
* [CodeQuality] Handle colon in arg value fto create variable or MoveOutMethodCallInsideIfConditionRector * regex constant name fix
This commit is contained in:
parent
1224a69c8a
commit
4a34bece7d
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\CodeQualityStrict\Rector\If_\MoveOutMethodCallInsideIfConditionRector\Fixture;
|
||||
|
||||
use DateTime;
|
||||
|
||||
final class StringArgVariableColon
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$dt = new DateTime();
|
||||
if ($dt->format('H:i:s') == '00:00:00') {
|
||||
echo "test".PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\CodeQualityStrict\Rector\If_\MoveOutMethodCallInsideIfConditionRector\Fixture;
|
||||
|
||||
use DateTime;
|
||||
|
||||
final class StringArgVariableColon
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$dt = new DateTime();
|
||||
$dtFormat = $dt->format('H:i:s');
|
||||
if ($dtFormat == '00:00:00') {
|
||||
echo "test".PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -33,6 +33,12 @@ final class MethodCallToVariableNameResolver
|
|||
*/
|
||||
private const SPACE_REGEX = '#\s+#';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @see https://regex101.com/r/TOPfAQ/1
|
||||
*/
|
||||
private const VALID_STRING_VARIABLE_REGEX = '#^[a-z_]\w*$#';
|
||||
|
||||
/**
|
||||
* @var NodeNameResolver
|
||||
*/
|
||||
|
@ -143,6 +149,10 @@ final class MethodCallToVariableNameResolver
|
|||
|
||||
private function normalizeStringVariableName(string $string): string
|
||||
{
|
||||
if (! Strings::match($string, self::VALID_STRING_VARIABLE_REGEX)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$get = str_ireplace('get', '', $string);
|
||||
$by = str_ireplace('by', '', $get);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user