Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
The Drupal.Classes.ClassCreateInstance.ParenthesisMissing can cause syntax error.
Checking a php file with the following content will result in this validation error: "Calling class constructors must always include parentheses"
This is correct, but all of them could be corrected automatically.
<?php
$obj1 = new DateTime;
$obj1 = new \DateTime;
$obj2 = $obj1->add(new \DateTime);
$obj2 = $obj1->add(new Vendor);
$obj2 = $obj1->add(new Vendor\DateTools);
$obj2 = $obj1->add(new Vendor\DateTools\DateInterval);
$obj2 = $obj1->add(new \Vendor\DateTools\DateInterval);
The fixer includes the required parentheses in wrong place when namespace separators are present. The result will look like this:
<?php
$obj1 = new DateTime();
$obj1 = new \DateTime;
$obj2 = $obj1->add(new \DateTime);
$obj2 = $obj1->add(new Vendor());
$obj2 = $obj1->add(new Vendor()\DateTools);
$obj2 = $obj1->add(new Vendor()\DateTools\DateInterval);
$obj2 = $obj1->add(new \Vendor\DateTools\DateInterval);
The correct result should be:
<?php
$obj1 = new DateTime();
$obj1 = new \DateTime();
$obj2 = $obj1->add(new \DateTime());
$obj2 = $obj1->add(new Vendor());
$obj2 = $obj1->add(new Vendor\DateTools());
$obj2 = $obj1->add(new Vendor\DateTools\DateInterval());
$obj2 = $obj1->add(new \Vendor\DateTools\DateInterval());
Comments
Comment #2
smatyas CreditAttribution: smatyas at Cheppers commentedComment #4
klausiCommitted a fix, thanks for reporting!