You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since we upgraded softcreatr/jsonpath to ^0.7.2, we noticed that some type checks were added to the JsonPath object (which is awesome 😍).
Here's the issue
class JsonPath
{
// .../** * @param array|ArrayAccess $data * @param bool $options */finalpublicfunction__construct($data = [], bool$options = false)
{
// Here, we should assert that `$data` is either an `array` or an instance of `ArrayAccess`, if not an `InvalidArgumentException` should be thrown$this->data = $data;
$this->options = $options;
}
// ...publicfunctiongetData(): array
{
// it will although returns a `TypeError` when `$data` is an instance of `ArrayAccess`return$this->data;
}
// ...
}
Have you spent some time to check if this issue has been raised before?
[x] I have read googled for a similar issue or checked our older issues for a similar bug
thank you for your report. Checking the code, I'm somewhat unconfident, that the current implementation is correct. Without testing it, the problem I see with your proposed change (and the current implementation) is the fact, that you should be able to pass nearly everything to the constructor, even strings, but getData should return either an array or an object. The easiest fix might be to modify the return type for getData() to array|ArrayAccess. However, union types only exist since PHP 8, so the fix might be to replace
@SoftCreatR I see. I haven't checked the test suite yet, but removing the return type hint, seems to be a pretty good solution. Beware however, because it seems that \stdClass objects generated by json_decode don't implements ArrayAccess, type checkers such as PHPStan or Psalm will complain :)
🐛 Bug Report
Since we upgraded
softcreatr/jsonpath
to^0.7.2
, we noticed that some type checks were added to theJsonPath
object (which is awesome 😍).Here's the issue
Have you spent some time to check if this issue has been raised before?
[x] I have read googled for a similar issue or checked our older issues for a similar bug
Have you read the Code of Conduct?
[x] I have read the Code of Conduct
To Reproduce
Expected behavior
An
InvalidArgumentException
Actual Behavior
No exception is thrown
Your Environment
Thank you, it you need additional information, feel free to contact me :) I can provide a "fix" if required
The text was updated successfully, but these errors were encountered: