Overriding PHPDoc types (or at least force them to be absolute) #4367
-
Hi. I am using a third party library (facebook/php-business-sdk) and I get errors when running phpstan:
for the following code: use FacebookAds\Object\ServerSide\CustomData;
use FacebookAds\Object\ServerSide\Event;
..
$custom_data = (new CustomData())->setValue($basketData['AmountNumeric']);
$event = (new Event())->setCustomData($customData); This seems to be due the PHPDoc on the namespace FacebookAds\Object\ServerSide;
class Event implements ArrayAccess {
...
/**
* Sets CustomData object that includes additional business data about the event.
* @param FacebookAds\Object\ServerSide\CustomData $custom_data
* @return $this
*/
public function setCustomData($custom_data) {
...
}
...
} AFAIU, the Is there a way to teach phpstan that this it should interprete these types in an absolute fashion? Or am I just missing something? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello, have you checked out the Stub files feature? It's built exactly for this purpose - overriding wrong 3rd party PHPDocs :) https://phpstan.org/user-guide/stub-files In this case this is a sufficient stub file that should be registered: <?php
namespace FacebookAds\Object\ServerSide;
class Event implements ArrayAccess {
...
/**
* Sets CustomData object that includes additional business data about the event.
* @param \FacebookAds\Object\ServerSide\CustomData $custom_data
* @return $this
*/
public function setCustomData($custom_data) {
}
...
} |
Beta Was this translation helpful? Give feedback.
Hello, have you checked out the Stub files feature? It's built exactly for this purpose - overriding wrong 3rd party PHPDocs :) https://phpstan.org/user-guide/stub-files
In this case this is a sufficient stub file that should be registered: