Skip to content

Commit fde5014

Browse files
committed
fix for #224, added safe php comparison
1 parent 39b2bf4 commit fde5014

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

modules/swagger-codegen/src/main/resources/php/api.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,20 @@ class {{classname}} {
4949
$headerParams['Content-Type'] = '{{#consumes}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/consumes}}';
5050
5151
{{#queryParams}}// query params
52-
if(${{paramName}} != null) {
52+
if(${{paramName}} !== null) {
5353
$queryParams['{{paramName}}'] = $this->apiClient->toQueryValue(${{paramName}});
5454
}{{/queryParams}}
5555
{{#headerParams}}// header params
56-
if(${{paramName}} != null) {
56+
if(${{paramName}} !== null) {
5757
$headerParams['{{paramName}}'] = $this->apiClient->toHeaderValue(${{paramName}});
5858
}{{/headerParams}}
5959
{{#pathParams}}// path params
60-
if(${{paramName}} != null) {
60+
if(${{paramName}} !== null) {
6161
$resourcePath = str_replace("{" . "{{paramName}}" . "}",
6262
$this->apiClient->toPathValue(${{paramName}}), $resourcePath);
6363
}{{/pathParams}}
6464
{{#formParams}}
65-
if (${{paramName}} != null) {
65+
if (${{paramName}} !== null) {
6666
$formParams[{{paramName}}] = {{#isFile}}'@' . {{/isFile}}${{paramName}};
6767
}{{/formParams}}
6868
{{#bodyParams}}// body params

samples/client/petstore/php/PetApi.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function findPetsByStatus($status) {
138138
$headerParams['Content-Type'] = '';
139139

140140
// query params
141-
if($status != null) {
141+
if($status !== null) {
142142
$queryParams['status'] = $this->apiClient->toQueryValue($status);
143143
}
144144

@@ -188,7 +188,7 @@ public function findPetsByTags($tags) {
188188
$headerParams['Content-Type'] = '';
189189

190190
// query params
191-
if($tags != null) {
191+
if($tags !== null) {
192192
$queryParams['tags'] = $this->apiClient->toQueryValue($tags);
193193
}
194194

@@ -240,7 +240,7 @@ public function getPetById($petId) {
240240

241241

242242
// path params
243-
if($petId != null) {
243+
if($petId !== null) {
244244
$resourcePath = str_replace("{" . "petId" . "}",
245245
$this->apiClient->toPathValue($petId), $resourcePath);
246246
}
@@ -293,15 +293,15 @@ public function updatePetWithForm($petId, $name, $status) {
293293

294294

295295
// path params
296-
if($petId != null) {
296+
if($petId !== null) {
297297
$resourcePath = str_replace("{" . "petId" . "}",
298298
$this->apiClient->toPathValue($petId), $resourcePath);
299299
}
300300

301-
if ($name != null) {
301+
if ($name !== null) {
302302
$formParams[name] = $name;
303303
}
304-
if ($status != null) {
304+
if ($status !== null) {
305305
$formParams[status] = $status;
306306
}
307307

@@ -344,11 +344,11 @@ public function deletePet($api_key, $petId) {
344344

345345

346346
// header params
347-
if($api_key != null) {
347+
if($api_key !== null) {
348348
$headerParams['api_key'] = $this->apiClient->toHeaderValue($api_key);
349349
}
350350
// path params
351-
if($petId != null) {
351+
if($petId !== null) {
352352
$resourcePath = str_replace("{" . "petId" . "}",
353353
$this->apiClient->toPathValue($petId), $resourcePath);
354354
}
@@ -373,13 +373,14 @@ public function deletePet($api_key, $petId) {
373373
* uploadFile
374374
*
375375
* uploads an image
376-
* additionalMetadata, string: Additional data to pass to server (required)
376+
* petId, int: ID of pet to update (required)
377+
* * additionalMetadata, string: Additional data to pass to server (required)
377378
* * file, file: file to upload (required)
378379
*
379380
* @return
380381
*/
381382

382-
public function uploadFile($additionalMetadata, $file) {
383+
public function uploadFile($petId, $additionalMetadata, $file) {
383384

384385
// parse inputs
385386
$resourcePath = "/pet/{petId}/uploadImage";
@@ -393,12 +394,16 @@ public function uploadFile($additionalMetadata, $file) {
393394

394395

395396

397+
// path params
398+
if($petId !== null) {
399+
$resourcePath = str_replace("{" . "petId" . "}",
400+
$this->apiClient->toPathValue($petId), $resourcePath);
401+
}
396402

397-
398-
if ($additionalMetadata != null) {
403+
if ($additionalMetadata !== null) {
399404
$formParams[additionalMetadata] = $additionalMetadata;
400405
}
401-
if ($file != null) {
406+
if ($file !== null) {
402407
$formParams[file] = '@' . $file;
403408
}
404409

samples/client/petstore/php/StoreApi.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function getOrderById($orderId) {
147147

148148

149149
// path params
150-
if($orderId != null) {
150+
if($orderId !== null) {
151151
$resourcePath = str_replace("{" . "orderId" . "}",
152152
$this->apiClient->toPathValue($orderId), $resourcePath);
153153
}
@@ -198,7 +198,7 @@ public function deleteOrder($orderId) {
198198

199199

200200
// path params
201-
if($orderId != null) {
201+
if($orderId !== null) {
202202
$resourcePath = str_replace("{" . "orderId" . "}",
203203
$this->apiClient->toPathValue($orderId), $resourcePath);
204204
}

samples/client/petstore/php/UserApi.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ public function loginUser($username, $password) {
184184
$headerParams['Content-Type'] = '';
185185

186186
// query params
187-
if($username != null) {
187+
if($username !== null) {
188188
$queryParams['username'] = $this->apiClient->toQueryValue($username);
189189
}// query params
190-
if($password != null) {
190+
if($password !== null) {
191191
$queryParams['password'] = $this->apiClient->toQueryValue($password);
192192
}
193193

@@ -279,7 +279,7 @@ public function getUserByName($username) {
279279

280280

281281
// path params
282-
if($username != null) {
282+
if($username !== null) {
283283
$resourcePath = str_replace("{" . "username" . "}",
284284
$this->apiClient->toPathValue($username), $resourcePath);
285285
}
@@ -331,7 +331,7 @@ public function updateUser($username, $body) {
331331

332332

333333
// path params
334-
if($username != null) {
334+
if($username !== null) {
335335
$resourcePath = str_replace("{" . "username" . "}",
336336
$this->apiClient->toPathValue($username), $resourcePath);
337337
}
@@ -380,7 +380,7 @@ public function deleteUser($username) {
380380

381381

382382
// path params
383-
if($username != null) {
383+
if($username !== null) {
384384
$resourcePath = str_replace("{" . "username" . "}",
385385
$this->apiClient->toPathValue($username), $resourcePath);
386386
}

0 commit comments

Comments
 (0)