Passed
Pull Request — master (#4)
by Morten Poul
12:59
created

ManagesCustomers::getCustomers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Signifly\Shopify\REST\Actions;
4
5
use Illuminate\Support\Collection;
6
use Signifly\Shopify\REST\Cursor;
7
use Signifly\Shopify\REST\Resources\ApiResource;
8
use Signifly\Shopify\REST\Resources\CustomerResource;
9
use Signifly\Shopify\Shopify;
10
11
/** @mixin Shopify */
12
trait ManagesCustomers
13
{
14
    public function createCustomer(array $data): CustomerResource
15
    {
16
        return $this->createResource('customers', $data);
0 ignored issues
show
Bug introduced by
The method createResource() does not exist on Signifly\Shopify\REST\Actions\ManagesCustomers. Did you maybe mean createCustomer()? ( Ignorable by Annotation )

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

16
        return $this->/** @scrutinizer ignore-call */ createResource('customers', $data);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
17
    }
18
19
    public function getCustomersCount(array $params = []): int
20
    {
21
        return $this->getResourceCount('customers', $params);
0 ignored issues
show
Bug introduced by
It seems like getResourceCount() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

21
        return $this->/** @scrutinizer ignore-call */ getResourceCount('customers', $params);
Loading history...
22
    }
23
24
    public function paginateSearchCustomers(string $query, array $params = []): Cursor
25
    {
26
        return $this->cursor($this->searchCustomers($query, $params));
0 ignored issues
show
Bug introduced by
It seems like cursor() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

26
        return $this->/** @scrutinizer ignore-call */ cursor($this->searchCustomers($query, $params));
Loading history...
27
    }
28
29
    public function searchCustomers(string $query, array $params = []): Collection
30
    {
31
        $response = $this->get('customers/search.json', ['query' => $query] + $params);
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

31
        /** @scrutinizer ignore-call */ 
32
        $response = $this->get('customers/search.json', ['query' => $query] + $params);
Loading history...
32
33
        return $this->transformCollection($response['customers'], CustomerResource::class);
0 ignored issues
show
Bug introduced by
It seems like transformCollection() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

33
        return $this->/** @scrutinizer ignore-call */ transformCollection($response['customers'], CustomerResource::class);
Loading history...
34
    }
35
36
    public function paginateCustomers(array $params = []): Cursor
37
    {
38
        return $this->cursor($this->getCustomers($params));
39
    }
40
41
    public function getCustomers(array $params = []): Collection
42
    {
43
        return $this->getResources('customers', $params);
0 ignored issues
show
Bug introduced by
It seems like getResources() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

43
        return $this->/** @scrutinizer ignore-call */ getResources('customers', $params);
Loading history...
44
    }
45
46
    public function getCustomer($customerId): CustomerResource
47
    {
48
        return $this->getResource('customers', $customerId);
0 ignored issues
show
Bug introduced by
It seems like getResource() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

48
        return $this->/** @scrutinizer ignore-call */ getResource('customers', $customerId);
Loading history...
49
    }
50
51
    public function updateCustomer($customerId, $data): CustomerResource
52
    {
53
        return $this->updateResource('customers', $customerId, $data);
0 ignored issues
show
Bug introduced by
The method updateResource() does not exist on Signifly\Shopify\REST\Actions\ManagesCustomers. Did you maybe mean updateCustomer()? ( Ignorable by Annotation )

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

53
        return $this->/** @scrutinizer ignore-call */ updateResource('customers', $customerId, $data);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
    }
55
56
    public function deleteCustomer($customerId): void
57
    {
58
        $this->deleteResource('customers', $customerId);
0 ignored issues
show
Bug introduced by
The method deleteResource() does not exist on Signifly\Shopify\REST\Actions\ManagesCustomers. Did you maybe mean deleteCustomer()? ( Ignorable by Annotation )

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

58
        $this->/** @scrutinizer ignore-call */ 
59
               deleteResource('customers', $customerId);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
    }
60
61
    public function createCustomerAccountActivationUrl($customerId): string
62
    {
63
        return $this->post("customers/{$customerId}/account_activation_url.json")['account_activation_url'];
0 ignored issues
show
Bug introduced by
It seems like post() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

63
        return $this->/** @scrutinizer ignore-call */ post("customers/{$customerId}/account_activation_url.json")['account_activation_url'];
Loading history...
64
    }
65
66
    public function sendCustomerInvite($customerId, array $data = []): ApiResource
67
    {
68
        $response = $this->post("customers/{$customerId}/send_invite.json", ['customer_invite' => $data]);
69
70
        return new ApiResource($response['customer_invite'], $this);
71
    }
72
73
    public function paginateCustomerOrders($customerId, array $params = []): Cursor
74
    {
75
        return $this->cursor($this->getCustomerOrders($customerId, $params));
76
    }
77
78
    public function getCustomerOrders($customerId, array $params = []): Collection
79
    {
80
        return $this->getResources('orders', $params, ['customers', $customerId]);
81
    }
82
83
    public function createCustomerAddress($customerId, array $data): ApiResource
84
    {
85
        return $this->createResource('addresses', $data, ['customers', $customerId]);
86
    }
87
88
    public function getCustomerAddresses($customerId, array $params = []): Collection
89
    {
90
        return $this->getResources('addresses', $params, ['customers', $customerId]);
91
    }
92
93
    public function getCustomerAddress($customerId, $addressId): ApiResource
94
    {
95
        return $this->getResource('addresses', $addressId, ['customers', $customerId]);
96
    }
97
98
    public function updateCustomerAddress($customerId, $addressId, $data): ApiResource
99
    {
100
        return $this->updateResource('addresses', $addressId, $data, ['customers', $customerId]);
101
    }
102
103
    public function deleteCustomerAddress($customerId, $addressId): void
104
    {
105
        $this->deleteResource('addresses', $addressId, ['customers', $customerId]);
106
    }
107
108
    public function setDefaultCustomerAddress($customerId, $addressId): ApiResource
109
    {
110
        $response = $this->put("customers/{$customerId}/addresses/{$addressId}/default.json");
0 ignored issues
show
Bug introduced by
It seems like put() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

110
        /** @scrutinizer ignore-call */ 
111
        $response = $this->put("customers/{$customerId}/addresses/{$addressId}/default.json");
Loading history...
111
112
        return new ApiResource($response['customer_address'], $this);
113
    }
114
}
115