Merge pull request #776 from wing328/php53_fix_warning

[PHP] Fix warning/error related to PHP5.3
This commit is contained in:
Tony Tam 2015-05-23 08:53:52 -07:00
commit 74dc05bbf5
3 changed files with 18 additions and 12 deletions

View File

@ -41,7 +41,7 @@ class APIClient {
* @param string $host Base url of the API server (optional)
*/
function __construct($host = null) {
if ($host == null) {
if ($host === null) {
$this->host = '{{basePath}}';
} else {
$this->host = $host;
@ -107,10 +107,12 @@ class APIClient {
* @return string API key with the prefix
*/
public function getApiKeyWithPrefix($apiKey) {
if (Configuration::$apiKeyPrefix[$apiKey]) {
if (isset(Configuration::$apiKeyPrefix[$apiKey])) {
return Configuration::$apiKeyPrefix[$apiKey]." ".Configuration::$apiKey[$apiKey];
} else {
} else if (isset(Configuration::$apiKey[$apiKey])) {
return Configuration::$apiKey[$apiKey];
} else {
return;
}
}
@ -368,7 +370,7 @@ class APIClient {
$instance = new $class();
foreach ($instance::$swaggerTypes as $property => $type) {
$original_property_name = $instance::$attributeMap[$property];
if (isset($original_property_name)) {
if (isset($original_property_name) && isset($data->$original_property_name)) {
$instance->$property = self::deserialize($data->$original_property_name, $type);
}
}

View File

@ -41,7 +41,7 @@ class APIClient {
* @param string $host Base url of the API server (optional)
*/
function __construct($host = null) {
if ($host == null) {
if ($host === null) {
$this->host = 'http://petstore.swagger.io/v2';
} else {
$this->host = $host;
@ -107,10 +107,12 @@ class APIClient {
* @return string API key with the prefix
*/
public function getApiKeyWithPrefix($apiKey) {
if (Configuration::$apiKeyPrefix[$apiKey]) {
if (isset(Configuration::$apiKeyPrefix[$apiKey])) {
return Configuration::$apiKeyPrefix[$apiKey]." ".Configuration::$apiKey[$apiKey];
} else {
} else if (isset(Configuration::$apiKey[$apiKey])) {
return Configuration::$apiKey[$apiKey];
} else {
return;
}
}
@ -373,7 +375,7 @@ class APIClient {
$instance = new $class();
foreach ($instance::$swaggerTypes as $property => $type) {
$original_property_name = $instance::$attributeMap[$property];
if (isset($original_property_name)) {
if (isset($original_property_name) && isset($data->$original_property_name)) {
$instance->$property = self::deserialize($data->$original_property_name, $type);
}
}

View File

@ -23,7 +23,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
$category->id = $new_pet_id; // use the same id as pet
$category->name = "test php category";
$new_pet->tags = [$tag];
$new_pet->tags = array($tag);
$new_pet->category = $category;
$pet_api = new SwaggerClient\PetAPI($api_client);
@ -47,12 +47,14 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
# test addDefaultHeader and getDefaultHeader
SwaggerClient\APIClient::addDefaultHeader('test1', 'value1');
SwaggerClient\APIClient::addDefaultHeader('test2', 200);
$this->assertSame('value1', SwaggerClient\APIClient::getDefaultHeader()['test1']);
$this->assertSame(200, SwaggerClient\APIClient::getDefaultHeader()['test2']);
$defaultHeader = SwaggerClient\APIClient::getDefaultHeader();
$this->assertSame('value1', $defaultHeader['test1']);
$this->assertSame(200, $defaultHeader['test2']);
# test deleteDefaultHeader
SwaggerClient\APIClient::deleteDefaultHeader('test2');
$this->assertFalse(isset(SwaggerClient\APIClient::getDefaultHeader()['test2']));
$defaultHeader = SwaggerClient\APIClient::getDefaultHeader();
$this->assertFalse(isset($defaultHeader['test2']));
}