ManagesCollections::deleteCustomCollection()   A
last analyzed

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\CollectResource;
9
use Signifly\Shopify\REST\Resources\CustomCollectionResource;
10
use Signifly\Shopify\REST\Resources\ProductResource;
11
use Signifly\Shopify\REST\Resources\SmartCollectionResource;
12
use Signifly\Shopify\Shopify;
13
14
/** @mixin Shopify */
15
trait ManagesCollections
16
{
17
    public function createCustomCollection(array $data): CustomCollectionResource
18
    {
19
        $response = $this->post('custom_collections.json', ['custom_collection' => $data]);
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

19
        /** @scrutinizer ignore-call */ 
20
        $response = $this->post('custom_collections.json', ['custom_collection' => $data]);
Loading history...
20
21
        return new CustomCollectionResource($response['custom_collection'], $this);
22
    }
23
24
    public function getCustomCollectionsCount(array $params = []): int
25
    {
26
        $response = $this->get('custom_collections/count.json', $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

26
        /** @scrutinizer ignore-call */ 
27
        $response = $this->get('custom_collections/count.json', $params);
Loading history...
27
28
        return $response['count'] ?? 0;
29
    }
30
31
    public function paginateCustomCollections(array $params): Cursor
32
    {
33
        return $this->cursor($this->getCustomCollections($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

33
        return $this->/** @scrutinizer ignore-call */ cursor($this->getCustomCollections($params));
Loading history...
34
    }
35
36
    public function getCustomCollections(array $params = []): Collection
37
    {
38
        $response = $this->get('custom_collections.json', $params);
39
40
        return $this->transformCollection($response['custom_collections'], CustomCollectionResource::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

40
        return $this->/** @scrutinizer ignore-call */ transformCollection($response['custom_collections'], CustomCollectionResource::class);
Loading history...
41
    }
42
43
    public function getCustomCollection($collectionId): CustomCollectionResource
44
    {
45
        $response = $this->get("custom_collections/{$collectionId}.json");
46
47
        return new CustomCollectionResource($response['custom_collection'], $this);
48
    }
49
50
    public function updateCustomCollection($collectionId, array $data): CustomCollectionResource
51
    {
52
        $response = $this->put("custom_collections/{$collectionId}.json", ['custom_collection' => $data]);
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

52
        /** @scrutinizer ignore-call */ 
53
        $response = $this->put("custom_collections/{$collectionId}.json", ['custom_collection' => $data]);
Loading history...
53
54
        return new CustomCollectionResource($response['custom_collection'], $this);
55
    }
56
57
    public function deleteCustomCollection($collectionId): void
58
    {
59
        $this->delete("custom_collections/{$collectionId}.json");
0 ignored issues
show
Bug introduced by
The method delete() does not exist on Signifly\Shopify\REST\Actions\ManagesCollections. Did you maybe mean deleteCollect()? ( Ignorable by Annotation )

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

59
        $this->/** @scrutinizer ignore-call */ 
60
               delete("custom_collections/{$collectionId}.json");

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...
60
    }
61
62
    public function createSmartCollection(array $data): SmartCollectionResource
63
    {
64
        $response = $this->post('smart_collections.json', ['smart_collection' => $data]);
65
66
        return new SmartCollectionResource($response['smart_collection'], $this);
67
    }
68
69
    public function getSmartCollectionsCount(array $params = []): int
70
    {
71
        $response = $this->get('smart_collections/count.json', $params);
72
73
        return $response['count'] ?? 0;
74
    }
75
76
    public function getSmartCollections(array $params = []): Collection
77
    {
78
        $response = $this->get('smart_collections.json', $params);
79
80
        return $this->transformCollection($response['smart_collections'], SmartCollectionResource::class);
81
    }
82
83
    public function getSmartCollection($collectionId): SmartCollectionResource
84
    {
85
        $response = $this->get("smart_collections/{$collectionId}.json");
86
87
        return new SmartCollectionResource($response['smart_collection'], $this);
88
    }
89
90
    public function updateSmartCollection($collectionId, array $data): SmartCollectionResource
91
    {
92
        $response = $this->put("smart_collections/{$collectionId}.json", ['smart_collection' => $data]);
93
94
        return new SmartCollectionResource($response['smart_collection'], $this);
95
    }
96
97
    public function deleteSmartCollection($collectionId): void
98
    {
99
        $this->delete("smart_collections/{$collectionId}.json");
100
    }
101
102
    public function reorderSmartCollection($collectionId, array $productIds)
103
    {
104
        $response = $this->put("smart_collections/{$collectionId}/order.json", ['products' => $productIds]);
105
106
        return new SmartCollectionResource($response['smart_collection'], $this);
107
    }
108
109
    public function createCollect(array $data): CollectResource
110
    {
111
        $response = $this->post('collects.json', ['collect' => $data]);
112
113
        return new CollectResource($response['collect'], $this);
114
    }
115
116
    public function getCollectsCount(array $params = []): int
117
    {
118
        $response = $this->get('collects/count.json', $params);
119
120
        return $response['count'] ?? 0;
121
    }
122
123
    public function getCollects(array $params = []): Collection
124
    {
125
        $response = $this->get('collects.json', $params);
126
127
        return $this->transformCollection($response['collects'], CollectResource::class);
128
    }
129
130
    public function deleteCollect($collectId): void
131
    {
132
        $this->delete("collects/{$collectId}.json");
133
    }
134
135
    public function getCollection($collectionId): ApiResource
136
    {
137
        $response = $this->get("collections/{$collectionId}.json");
138
139
        return new ApiResource($response['collection'], $this);
140
    }
141
142
    public function getCollectionProducts($collectionId, array $params = []): Collection
143
    {
144
        $response = $this->get("collections/{$collectionId}/products.json", $params);
145
146
        return $this->transformCollection($response['products'], ProductResource::class);
147
    }
148
}
149