CustomerAddressEndpoint::findOne()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
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 CustomerAddressEndpoint extends AbstractEndpoint
11
{
12
    /**
13
     * @param int $customerId
14
     * @return array
15
     */
16
    public function findByCustomer($customerId)
17
    {
18
        $request = new GetJson('/admin/customers/' . $customerId . '.json');
19
        $response = $this->sendPaged($request, 'addresses');
20
        return $this->createCollection($response);
21
    }
22
23
    /**
24
     * @param int $customerId
25
     * @param int $addressId
26
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
27
     */
28
    public function findOne($customerId, $addressId)
29
    {
30
        $request = new GetJson('/admin/customers/' . $customerId . '/addresses/' . $addressId . '.json');
31
        $response = $this->send($request);
32
        return $this->createEntity($response->get('customer_address'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('customer_address') 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

32
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('customer_address'));
Loading history...
33
    }
34
35
    /**
36
     * @param int $customerId
37
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $address
38
     * @return GenericResource
39
     */
40
    public function create($customerId, GenericResource $address)
41
    {
42
        $request = new PostJson('/admin/customers/' . $customerId . '/addresses.json', array('address' => $address->toArray()));
43
        $response = $this->send($request);
44
        return $this->createEntity($response->get('customer_address'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('customer_address') 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

44
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('customer_address'));
Loading history...
45
    }
46
47
    /**
48
     * @param int $customerId
49
     * @param int $addressId
50
     * @param GenericResource $address
51
     * @return GenericResource
52
     */
53
    public function update($customerId, $addressId, GenericResource $address)
54
    {
55
        $request = new PutJson('/admin/customers/' . $customerId . '/addresses/' . $addressId . '.json', array('address' => $address->toArray()));
56
        $response = $this->send($request);
57
        return $this->createEntity($response->get('customer_address'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('customer_address') 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

57
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('customer_address'));
Loading history...
58
    }
59
60
    /**
61
     * @param int $customerId
62
     * @param int $addressId
63
     */
64
    public function delete($customerId, $addressId)
65
    {
66
        $request = new DeleteParams('/admin/customers/' . $customerId . '/addresses/' . $addressId . '.json');
67
        $this->send($request);
68
    }
69
70
    /**
71
     * @param int $customerId
72
     * @param array $addressIds
73
     * @param array $bulkOperation
74
     */
75
    public function bulkOperation($customerId, array $addressIds, $bulkOperation)
76
    {
77
        $queryString = array();
78
79
        foreach ($addressIds as $addressId) {
80
            $queryString[] = 'address_ids[]=' . $addressId;
81
        }
82
83
        $queryString[] = 'operation=' . $bulkOperation;
0 ignored issues
show
Bug introduced by
Are you sure $bulkOperation of type array can be used in concatenation? ( Ignorable by Annotation )

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

83
        $queryString[] = 'operation=' . /** @scrutinizer ignore-type */ $bulkOperation;
Loading history...
84
85
        $request = new PutJson('/admin/customers/' . $customerId . '/addresses/set.json?' . implode('&', $queryString));
86
        $this->send($request);
87
    }
88
89
    /**
90
     * @param int $customerId
91
     * @param int $addressId
92
     */
93
    public function setAsDefault($customerId, $addressId)
94
    {
95
        $request = new PutJson('/admin/customers/' . $customerId . '/addresses/' . $addressId . '/default.json');
96
        $this->send($request);
97
    }
98
}
99