magento-coding-standard icon indicating copy to clipboard operation
magento-coding-standard copied to clipboard

Reactor rule php8 ReplaceNewDateTimeNull has wrong implementation

Open 0m3r opened this issue 3 years ago • 1 comments
trafficstars

Description

I have a couple of wrong passes of the rule


-        $date = new \DateTime($date);
-        $now = new \DateTime();
+        $date = new \DateTime('now');
+        $now = new \DateTime('now');
         $now->setTime(0, 0, 0, 0);
         $minDelay = $this->getMinDelayDays();
         $interval = $now->diff($date);
    ----------- end diff -----------

Applied rules:
 * ReplaceNewDateTimeNull
public function __construct(
        #[LanguageLevelTypeAware(['8.0' => 'string'], default: '')] $datetime = 'now',
        #[LanguageLevelTypeAware(['8.0' => 'DateTimeZone|null'], default: 'DateTimeZone')] $timezone = null
    ) {}

default is 'now' and it's a string so that the first argument can be empty and it's also can be variable
but in rule it's always must by string

https://github.com/magento/magento-coding-standard/blob/50e7c2ad3d7110b06527d75a1aa954b7c20f6ea1/Magento2/Rector/Src/ReplaceNewDateTimeNull.php#L36

if ($node->args[0] !== String_::class) {

Expected behavior

it looks like this rule should work only if the first argument is precisely null

0m3r avatar May 23 '22 14:05 0m3r

Hi @0m3r. Thank you for your report. To speed up processing of this issue, make sure that you provided sufficient information.

Add a comment to assign the issue: @magento I am working on this


m2-assistant[bot] avatar May 23 '22 14:05 m2-assistant[bot]