LKDevelopment / hetzner-cloud-php-sdk

A PHP SDK for the Hetzner Cloud API
MIT License
104 stars 51 forks source link

Prevent API undefined property: stdClass:$server error when firewall has attached tags #83

Closed geisi closed 1 year ago

geisi commented 2 years ago

Hello this is my first PR in this project:

Before this PR following error occurred when you query a firewall with an attached label:

Undefined property: stdClass::$server thrown in hetzner-cloud-php-sdk/src/Models/Firewalls/Firewall.php:125

I reproduced this error by extending the firewall.json and firewalls.json fixtures with tag objects.

This error happens because the firewall model assumes that only server resources can be attached to a firewall.

This PR checks every firewall applied service and only adds it to the appliedTo array when it is a server object. This is only a workaround around this problem. In the future these tags(and their corresponding servers) should also be applied to the appliedTo array but this needs some bigger refactoring in the firewall model code. So this is only a quick fix.

Thank you for your hard work!

LKaemmerling commented 1 year ago

Good catch! Thank you!