Passed
Pull Request — master (#10)
by Daniel
03:13
created

MetafieldEndpoint::findCustomerMetafields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php
2
namespace CodeCloud\Bundle\ShopifyBundle\Api\Endpoint;
3
4
use CodeCloud\Bundle\ShopifyBundle\Api\Request\DeleteParams;
5
use CodeCloud\Bundle\ShopifyBundle\Api\Request\GetJson;
6
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PostJson;
7
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PutJson;
8
use CodeCloud\Bundle\ShopifyBundle\Api\GenericResource;
9
10
class MetafieldEndpoint extends AbstractEndpoint
11
{
12
    /**
13
     * @param int $customerId
14
     * @param array $query
15
     * @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[]
16
     */
17
    public function findCustomerMetafields($customerId, array $query = array())
18
    {
19
        $request = new GetJson('/admin/customers/' . $customerId . '/metafields.json', $query);
20
        $response = $this->sendPaged($request, 'metafields');
21
        return $this->createCollection($response);
22
    }
23
24
    /**
25
     * @param array $query
26
     * @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[]
27
     */
28
    public function findStoreMetafields(array $query = array())
29
    {
30
        $request = new GetJson('/admin/metafields.json', $query);
31
        $response = $this->sendPaged($request, 'metafields');
32
        return $this->createCollection($response);
33
    }
34
35
    /**
36
     * @param int $productId
37
     * @param array $query
38
     * @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[]
39
     */
40
    public function findProductMetafields($productId, array $query = array())
41
    {
42
        $request = new GetJson('/admin/products/' . $productId . '/metafields.json', $query);
43
        $response = $this->sendPaged($request, 'metafields');
44
        return $this->createCollection($response);
45
    }
46
47
    /**
48
     * @param int $productImageId
49
     * @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[]
50
     */
51
    public function findProductImageMetafields($productImageId)
52
    {
53
        $params = array(
54
            'metafield[owner_id]'       => $productImageId,
55
            'metafield[owner_resource]' => 'product_image'
56
        );
57
58
        $request = new GetJson('/admin/metafields.json', $params);
59
        $response = $this->sendPaged($request, 'metafields');
60
        return $this->createCollection($response);
61
    }
62
63
    /**
64
     * @param int $metafieldId
65
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
66
     */
67
    public function findOneCustomerMetafield($metafieldId, $customerId)
68
    {
69
        $request = new GetJson('/admin/customers/' . $customerId . '/metafields/' . $metafieldId . '.json');
70
        $response = $this->send($request);
71
        return $this->createEntity($response->get('metafield'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('metafield') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

71
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('metafield'));
Loading history...
72
    }
73
74
    /**
75
     * @param int $metafieldId
76
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
77
     */
78
    public function findOneStoreMetafield($metafieldId)
79
    {
80
        $request = new GetJson('/admin/metafields/' . $metafieldId . '.json');
81
        $response = $this->send($request);
82
        return $this->createEntity($response->get('metafield'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('metafield') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('metafield'));
Loading history...
83
    }
84
85
    /**
86
     * @param int $metafieldId
87
     * @param int $productId
88
     * @return GenericResource
89
     */
90
    public function findOneProductMetafield($metafieldId, $productId)
91
    {
92
        $request = new GetJson('/admin/products/' . $productId . '/metafields/' . $metafieldId . '.json');
93
        $response = $this->send($request);
94
        return $this->createEntity($response->get('metafield'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('metafield') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

94
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('metafield'));
Loading history...
95
    }
96
97
    /**
98
     * @param int $customerId
99
     * @return int
100
     */
101
    public function countByCustomer($customerId)
102
    {
103
        $request = new GetJson('/admin/customers/' . $customerId . '/metafields/count.json');
104
        $response = $this->send($request);
105
        return $response->get('count');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response->get('count') also could return the type string which is incompatible with the documented return type integer.
Loading history...
106
    }
107
108
    /**
109
     * @return int
110
     */
111
    public function countStoreMetafields()
112
    {
113
        $request = new GetJson('/admin/metafields/count.json');
114
        $response = $this->send($request);
115
        return $response->get('count');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response->get('count') also could return the type string which is incompatible with the documented return type integer.
Loading history...
116
    }
117
118
    /**
119
     * @param int $productId
120
     * @return int
121
     */
122
    public function countByProduct($productId)
123
    {
124
        $request = new GetJson('/admin/products/' . $productId . '/metafields/count.json');
125
        $response = $this->send($request);
126
        return $response->get('count');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response->get('count') also could return the type string which is incompatible with the documented return type integer.
Loading history...
127
    }
128
129
    /**
130
     * @param int $customerId
131
     * @param GenericResource $metafield
132
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
133
     */
134
    public function createCustomerMetafield($customerId, GenericResource $metafield)
135
    {
136
        $request = new PostJson('/admin/customers/' . $customerId . '/metafields.json', array('metafield' => $metafield->toArray()));
137
        $response = $this->send($request);
138
        return $this->createEntity($response->get('metafield'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('metafield') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

138
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('metafield'));
Loading history...
139
    }
140
141
    /**
142
     * @param GenericResource $metafield
143
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
144
     */
145
    public function createStoreMetafield(GenericResource $metafield)
146
    {
147
        $request = new PostJson('/admin/metafields.json', array('metafield' => $metafield->toArray()));
148
        $response = $this->send($request);
149
        return $this->createEntity($response->get('metafield'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('metafield') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

149
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('metafield'));
Loading history...
150
    }
151
152
    /**
153
     * @param int $productId
154
     * @param GenericResource $metafield
155
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
156
     */
157
    public function createProductMetafield($productId, GenericResource $metafield)
158
    {
159
        $request = new PostJson('/admin/products/' . $productId . '/metafields.json', array('metafield' => $metafield->toArray()));
160
        $response = $this->send($request);
161
        return $this->createEntity($response->get('metafield'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('metafield') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

161
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('metafield'));
Loading history...
162
    }
163
164
    /**
165
     * @param int $metafieldId
166
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $metafield
167
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
168
     */
169
    public function updateStoreMetafield($metafieldId, GenericResource $metafield)
170
    {
171
        $request = new PutJson('/admin/metafields/' . $metafieldId . '.json', array('metafield' => $metafield->toArray()));
172
        $response = $this->send($request);
173
        return $this->createEntity($response->get('metafield'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('metafield') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

173
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('metafield'));
Loading history...
174
    }
175
176
    /**
177
     * @param int $metafieldId
178
     * @param int $customerId
179
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $metafield
180
     * @return GenericResource
181
     */
182
    public function updateCustomerMetafield($metafieldId, $customerId, GenericResource $metafield)
183
    {
184
        $request = new PutJson('/admin/products/' . $customerId . '/metafields/' . $metafieldId . '.json', array('metafield' => $metafield->toArray()));
185
        $response = $this->send($request);
186
        return $this->createEntity($response->get('metafield'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('metafield') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

186
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('metafield'));
Loading history...
187
    }
188
189
    /**
190
     * @param int $metafieldId
191
     * @param int $productId
192
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $metafield
193
     * @return GenericResource
194
     */
195
    public function updateProductMetafield($metafieldId, $productId, GenericResource $metafield)
196
    {
197
        $request = new PutJson('/admin/products/' . $productId . '/metafields/' . $metafieldId . '.json', array('metafield' => $metafield->toArray()));
198
        $response = $this->send($request);
199
        return $this->createEntity($response->get('metafield'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('metafield') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

199
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('metafield'));
Loading history...
200
    }
201
202
    /**
203
     * @param int $metafieldId
204
     * @param int $customerId
205
     */
206
    public function deleteCustomerMetafield($metafieldId, $customerId)
207
    {
208
        $request = new DeleteParams('/admin/customers/' . $customerId . '/metafields/' . $metafieldId . '.json');
209
        $this->send($request);
210
    }
211
212
    /**
213
     * @param int $metafieldId
214
     */
215
    public function deleteStoreMetafield($metafieldId)
216
    {
217
        $request = new DeleteParams('/admin/metafields/' . $metafieldId . '.json');
218
        $this->send($request);
219
    }
220
221
    /**
222
     * @param int $metafieldId
223
     * @param int $productId
224
     */
225
    public function deleteProductMetafield($metafieldId, $productId)
226
    {
227
        $request = new DeleteParams('/admin/products/' . $productId . '/metafields/' . $metafieldId . '.json');
228
        $this->send($request);
229
    }
230
}
231