@@ -91,76 +91,44 @@ final class Droplet extends AbstractEntity
9191 public function build (array $ parameters ): void
9292 {
9393 foreach ($ parameters as $ property => $ value ) {
94- switch ($ property ) {
95- case 'networks ' :
96- if (\is_object ($ value )) {
97- if (\property_exists ($ value , 'v4 ' )) {
98- foreach ($ value ->v4 as $ subValue ) {
99- $ subValue ->version = 4 ;
100- $ this ->networks [] = new Network ($ subValue );
101- }
102- }
103-
104- if (\property_exists ($ value , 'v6 ' )) {
105- foreach ($ value ->v6 as $ subValue ) {
106- /** @var object{ip_address: string, netmask: int, gateway: string, type: string} $subValue */
107- $ this ->networks [] = new Network ((object ) [
108- 'ip_address ' => $ subValue ->ip_address ,
109- 'netmask ' => null ,
110- 'gateway ' => $ subValue ->gateway ,
111- 'type ' => $ subValue ->type ,
112- 'cidr ' => \sprintf ('%s/%d ' , $ subValue ->ip_address , $ subValue ->netmask ),
113- 'version ' => 6 ,
114- ]);
115- }
116- }
117- }
118- unset($ parameters [$ property ]);
119-
120- break ;
121-
122- case 'kernel ' :
123- if (\is_object ($ value )) {
124- $ this ->kernel = new Kernel ($ value );
125- }
126- unset($ parameters [$ property ]);
127-
128- break ;
129-
130- case 'size ' :
131- if (\is_object ($ value )) {
132- $ this ->size = new Size ($ value );
133- }
134- unset($ parameters [$ property ]);
94+ $ property = static ::convertToCamelCase ($ property );
13595
136- break ;
137-
138- case ' region ' :
139- if ( \is_object ( $ value )) {
140- $ this ->region = new Region ( $ value );
96+ if ( ' networks ' === $ property ) {
97+ if ( \property_exists ( $ value , ' v4 ' )) {
98+ foreach ( $ value -> v4 as $ subValue ) {
99+ $ subValue -> version = 4 ;
100+ $ this ->networks [] = new Network ( $ subValue );
141101 }
142- unset($ parameters [$ property ]);
143-
144- break ;
145-
146- case 'image ' :
147- if (\is_object ($ value )) {
148- $ this ->image = new Image ($ value );
102+ }
103+
104+ if (\property_exists ($ value , 'v6 ' )) {
105+ foreach ($ value ->v6 as $ subValue ) {
106+ /** @var object{ip_address: string, netmask: int, gateway: string, type: string} $subValue */
107+ $ this ->networks [] = new Network ((object ) [
108+ 'ip_address ' => $ subValue ->ip_address ,
109+ 'netmask ' => null ,
110+ 'gateway ' => $ subValue ->gateway ,
111+ 'type ' => $ subValue ->type ,
112+ 'cidr ' => \sprintf ('%s/%d ' , $ subValue ->ip_address , $ subValue ->netmask ),
113+ 'version ' => 6 ,
114+ ]);
149115 }
150- unset($ parameters [$ property ]);
151-
152- break ;
153-
154- case 'next_backup_window ' :
155- $ this ->nextBackupWindow = new NextBackupWindow ($ value );
156- unset($ parameters [$ property ]);
157-
158- break ;
116+ }
117+ } elseif ('kernel ' === $ property ) {
118+ $ this ->kernel = new Kernel ($ value );
119+ } elseif ('size ' === $ property ) {
120+ $ this ->size = new Size ($ value );
121+ } elseif ('region ' === $ property ) {
122+ $ this ->region = new Region ($ value );
123+ } elseif ('image ' === $ property ) {
124+ $ this ->image = new Image ($ value );
125+ } elseif ('nextBackupWindow ' === $ property ) {
126+ $ this ->nextBackupWindow = new NextBackupWindow ($ value );
127+ } elseif (\property_exists ($ this , $ property )) {
128+ $ this ->$ property = $ value ;
159129 }
160130 }
161131
162- parent ::build ($ parameters );
163-
164132 $ this ->backupsEnabled = \in_array ('backups ' , $ this ->features , true );
165133 $ this ->virtIOEnabled = \in_array ('virtio ' , $ this ->features , true );
166134 $ this ->privateNetworkingEnabled = \in_array ('private_networking ' , $ this ->features , true );
0 commit comments