Access to an array returned by a method property
manuelbcd opened this issue · 4 comments
Hi. This way of accessing is not working, almost in my tests.
Imagine that PropertyA is an associative array like this: ["a" => "b", "c" => "d"]
assertion) object.getPropertyA()["a"] = "b" --> Throws the following error
CRITICAL: Uncaught PHP Exception Hoa\Ruler\Exception\Asserter: "Try to access to an undefined index: a (dimension number 2 of object), because it is not an array." at /var/www/html/vendor/hoa/ruler/Visitor/Asserter.php line 345 {"exception":"[object] (Hoa\\Ruler\\Exc
eption\\Asserter(code: 3): Try to access to an undefined index: a (dimension number 2 of object), because it is not an array. at /var/www/html/vendor/hoa/ruler/Visitor/Asserter.php:345)"
It seems that the chain object.property()[array_position] does not work.
----------Update------------------------
I just realized that the array is not a basic array. It is a Doctrine ArrayCollection
i.e.) new ArrayCollection(["a" => "b", "c" => "d"]
Maybe it explains the problem.
Hello :-),
Does the ArrayCollection
from Doctrine acts as an array (with ArrayAccess
for instance)?
We should patch https://github.com/hoaproject/Ruler/blob/master/Visitor/Asserter.php#L333-L366 to accept more than regular arrays, but array-like structure. Do you want to try a patch?
@manuelbcd See #106.
Great. Thank you