Lookup   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
c 1
b 0
f 0
lcom 2
cbo 1
dl 0
loc 155
rs 10
ccs 40
cts 40
cp 1

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A setItemIds() 0 11 2
A getItemId() 0 4 1
A setItemId() 0 6 1
A getIdType() 0 4 1
B setIdType() 0 26 4
A getSearchIndex() 0 4 1
A setSearchIndex() 0 6 1
A getCondition() 0 4 1
A setCondition() 0 6 1
1
<?php
2
/*
3
 * Copyright 2016 Jan Eichhorn <[email protected]>
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace ApaiIO\Operations;
19
20
/**
21
 * A item lookup operation
22
 *
23
 * @see    http://docs.aws.amazon.com/AWSECommerceService/2011-08-01/DG/ItemLookup.html
24
 * @author Jan Eichhorn <[email protected]>
25
 *
26
 * @method Lookup setMerchantId(string $merchantId)
27
 */
28
class Lookup extends AbstractOperation
29
{
30
    const TYPE_ASIN = 'ASIN';
31
    const TYPE_SKU = 'SKU';
32
    const TYPE_UPC = 'UPC';
33
    const TYPE_EAN = 'EAN';
34
    const TYPE_ISBN = 'ISBN';
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 4
    public function getName()
40
    {
41 4
        return 'ItemLookup';
42
    }
43
44
    /**
45
     * Pass up to 10 itemid's which should be looked up
46
     *
47
     * @param array $itemIds
48
     *
49
     * @return Lookup
50
     *
51
     * @throws \Exception
52
     */
53 2
    public function setItemIds(array $itemIds)
54
    {
55 2
        if (count($itemIds) > 10) {
56 1
            throw new \Exception('setItemIds accepts not more then 10 itemid\'s at once');
57
        }
58
59 1
        $asinString = implode(',', $itemIds);
60 1
        $this->setItemId($asinString);
61
62 1
        return $this;
63
    }
64
65
    /**
66
     * Returns the itemid
67
     *
68
     * @return string
69
     */
70 2
    public function getItemId()
71
    {
72 2
        return $this->getSingleOperationParameter('ItemId');
73
    }
74
75
    /**
76
     * Sets the itemid which should be looked up
77
     *
78
     * @param string $itemId
79
     *
80
     * @return \ApaiIO\Operations\Lookup
81
     */
82 5
    public function setItemId($itemId)
83
    {
84 5
        $this->parameters['ItemId'] = $itemId;
85
86 5
        return $this;
87
    }
88
89
    /**
90
     * Returns the idtype either ASIN (Default), SKU, UPC, EAN, and ISBN
91
     *
92
     * @return string
93
     */
94 1
    public function getIdType()
95
    {
96 1
        return $this->getSingleOperationParameter('IdType');
97
    }
98
99
    /**
100
     * Sets the idtype either ASIN (Default), SKU, UPC, EAN, and ISBN
101
     *
102
     * @param string $idType
103
     *
104
     * @return \ApaiIO\Operations\Lookup
105
     */
106 7
    public function setIdType($idType)
107
    {
108
        $idTypes = [
109 7
            self::TYPE_ASIN,
110 7
            self::TYPE_SKU,
111 7
            self::TYPE_UPC,
112 7
            self::TYPE_EAN,
113 7
            self::TYPE_ISBN
114
        ];
115
116 7
        if (!in_array($idType, $idTypes)) {
117 1
            throw new \InvalidArgumentException(sprintf(
118 1
                "Invalid type '%s' passed. Valid types are: '%s'",
119 1
                $idType,
120 1
                implode(', ', $idTypes)
121
            ));
122
        }
123
124 6
        $this->parameters['IdType'] = $idType;
125
126 6
        if (empty($this->parameters['SearchIndex']) && $idType != self::TYPE_ASIN) {
127 5
            $this->parameters['SearchIndex'] = 'All';
128
        }
129
130 6
        return $this;
131
    }
132
133
    /**
134
     * Returns the searchindex
135
     *
136
     * @return mixed
137
     */
138 1
    public function getSearchIndex()
139
    {
140 1
        return $this->getSingleOperationParameter('SearchIndex');
141
    }
142
143
    /**
144
     * Sets the searchindex which should be used when set IdType other than ASIN
145
     *
146
     * @param string $searchIndex
147
     *
148
     * @return \ApaiIO\Operations\Lookup
149
     */
150 1
    public function setSearchIndex($searchIndex)
151
    {
152 1
        $this->parameters['SearchIndex'] = $searchIndex;
153
154 1
        return $this;
155
    }
156
157
    /**
158
     * Returns the condition of the items to return. New | Used | Collectible | Refurbished | All
159
     *
160
     * @return string
161
     */
162 2
    public function getCondition()
163
    {
164 2
        return $this->getSingleOperationParameter('Condition');
165
    }
166
167
    /**
168
     * Sets the condition of the items to return: New | Used | Collectible | Refurbished | All
169
     *
170
     * Defaults to New.
171
     *
172
     * @param string $condition
173
     *
174
     * @return \ApaiIO\Operations\Search
175
     */
176 2
    public function setCondition($condition)
177
    {
178 2
        $this->parameters['Condition'] = $condition;
179
180 2
        return $this;
181
    }
182
}
183