So, I have some method with a parameter expecting an array. Like this:
private function handler($db_data){
$formatted_date = $db_data['StartDate']->format('Y-m-d H:i:s');
}
As you can see, this array have DateTime object in it. The problem is that I don't know how to declare this DateTime object using PHPDoc, so PHPStorm is telling me that method 'format' is not found. Anybody know how to solve it? Don't propose to suppress this warning :) Thanks
You could store it in a temporary variable and add PHPDoc there. For instance:
/** @var DateTime $date */
$date = $db_data['StartDate'];
That way PhpStorm should know the available methods.
The only thing I can come up with (since arrays are dynamically typed) is this:
/** @var \DateTime $unformatted_date */
$unformatted_date = $db_data['StartDate'];
$formatted_date = $unformatted_date->format('Y-m-d H:i:s');
EDIT
Side note: don't rely too much on your IDE. My answer isn't really useful, since your original statement was perfectly readable and it conveys the meaning well. The phpdoc isn't going to typecheck your array, so it's literally only there to remove the warning your IDE is giving you. It obstructs code readability in my opinion. It's up to you ofcourse, but I would use comments like these for very complicated datastructures. Not for code that is perfectly readable and concise.