Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

Commit

Permalink
Style fixes on main source.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Mar 10, 2017
1 parent 88740de commit 9c839c2
Show file tree
Hide file tree
Showing 36 changed files with 719 additions and 469 deletions.
15 changes: 11 additions & 4 deletions library/ZendService/Amazon/AbstractAmazon.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ abstract class AbstractAmazon
/**
* @var string Format to use for Date header
*/
const AMAZON_DATE_FORMAT='D, d M Y H:i:s \G\M\T';
const AMAZON_DATE_FORMAT = 'D, d M Y H:i:s \G\M\T';

/**
* Constructor
Expand Down Expand Up @@ -112,18 +112,22 @@ public function getHttpClient()
*/
public function setRequestDate(DateTime $date = null, $preserve = null)
{
if ($date instanceof DateTime && !is_null($preserve)) {
if ($date instanceof DateTime && ! is_null($preserve)) {
$date->{self::DATE_PRESERVE_KEY} = (boolean) $preserve;
}

$this->requestDate = $date;
}

// TODO: Unsuppress standards checking when underscores removed from method names
// @codingStandardsIgnoreStart

/**
* Method to fetch the Access Key
*
* @return string
* @throws Exception\InvalidArgumentException
* @deprecated Underscore should be removed from method name
*/
protected function _getAccessKey()
{
Expand All @@ -139,6 +143,7 @@ protected function _getAccessKey()
*
* @return string
* @throws Exception\InvalidArgumentException
* @deprecated Underscore should be removed from method name
*/
protected function _getSecretKey()
{
Expand All @@ -149,6 +154,8 @@ protected function _getSecretKey()
return $this->secretKey;
}

// @codingStandardsIgnoreEnd

/**
* Method to get the Response object of the last call to the service,
* null if no call was done or no response was obtained
Expand All @@ -171,7 +178,7 @@ public function getLastResponse()
*/
public function getRequestDate()
{
if (!is_object($this->requestDate)) {
if (! is_object($this->requestDate)) {
$date = new DateTime();
} else {
$date = $this->requestDate;
Expand All @@ -195,7 +202,7 @@ public function getRequestDate()
*/
public function getRequestIsoDate()
{
if (!is_object($this->requestDate)) {
if (! is_object($this->requestDate)) {
$date = new DateTime();
} else {
$date = $this->requestDate;
Expand Down
2 changes: 1 addition & 1 deletion library/ZendService/Amazon/Accessories.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(DOMElement $dom)
{
$xpath = new DOMXPath($dom->ownerDocument);
$xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/' . Amazon::getVersion());
foreach (array('ASIN', 'Title') as $el) {
foreach (['ASIN', 'Title'] as $el) {
$this->$el = (string) $xpath->query("./az:$el/text()", $dom)->item(0)->data;
}
}
Expand Down
45 changes: 30 additions & 15 deletions library/ZendService/Amazon/Amazon.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ class Amazon
public $appId;

/**
* API Version
*
* @var string
*/
protected $_secretKey = null;
protected static $version = '2011-08-01';

// TODO: Unsuppress standards checking when underscores removed from property names
// @codingStandardsIgnoreStart

/**
* API Version
*
* @var string
*/
protected static $version = '2011-08-01';
protected $_secretKey = null;

/**
* @var string
Expand All @@ -51,12 +54,12 @@ class Amazon
*
* @var array
*/
protected $_baseUriList = array('US' => 'http://webservices.amazon.com',
protected $_baseUriList = ['US' => 'http://webservices.amazon.com',
'UK' => 'http://webservices.amazon.co.uk',
'DE' => 'http://webservices.amazon.de',
'JP' => 'http://webservices.amazon.co.jp',
'FR' => 'http://webservices.amazon.fr',
'CA' => 'http://webservices.amazon.ca');
'CA' => 'http://webservices.amazon.ca'];

/**
* Reference to REST client object
Expand All @@ -65,6 +68,7 @@ class Amazon
*/
protected $_rest = null;

// @codingStandardsIgnoreEnd

/**
* Constructs a new Amazon Web Services Client
Expand All @@ -81,12 +85,12 @@ public function __construct($appId, $countryCode = 'US', $secretKey = null, $ver
$this->appId = (string) $appId;
$this->_secretKey = $secretKey;

if (!is_null($version)) {
if (! is_null($version)) {
self::setVersion($version);
}

$countryCode = (string) $countryCode;
if (!isset($this->_baseUriList[$countryCode])) {
if (! isset($this->_baseUriList[$countryCode])) {
throw new Exception\InvalidArgumentException("Unknown country code: $countryCode");
}

Expand All @@ -107,7 +111,7 @@ public function itemSearch(array $options)
$client = $this->getRestClient();
$client->setUri($this->_baseUri);

$defaultOptions = array('ResponseGroup' => 'Small');
$defaultOptions = ['ResponseGroup' => 'Small'];
$options = $this->_prepareOptions('ItemSearch', $options, $defaultOptions);
$client->getHttpClient()->resetParameters();
$response = $client->restGet('/onca/xml', $options);
Expand All @@ -134,13 +138,13 @@ public function itemSearch(array $options)
* @throws Exception\RuntimeException
* @return Item|ResultSet
*/
public function itemLookup($asin, array $options = array())
public function itemLookup($asin, array $options = [])
{
$client = $this->getRestClient();
$client->setUri($this->_baseUri);
$client->getHttpClient()->resetParameters();

$defaultOptions = array('ResponseGroup' => 'Small');
$defaultOptions = ['ResponseGroup' => 'Small'];
$options['ItemId'] = (string) $asin;
$options = $this->_prepareOptions('ItemLookup', $options, $defaultOptions);
$response = $client->restGet('/onca/xml', $options);
Expand Down Expand Up @@ -191,6 +195,8 @@ public function setRestClient(RestClient $client)
return $this;
}

// TODO: Unsuppress standards checking when underscores removed from method name
// @codingStandardsIgnoreStart

/**
* Prepare options for request
Expand All @@ -199,6 +205,7 @@ public function setRestClient(RestClient $client)
* @param array $options User supplied options
* @param array $defaultOptions Default options
* @return array
* @deprecated Underscore should be removed from method name
*/
protected function _prepareOptions($query, array $options, array $defaultOptions)
{
Expand All @@ -211,7 +218,7 @@ protected function _prepareOptions($query, array $options, array $defaultOptions
if (isset($options['ResponseGroup'])) {
$responseGroup = explode(',', $options['ResponseGroup']);

if (!in_array('Request', $responseGroup)) {
if (! in_array('Request', $responseGroup)) {
$responseGroup[] = 'Request';
$options['ResponseGroup'] = implode(',', $responseGroup);
}
Expand All @@ -228,6 +235,8 @@ protected function _prepareOptions($query, array $options, array $defaultOptions
return $options;
}

// @codingStandardsIgnoreEnd

/**
* Compute Signature for Authentication with Amazon Product Advertising Webservices
*
Expand All @@ -254,24 +263,28 @@ public static function computeSignature($baseUri, $secretKey, array $options)
public static function buildRawSignature($baseUri, $options)
{
ksort($options);
$params = array();
$params = [];
foreach ($options as $k => $v) {
$params[] = $k."=".rawurlencode($v);
}

return sprintf("GET\n%s\n/onca/xml\n%s",
return sprintf(
"GET\n%s\n/onca/xml\n%s",
str_replace('http://', '', $baseUri),
implode("&", $params)
);
}

// TODO: Unsuppress standards checking when underscores removed from method name
// @codingStandardsIgnoreStart

/**
* Check result for errors
*
* @param DOMDocument $dom
* @throws Exception\RuntimeException
* @return void
* @deprecated Underscore should be removed from method name
*/
protected static function _checkErrors(DOMDocument $dom)
{
Expand All @@ -291,6 +304,8 @@ protected static function _checkErrors(DOMDocument $dom)
}
}

// @codingStandardsIgnoreEnd

/**
* Set the Amazon API version
*
Expand All @@ -299,7 +314,7 @@ protected static function _checkErrors(DOMDocument $dom)
*/
public static function setVersion($version)
{
if (!preg_match('/\d{4}-\d{2}-\d{2}/', $version)) {
if (! preg_match('/\d{4}-\d{2}-\d{2}/', $version)) {
throw new Exception\InvalidArgumentException("$version is an invalid API Version");
}
self::$version = $version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
abstract class AbstractAuthentication
{
// TODO: Unsuppress standards checking when underscores removed from property names
// @codingStandardsIgnoreStart

/**
* @var string
*/
Expand All @@ -32,6 +35,8 @@ abstract class AbstractAuthentication
*/
protected $_apiVersion;

// @codingStandardsIgnoreEnd

/**
* Constructor
*
Expand Down
6 changes: 3 additions & 3 deletions library/ZendService/Amazon/Authentication/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class S3 extends AbstractAuthentication
public function generateSignature($method, $path, &$headers)
{
if (! is_array($headers)) {
$headers = array($headers);
$headers = [$headers];
}

$type = $md5 = $date = '';
Expand All @@ -55,7 +55,7 @@ public function generateSignature($method, $path, &$headers)

// For x-amz- headers, combine like keys, lowercase them, sort them
// alphabetically and remove excess spaces around values
$amz_headers = array();
$amz_headers = [];
foreach ($headers as $key => $val) {
$key = strtolower($key);
if (substr($key, 0, 6) == 'x-amz-') {
Expand All @@ -66,7 +66,7 @@ public function generateSignature($method, $path, &$headers)
}
}
}
if (!empty($amz_headers)) {
if (! empty($amz_headers)) {
ksort($amz_headers);
foreach ($amz_headers as $key => $val) {
$sig_str .= $key . ':' . implode(',', $val) . "\n";
Expand Down
14 changes: 12 additions & 2 deletions library/ZendService/Amazon/Authentication/V1.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
class V1 extends AbstractAuthentication
{
// TODO: Unsuppress standards checking when underscores removed from property names
// @codingStandardsIgnoreStart

/**
* Signature Version
*/
Expand All @@ -29,6 +32,8 @@ class V1 extends AbstractAuthentication
*/
protected $_signatureMethod = 'HmacSHA256';

// @codingStandardsIgnoreEnd

/**
* Generate the required attributes for the signature
* @param string $url
Expand All @@ -40,15 +45,18 @@ public function generateSignature($url, array &$parameters)
$parameters['AWSAccessKeyId'] = $this->_accessKey;
$parameters['SignatureVersion'] = $this->_signatureVersion;
$parameters['Version'] = $this->_apiVersion;
if (!isset($parameters['Timestamp'])) {
$parameters['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z', time()+10);
if (! isset($parameters['Timestamp'])) {
$parameters['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z', time() + 10);
}

$data = $this->_signParameters($url, $parameters);

return $data;
}

// TODO: Unsuppress standards checking when underscores removed from property names
// @codingStandardsIgnoreStart

/**
* Computes the RFC 2104-compliant HMAC signature for request parameters
*
Expand All @@ -68,6 +76,7 @@ public function generateSignature($url, array &$parameters)
* @param array $parameters the parameters for which to get the signature.
*
* @return string the signed data.
* @deprecated Underscore should be removed from method name
*/
protected function _signParameters($url, array &$parameters)
{
Expand All @@ -86,4 +95,5 @@ protected function _signParameters($url, array &$parameters)

return $data;
}
// @codingStandardsIgnoreEnd
}
Loading

0 comments on commit 9c839c2

Please sign in to comment.