-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from maxbeckers/feature/code_optimization
Feature/code optimization
- Loading branch information
Showing
38 changed files
with
329 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ composer.lock | |
.php_cs.cache | ||
/.idea/ | ||
.phpunit.result.cache | ||
.phpunit.cache/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace MaxBeckers\AmazonAlexa\Helper; | ||
|
||
/** | ||
* This helper class simplifies the property handling. | ||
* | ||
* @author Maximilian Beckers <[email protected]> | ||
*/ | ||
class PropertyHelper | ||
{ | ||
/** | ||
* @param array $data | ||
* @param string $key | ||
* | ||
* @return string|null | ||
*/ | ||
public static function checkNullValueString(array $data, string $key) | ||
{ | ||
return isset($data[$key]) ? $data[$key] : null; | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* @param string $key | ||
* | ||
* @return int|null | ||
*/ | ||
public static function checkNullValueInt(array $data, string $key) | ||
{ | ||
return isset($data[$key]) ? $data[$key] : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace MaxBeckers\AmazonAlexa\Helper; | ||
|
||
/** | ||
* This trait is helpful for the property to ArrayObject mapping. | ||
* | ||
* @author Maximilian Beckers <[email protected]> | ||
*/ | ||
trait SerializeValueMapper | ||
{ | ||
/** | ||
* @param \ArrayObject $data | ||
* @param string $property | ||
*/ | ||
protected function valueToArrayIfSet(\ArrayObject $data, string $property) | ||
{ | ||
if (null !== $this->{$property}) { | ||
$data[$property] = $this->{$property}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
namespace MaxBeckers\AmazonAlexa\Request; | ||
|
||
use MaxBeckers\AmazonAlexa\Helper\PropertyHelper; | ||
|
||
/** | ||
* @author Maximilian Beckers <[email protected]> | ||
*/ | ||
|
@@ -38,9 +40,9 @@ public static function fromAmazonRequest(array $amazonRequest): self | |
{ | ||
$audioPlayer = new self(); | ||
|
||
$audioPlayer->token = isset($amazonRequest['token']) ? $amazonRequest['token'] : null; | ||
$audioPlayer->offsetInMilliseconds = isset($amazonRequest['offsetInMilliseconds']) ? (int) $amazonRequest['offsetInMilliseconds'] : null; | ||
$audioPlayer->playerActivity = isset($amazonRequest['playerActivity']) ? $amazonRequest['playerActivity'] : null; | ||
$audioPlayer->token = PropertyHelper::checkNullValueString($amazonRequest, 'token'); | ||
$audioPlayer->offsetInMilliseconds = PropertyHelper::checkNullValueInt($amazonRequest, 'offsetInMilliseconds'); | ||
$audioPlayer->playerActivity = PropertyHelper::checkNullValueString($amazonRequest, 'playerActivity'); | ||
|
||
return $audioPlayer; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
namespace MaxBeckers\AmazonAlexa\Request; | ||
|
||
use MaxBeckers\AmazonAlexa\Helper\PropertyHelper; | ||
|
||
/** | ||
* @author Maximilian Beckers <[email protected]> | ||
*/ | ||
|
@@ -31,9 +33,9 @@ public static function fromAmazonRequest(array $amazonRequest): self | |
{ | ||
$device = new self(); | ||
|
||
$device->deviceId = isset($amazonRequest['deviceId']) ? $amazonRequest['deviceId'] : null; | ||
$device->deviceId = PropertyHelper::checkNullValueString($amazonRequest, 'deviceId'); | ||
$device->supportedInterfaces = isset($amazonRequest['supportedInterfaces']) ? (array) $amazonRequest['supportedInterfaces'] : []; | ||
$device->accessToken = isset($amazonRequest['accessToken']) ? $amazonRequest['accessToken'] : null; | ||
$device->accessToken = PropertyHelper::checkNullValueString($amazonRequest, 'accessToken'); | ||
|
||
return $device; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
namespace MaxBeckers\AmazonAlexa\Request\Device; | ||
|
||
use MaxBeckers\AmazonAlexa\Helper\PropertyHelper; | ||
|
||
/** | ||
* @author Maximilian Beckers <[email protected]> | ||
*/ | ||
|
@@ -56,14 +58,14 @@ public static function fromApiResponse(array $amazonApiResponse): self | |
{ | ||
$deviceAddressInformation = new self(); | ||
|
||
$deviceAddressInformation->stateOrRegion = isset($amazonApiResponse['stateOrRegion']) ? $amazonApiResponse['stateOrRegion'] : null; | ||
$deviceAddressInformation->city = isset($amazonApiResponse['city']) ? $amazonApiResponse['city'] : null; | ||
$deviceAddressInformation->countryCode = isset($amazonApiResponse['countryCode']) ? $amazonApiResponse['countryCode'] : null; | ||
$deviceAddressInformation->postalCode = isset($amazonApiResponse['postalCode']) ? $amazonApiResponse['postalCode'] : null; | ||
$deviceAddressInformation->addressLine1 = isset($amazonApiResponse['addressLine1']) ? $amazonApiResponse['addressLine1'] : null; | ||
$deviceAddressInformation->addressLine2 = isset($amazonApiResponse['addressLine2']) ? $amazonApiResponse['addressLine2'] : null; | ||
$deviceAddressInformation->addressLine3 = isset($amazonApiResponse['addressLine3']) ? $amazonApiResponse['addressLine3'] : null; | ||
$deviceAddressInformation->districtOrCounty = isset($amazonApiResponse['districtOrCounty']) ? $amazonApiResponse['districtOrCounty'] : null; | ||
$deviceAddressInformation->stateOrRegion = PropertyHelper::checkNullValueString($amazonApiResponse, 'stateOrRegion'); | ||
$deviceAddressInformation->city = PropertyHelper::checkNullValueString($amazonApiResponse, 'city'); | ||
$deviceAddressInformation->countryCode = PropertyHelper::checkNullValueString($amazonApiResponse, 'countryCode'); | ||
$deviceAddressInformation->postalCode = PropertyHelper::checkNullValueString($amazonApiResponse, 'postalCode'); | ||
$deviceAddressInformation->addressLine1 = PropertyHelper::checkNullValueString($amazonApiResponse, 'addressLine1'); | ||
$deviceAddressInformation->addressLine2 = PropertyHelper::checkNullValueString($amazonApiResponse, 'addressLine2'); | ||
$deviceAddressInformation->addressLine3 = PropertyHelper::checkNullValueString($amazonApiResponse, 'addressLine3'); | ||
$deviceAddressInformation->districtOrCounty = PropertyHelper::checkNullValueString($amazonApiResponse, 'districtOrCounty'); | ||
|
||
return $deviceAddressInformation; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
namespace MaxBeckers\AmazonAlexa\Request\Request\AlexaSkillEvent; | ||
|
||
use MaxBeckers\AmazonAlexa\Helper\PropertyHelper; | ||
|
||
/** | ||
* @author Maximilian Beckers <[email protected]> | ||
*/ | ||
|
@@ -21,7 +23,7 @@ public static function fromAmazonRequest(array $amazonRequest): self | |
{ | ||
$permission = new self(); | ||
|
||
$permission->scope = isset($amazonRequest['scope']) ? $amazonRequest['scope'] : null; | ||
$permission->scope = PropertyHelper::checkNullValueString($amazonRequest, 'scope'); | ||
|
||
return $permission; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
namespace MaxBeckers\AmazonAlexa\Request\Request\AlexaSkillEvent; | ||
|
||
use MaxBeckers\AmazonAlexa\Helper\PropertyHelper; | ||
|
||
/** | ||
* @author Maximilian Beckers <[email protected]> | ||
*/ | ||
|
@@ -21,7 +23,7 @@ public static function fromAmazonRequest(array $amazonRequest): self | |
{ | ||
$body = new self(); | ||
|
||
$body->accessToken = isset($amazonRequest['accessToken']) ? $amazonRequest['accessToken'] : null; | ||
$body->accessToken = PropertyHelper::checkNullValueString($amazonRequest, 'accessToken'); | ||
|
||
return $body; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
namespace MaxBeckers\AmazonAlexa\Request\Request\AlexaSkillEvent; | ||
|
||
use MaxBeckers\AmazonAlexa\Helper\PropertyHelper; | ||
|
||
/** | ||
* @author Maximilian Beckers <[email protected]> | ||
*/ | ||
|
@@ -24,7 +26,7 @@ public static function fromAmazonRequest(array $amazonRequest): self | |
{ | ||
$body = new self(); | ||
|
||
$body->userInformationPersistenceStatus = isset($amazonRequest['userInformationPersistenceStatus']) ? $amazonRequest['userInformationPersistenceStatus'] : null; | ||
$body->userInformationPersistenceStatus = PropertyHelper::checkNullValueString($amazonRequest, 'userInformationPersistenceStatus'); | ||
|
||
return $body; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.