Skip to content

Fixed hydration of the Network class with IPv6 addresses #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ CHANGE LOG
==========


## 5.0.3 (UPCOMING)

* Fixed hydration of the Network class with IPv6 addresses


## 5.0.2 (04/03/2025)

* Fixed a couple of incorrect property types
Expand Down
14 changes: 1 addition & 13 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,10 @@ parameters:
count: 2
path: src/Entity/Droplet.php

-
message: '#^Cannot access property \$cidr on mixed\.$#'
identifier: property.nonObject
count: 1
path: src/Entity/Droplet.php

-
message: '#^Cannot access property \$netmask on mixed\.$#'
identifier: property.nonObject
count: 2
path: src/Entity/Droplet.php

-
message: '#^Cannot access property \$version on mixed\.$#'
identifier: property.nonObject
count: 2
count: 1
path: src/Entity/Droplet.php

-
Expand Down
13 changes: 9 additions & 4 deletions src/Entity/Droplet.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,15 @@ public function build(array $parameters): void

if (\property_exists($value, 'v6')) {
foreach ($value->v6 as $subValue) {
$subValue->version = 6;
$subValue->cidr = $subValue->netmask;
$subValue->netmask = null;
$this->networks[] = new Network($subValue);
/** @var object{ip_address: string, netmask: int, gateway: string, type: string} $subValue */
$this->networks[] = new Network((object) [
'ip_address' => $subValue->ip_address,
'netmask' => null,
'gateway' => $subValue->gateway,
'type' => $subValue->type,
'cidr' => \sprintf('%s/%d', $subValue->ip_address, $subValue->netmask),
'version' => 6,
]);
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/DropletEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ public function testConstructor(): void
'description' => 'Basic',
],
'size_slug' => 's-1vcpu-1gb',
'networks' => (object) [
'v4' => [
(object) [
'ip_address' => '10.135.0.3',
'netmask' => '255.255.0.0',
'gateway' => '10.135.0.1',
'type' => 'private',
],
],
'v6' => [
(object) [
'ip_address' => '2001:db8:a::1234:5678',
'netmask' => 64,
'gateway' => '2001:db8:a::1',
'type' => 'public',
],
],
],
'region' => (object) [
'name' => 'New York 3',
'slug' => 'nyc3',
Expand Down