Expected parameter of type '\App\Entity\User', 'object' provided

Hi,

 

Since PhpStorm updated to 2020.1.1 RC I've got this warning inspection :

here is the setCreatedBy declaration :

Invalidating and restarting doesn't help.

Thanks for any help.

0

Unfortunately, it is hard to say anything for sure without checking the project first. Would it be possible to share a minimal set of files to reproduce the warning?

0
Avatar
Permanently deleted user

Hi,

 

there is nothing paticular in the project.

I have a :

User entity :

class User implements UserInterface

 

BlameableEntity :

/**
* @var User
*
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(referencedColumnName="id", nullable=true)
*
* @Gedmo\Blameable(on="create")
*/
protected $createdBy;

/**
* @param User $createdBy
*
* @return $this
*/
public function setCreatedBy(User $createdBy): self
{
$this->createdBy = $createdBy;

return $this;
}

 

In my entity, I call for the BlameableEntity :


use BlameableEntity;

 

And then in a Controller :

$em = $this->getDoctrine()->getManager();
$test = new MyEntity();

$user = $em->getRepository(User::class)->findOneBy(['username' => 'test']);
$test->setCreatedBy($user);

It does this with every ManyToOne relation.

My phpstorm version : 2020.1.1 RC with Symfony and PHP Annotations plugins.

OS : linux mint 18

 

Thanks again

0
Avatar
Permanently deleted user

I created a simple project from scratch that show the warning message inside the controller :

git@gitlab.com:gaea44/tests.git

 

0

Thanks for a project. The type is coming from vendor/doctrine/persistence/lib/Doctrine/Persistence/ObjectRepository.php:

You can either correct the PhpDoc there, or rather add 

/** @var Test2|object|null $test2 */

PHPDoc above $test2:

0

请先登录再写评论。