-
I was using the following snippet for the mapper: $this->mapper->map(['finished' => true], BookDto::class); Now I noticed my PHPstan was not happy as I was passing an So is it designed to handle Now I was trying to prevent these PHPstan warnings and I thought maybe explicitely casting the array to an object would do the trick: $this->mapper->map((object) ['finished' => true], BookDto::class); But the mapper doesn't like this as it throws an I was looking through the docs to something related to this, but couldn't seem to find it, so could you point me in the right direction, or maybe suggest an alternative on how to solve this problem? Version: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The code works because there is a bug in the implementation that it accepts mixed, not object, unlike the interface. Liskov allows it, so static analysis did not catch the bug. I'll fix the bug later. Internally, the engine can handle array to object mapping. It just forwards the job to Symfony Serializer. So your code can work. PHPstan does not like it because it sees I blacklisted internal classes because it almost always results in an error with an obscure error message. |
Beta Was this translation helpful? Give feedback.
The code works because there is a bug in the implementation that it accepts mixed, not object, unlike the interface. Liskov allows it, so static analysis did not catch the bug. I'll fix the bug later.
Internally, the engine can handle array to object mapping. It just forwards the job to Symfony Serializer. So your code can work.
PHPstan does not like it because it sees
$this->mapper
as aMapperInterface
, not the concreteMapper
. But PHP doesn't care, it just runs the code.I blacklisted internal classes because it almost always results in an error with an obscure error message.
stdClass
should be specifically supported, though. I…