Skip to content

Commit 74dc05b

Browse files
committed
Merge pull request #776 from wing328/php53_fix_warning
[PHP] Fix warning/error related to PHP5.3
2 parents b6d206a + fa15f58 commit 74dc05b

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class APIClient {
4141
* @param string $host Base url of the API server (optional)
4242
*/
4343
function __construct($host = null) {
44-
if ($host == null) {
44+
if ($host === null) {
4545
$this->host = '{{basePath}}';
4646
} else {
4747
$this->host = $host;
@@ -107,10 +107,12 @@ class APIClient {
107107
* @return string API key with the prefix
108108
*/
109109
public function getApiKeyWithPrefix($apiKey) {
110-
if (Configuration::$apiKeyPrefix[$apiKey]) {
110+
if (isset(Configuration::$apiKeyPrefix[$apiKey])) {
111111
return Configuration::$apiKeyPrefix[$apiKey]." ".Configuration::$apiKey[$apiKey];
112-
} else {
112+
} else if (isset(Configuration::$apiKey[$apiKey])) {
113113
return Configuration::$apiKey[$apiKey];
114+
} else {
115+
return;
114116
}
115117
}
116118

@@ -368,7 +370,7 @@ class APIClient {
368370
$instance = new $class();
369371
foreach ($instance::$swaggerTypes as $property => $type) {
370372
$original_property_name = $instance::$attributeMap[$property];
371-
if (isset($original_property_name)) {
373+
if (isset($original_property_name) && isset($data->$original_property_name)) {
372374
$instance->$property = self::deserialize($data->$original_property_name, $type);
373375
}
374376
}

samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class APIClient {
4141
* @param string $host Base url of the API server (optional)
4242
*/
4343
function __construct($host = null) {
44-
if ($host == null) {
44+
if ($host === null) {
4545
$this->host = 'http://petstore.swagger.io/v2';
4646
} else {
4747
$this->host = $host;
@@ -107,10 +107,12 @@ public function setTimeout($seconds) {
107107
* @return string API key with the prefix
108108
*/
109109
public function getApiKeyWithPrefix($apiKey) {
110-
if (Configuration::$apiKeyPrefix[$apiKey]) {
110+
if (isset(Configuration::$apiKeyPrefix[$apiKey])) {
111111
return Configuration::$apiKeyPrefix[$apiKey]." ".Configuration::$apiKey[$apiKey];
112-
} else {
112+
} else if (isset(Configuration::$apiKey[$apiKey])) {
113113
return Configuration::$apiKey[$apiKey];
114+
} else {
115+
return;
114116
}
115117
}
116118

@@ -373,7 +375,7 @@ public static function deserialize($data, $class)
373375
$instance = new $class();
374376
foreach ($instance::$swaggerTypes as $property => $type) {
375377
$original_property_name = $instance::$attributeMap[$property];
376-
if (isset($original_property_name)) {
378+
if (isset($original_property_name) && isset($data->$original_property_name)) {
377379
$instance->$property = self::deserialize($data->$original_property_name, $type);
378380
}
379381
}

samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function setUpBeforeClass() {
2323
$category->id = $new_pet_id; // use the same id as pet
2424
$category->name = "test php category";
2525

26-
$new_pet->tags = [$tag];
26+
$new_pet->tags = array($tag);
2727
$new_pet->category = $category;
2828

2929
$pet_api = new SwaggerClient\PetAPI($api_client);
@@ -47,12 +47,14 @@ public function testAPIClient()
4747
# test addDefaultHeader and getDefaultHeader
4848
SwaggerClient\APIClient::addDefaultHeader('test1', 'value1');
4949
SwaggerClient\APIClient::addDefaultHeader('test2', 200);
50-
$this->assertSame('value1', SwaggerClient\APIClient::getDefaultHeader()['test1']);
51-
$this->assertSame(200, SwaggerClient\APIClient::getDefaultHeader()['test2']);
50+
$defaultHeader = SwaggerClient\APIClient::getDefaultHeader();
51+
$this->assertSame('value1', $defaultHeader['test1']);
52+
$this->assertSame(200, $defaultHeader['test2']);
5253

5354
# test deleteDefaultHeader
5455
SwaggerClient\APIClient::deleteDefaultHeader('test2');
55-
$this->assertFalse(isset(SwaggerClient\APIClient::getDefaultHeader()['test2']));
56+
$defaultHeader = SwaggerClient\APIClient::getDefaultHeader();
57+
$this->assertFalse(isset($defaultHeader['test2']));
5658

5759
}
5860

0 commit comments

Comments
 (0)