1 | <?php namespace Packback\Prices\Clients; |
||
8 | class AmazonPriceClient extends PriceClient |
||
9 | { |
||
10 | const RETAILER = 'amazon'; |
||
11 | |||
12 | public $conf; |
||
13 | public $container; |
||
14 | public $search; |
||
15 | |||
16 | 16 | public function __construct($config = []) |
|
23 | |||
24 | 16 | public function setConfiguration($config = []) |
|
25 | { |
||
26 | 16 | $this->conf |
|
27 | 16 | ->setCountry('com') |
|
28 | 16 | ->setAccessKey($config['access_key']) |
|
29 | 16 | ->setSecretKey($config['secret_key']) |
|
30 | 16 | ->setAssociateTag($config['associate_tag']); |
|
31 | 16 | $this->conf->setResponseTransformer('\ApaiIO\ResponseTransformer\XmlToSimpleXmlObject'); |
|
32 | 16 | } |
|
33 | |||
34 | 6 | public function getPricesForIsbns($isbns = []) |
|
35 | { |
||
36 | 6 | $isbn_groups = []; |
|
37 | |||
38 | 6 | if (count($isbns) > 10) { |
|
39 | 2 | $isbn_groups = array_chunk($isbns, 10); |
|
40 | 2 | } else { |
|
41 | 4 | array_push($isbn_groups, $isbns); |
|
42 | } |
||
43 | 6 | foreach ($isbn_groups as $isbn_group) { |
|
44 | 6 | $response = $this->addParam('Condition', 'New') |
|
|
|||
45 | 6 | ->addParam('IdType', 'ISBN') |
|
46 | 6 | ->addParam('ItemId', $isbn_group) |
|
47 | 6 | ->addParam('Condition', 'All') |
|
48 | 6 | ->addParam('SearchIndex', 'Books') |
|
49 | 6 | ->addParam('Operation', 'ItemLookup') |
|
50 | 6 | ->addParam('Version', '2011-08-01') |
|
51 | 6 | ->addParam('ResponseGroup', ['Large']) |
|
52 | 6 | ->addParam('Service', 'AWSECommerceService'); |
|
53 | |||
54 | // Get response for Marketplace books |
||
55 | 6 | $response = $this->send(); |
|
56 | // If there is an error with the API key, throw an exception |
||
57 | 6 | if (isset($response->Error)) { |
|
58 | throw new \Exception($response->Error->Code.': '.$response->Error->Message); |
||
59 | } |
||
60 | 6 | $this->addPricesToCollection($response); |
|
61 | // Get response for only Amazon books |
||
62 | 6 | $response = $this->addParam('MerchantId', 'Amazon')->send(); |
|
63 | 6 | $this->addPricesToCollection($response); |
|
64 | 6 | } |
|
65 | |||
66 | 6 | return $this->collection; |
|
67 | } |
||
68 | |||
69 | 6 | public function addPricesToCollection($response) |
|
90 | |||
91 | 10 | public function populatePriceData($offer, $item, $merchant_id) |
|
115 | |||
116 | 6 | public function addParam($key, $value) |
|
121 | |||
122 | 10 | public function send() |
|
123 | { |
||
127 | } |
||
128 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.