Is it possible to type hint a parameter directly inline during a function call?
public function load(ObjectManager $manager)
{
$product = $this->createProduct(
"T-SHIRT",
$this->getReference('brand-4') /** @var Brand <=== NOT WORKING */
);
$manager->persist($product);
$this->addReference('product-1', $product);
}
/**
* @param string $name
* @param Brand $brand
*/
private function createProduct($name, $brand)
{
$product = new Product();
$product
->setName($name)
->setBrand($brand) // <== this setter needs a Brand entity
;
// [...]
}
Of course phpstan is giving me an error because getReference
returns an object and the function expects a Brand object:
Parameter #2 $brand of method AppBundle\DataFixtures\ORM\ProductFixtures::createProduct() expects AppBundle\Entity\Brand, object given.
I would NOT like to explicity declare a variable like this:
/** @var Brand */
$brand = $this->getReference('brand-4');
$product = $this->createProduct(
"T-SHIRT",
$brand
);
It would save me a lot of time!