是否可以在函数调用期间直接内联输入提示参数?
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
;
// [...]
}
当然 phpstan 给了我一个错误,因为getReference
返回一个对象并且该函数需要一个 Brand 对象:
Parameter #2 $brand of method AppBundle\DataFixtures\ORM\ProductFixtures::createProduct() expects AppBundle\Entity\Brand, object given.
我不想明确声明这样的变量:
/** @var Brand */
$brand = $this->getReference('brand-4');
$product = $this->createProduct(
"T-SHIRT",
$brand
);
它会为我节省很多时间!