I am currently working on bringing my extensions to the current coding standard.
So, when writing a function, normally I would describe it the following way:
protected function exampleFunction(string $name): string|null
{
return $name;
}
But there are some cases, where I dont know, how to "describe" the return value.
For example:
protected function getParentProduct(int $id): ??????
{
$parentByChild = $this->catalogProductTypeConfigurable->getParentIdsByChild($id);
if (isset($parentByChild[0])) {
//set id as parent product id...
$parentid = $parentByChild[0];
return $this->ProductFactory->create()->load($parentid);
}
}
So, the function returns a loaded product (built with ProductFactory. But as the Product-class is not explicity at the begin of the class (Magento\Catalog\Model\Product), I dont know, what I should use for the description or if its ok, to just write:
protected function getParentProduct(int $id): Product|null
I know, this is nothing, that would break the code, but I want to use more good habits, when coding my extensions.