nextras / orm-phpstan

PHPStan extension for Nextras Orm
https://nextras.org/orm
MIT License
11 stars 6 forks source link

Entity relationship property set to primary key instead of related entity generates error #4

Closed vasekbrychta closed 5 years ago

vasekbrychta commented 5 years ago

Having similar definition

/**
 * @property int     $id          {primary}
 * @property Author  $author      {m:1 Author::$books}
 */
class Book extends Nextras\Orm\Entity\Entity
{}

and calling $book->author = 1; generates

Property Book::$author (Author) does not accept int.

although the Author entity is correctly auto-loaded.

hrach commented 5 years ago

Hi, to fix this I would need an actual reproduction. This seems like not properly initialized relationship container. This behaviour is currently covered by tests, so there will be some mistake.

I'm missed the most important thing this is reported on phpstan extension repo... 🤕 . Ok, sorry.

This is known limitation and I'm working on a fix. The fix require some changes in PhpStan, which I hope are quite near mering

hrach commented 5 years ago

In my projects I currently ignore this errors by

- '#Property [\w\\]+::\$\w+ \([\w|\\]+\) does not accept int\.#'
- '#Property [\w\\]+::\$\w+ \([\w|\\]+\) does not accept int|null\.#'

Be aware they are not super-save.

vasekbrychta commented 5 years ago

Ok, that's great! Thanks for the workaround. I might add the common namespace prefix for all my Entities to be more safe for now.

hrach commented 5 years ago

Finally fixed, right now works only with PhpStan master.