diff --git a/config/set/php85.php b/config/set/php85.php index 074c18b2af9..64d6c3b92a5 100644 --- a/config/set/php85.php +++ b/config/set/php85.php @@ -10,6 +10,7 @@ use Rector\Php85\Rector\ArrayDimFetch\ArrayFirstLastRector; use Rector\Php85\Rector\ClassMethod\NullDebugInfoReturnRector; use Rector\Php85\Rector\Const_\DeprecatedAnnotationToDeprecatedAttributeRector; +use Rector\Php85\Rector\Double\DoubleToFloatCastRector; use Rector\Php85\Rector\FuncCall\ArrayKeyExistsNullToEmptyStringRector; use Rector\Php85\Rector\FuncCall\RemoveFinfoBufferContextArgRector; use Rector\Php85\Rector\Switch_\ColonAfterSwitchCaseRector; @@ -34,6 +35,7 @@ DeprecatedAnnotationToDeprecatedAttributeRector::class, ColonAfterSwitchCaseRector::class, ArrayKeyExistsNullToEmptyStringRector::class, + DoubleToFloatCastRector::class, ] ); diff --git a/rules-tests/Php85/Rector/Double/DoubleToFloatCastRector/DoubleToFloatCastRectorTest.php b/rules-tests/Php85/Rector/Double/DoubleToFloatCastRector/DoubleToFloatCastRectorTest.php new file mode 100644 index 00000000000..2705e4bb60f --- /dev/null +++ b/rules-tests/Php85/Rector/Double/DoubleToFloatCastRector/DoubleToFloatCastRectorTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/rules-tests/Php85/Rector/Double/DoubleToFloatCastRector/Fixture/double.php.inc b/rules-tests/Php85/Rector/Double/DoubleToFloatCastRector/Fixture/double.php.inc new file mode 100644 index 00000000000..638bf7e96ea --- /dev/null +++ b/rules-tests/Php85/Rector/Double/DoubleToFloatCastRector/Fixture/double.php.inc @@ -0,0 +1,11 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/Php85/Rector/Double/DoubleToFloatCastRector/config/configured_rule.php b/rules-tests/Php85/Rector/Double/DoubleToFloatCastRector/config/configured_rule.php new file mode 100644 index 00000000000..f9f79d798b1 --- /dev/null +++ b/rules-tests/Php85/Rector/Double/DoubleToFloatCastRector/config/configured_rule.php @@ -0,0 +1,13 @@ +rule(DoubleToFloatCastRector::class); + + $rectorConfig->phpVersion(PhpVersion::PHP_85); +}; diff --git a/rules/Php85/Rector/Double/DoubleToFloatCastRector.php b/rules/Php85/Rector/Double/DoubleToFloatCastRector.php new file mode 100644 index 00000000000..cdff1624e0b --- /dev/null +++ b/rules/Php85/Rector/Double/DoubleToFloatCastRector.php @@ -0,0 +1,65 @@ +getAttribute(AttributeKey::KIND); + if ($kind !== Double::KIND_DOUBLE) { + return null; + } + + $node->setAttribute(AttributeKey::KIND, Double::KIND_FLOAT); + $node->setAttribute(AttributeKey::ORIGINAL_NODE, null); + + return $node; + } + + public function provideMinPhpVersion(): int + { + return PhpVersionFeature::DEPRECATE_DOUBLE_CAST; + } +} diff --git a/src/ValueObject/PhpVersionFeature.php b/src/ValueObject/PhpVersionFeature.php index 1c72c63d39b..5cff4032ed8 100644 --- a/src/ValueObject/PhpVersionFeature.php +++ b/src/ValueObject/PhpVersionFeature.php @@ -798,4 +798,7 @@ final class PhpVersionFeature * @var int */ public const DEPRECATE_NULL_ARG_IN_ARRAY_KEY_EXISTS_FUNCTION = PhpVersion::PHP_85; + + public const DEPRECATE_DOUBLE_CAST = PhpVersion::PHP_85; + }