geocoder-php / Geocoder

The most featured Geocoder library written in PHP.
https://geocoder-php.org
MIT License
3.95k stars 516 forks source link

GoogleMapsPlaces: check if value "open_now" in "opening_hours" #1034

Closed ghost closed 4 years ago

ghost commented 4 years ago

If you perform the following request you will see that the value of "opening_hours" is an empty object and "open_now" is not set.

https://maps.googleapis.com/maps/api/place/textsearch/json?location=51.0572773,13.7763207&rankby=distance&type=transit_station&key=YOUR_API_KEY

{
  "results": [
    {
      "id": "b427385cd417b5851b4e23de4225d102ffc2aa43",
      "opening_hours": {},
      // ...
    },
    // ...
  ],
  // ...
}

This will result in the following error.

In OpeningHours.php line 76:

  Notice: Undefined property: stdClass::$open_now

Therefore, we should check if the property "open_now" exists.

atymic commented 4 years ago

Thanks for the PR @bitecodes

Can you please add a test to cover the example you provided?

ghost commented 4 years ago

Thanks for the PR @bitecodes

Can you please add a test to cover the example you provided?

Yes, I will add a test

ghost commented 4 years ago

Added a test and made open_now nullable

ghost commented 4 years ago

Code style fixed! ;-)

atymic commented 4 years ago

Merged 🎉

Could you please tag a new version of the package @Nyholm? I only have permissions on this repo, not on the subtree split versions.

Thanks!

jbelien commented 4 years ago

Done: 1.0.1 🎉

atymic commented 4 years ago

Thanks @jbelien :)