ManagesInventory::getLocationInventoryLevels()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
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\Resources\ApiResource;
7
use Signifly\Shopify\Shopify;
8
9
/** @mixin Shopify */
10
trait ManagesInventory
11
{
12
    public function getInventoryItems(array $params = []): Collection
13
    {
14
        $response = $this->get('inventory_items.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

14
        /** @scrutinizer ignore-call */ 
15
        $response = $this->get('inventory_items.json', $params);
Loading history...
15
16
        return $this->transformCollection($response['inventory_items'], ApiResource::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

16
        return $this->/** @scrutinizer ignore-call */ transformCollection($response['inventory_items'], ApiResource::class);
Loading history...
17
    }
18
19
    public function getInventoryItem($inventoryItemId): ApiResource
20
    {
21
        $response = $this->get("inventory_items/{$inventoryItemId}.json");
22
23
        return new ApiResource($response['inventory_item'], $this);
24
    }
25
26
    public function updateInventoryItem($inventoryItemId, array $data): ApiResource
27
    {
28
        $response = $this->put("inventory_items/{$inventoryItemId}.json", ['inventory_item' => $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

28
        /** @scrutinizer ignore-call */ 
29
        $response = $this->put("inventory_items/{$inventoryItemId}.json", ['inventory_item' => $data]);
Loading history...
29
30
        return new ApiResource($response['inventory_item'], $this);
31
    }
32
33
    public function getInventoryLevels(array $params = []): Collection
34
    {
35
        $response = $this->get('inventory_levels.json', $params);
36
37
        return $this->transformCollection($response['inventory_levels'], ApiResource::class);
38
    }
39
40
    public function deleteInventoryLevel($inventoryItemId, $locationId): void
41
    {
42
        $this->delete('inventory_levels.json', [
0 ignored issues
show
Bug introduced by
The method delete() does not exist on Signifly\Shopify\REST\Actions\ManagesInventory. Did you maybe mean deleteInventoryLevel()? ( Ignorable by Annotation )

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

42
        $this->/** @scrutinizer ignore-call */ 
43
               delete('inventory_levels.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...
43
            'inventory_item_id' => $inventoryItemId,
44
            'location_id' => $locationId,
45
        ]);
46
    }
47
48
    public function adjustInventoryLevel($inventoryItemId, $locationId, int $availableAdjustment): ApiResource
49
    {
50
        $response = $this->post('inventory_levels/adjust.json', [
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

50
        /** @scrutinizer ignore-call */ 
51
        $response = $this->post('inventory_levels/adjust.json', [
Loading history...
51
            'inventory_item_id' => $inventoryItemId,
52
            'location_id' => $locationId,
53
            'available_adjustment' => $availableAdjustment,
54
        ]);
55
56
        return new ApiResource($response['inventory_level'], $this);
57
    }
58
59
    public function connectInventoryLevel($inventoryItemId, $locationId, bool $relocate = false): ApiResource
60
    {
61
        $response = $this->post('inventory_levels/connect.json', [
62
            'inventory_item_id' => $inventoryItemId,
63
            'location_id' => $locationId,
64
            'relocate_if_necessary' => $relocate,
65
        ]);
66
67
        return new ApiResource($response['inventory_level'], $this);
68
    }
69
70
    public function setInventoryLevel($inventoryItemId, $locationId, int $available, bool $disconnect = false): ApiResource
71
    {
72
        $response = $this->post('inventory_levels/set.json', [
73
            'inventory_item_id' => $inventoryItemId,
74
            'location_id' => $locationId,
75
            'available' => $available,
76
            'disconnect_if_necessary' => $disconnect,
77
        ]);
78
79
        return new ApiResource($response['inventory_level'], $this);
80
    }
81
82
    public function getLocationsCount(array $params = []): int
83
    {
84
        $response = $this->get('locations/count.json', $params);
85
86
        return $response['count'] ?? 0;
87
    }
88
89
    public function getLocations(array $params = []): Collection
90
    {
91
        $response = $this->get('locations.json', $params);
92
93
        return $this->transformCollection($response['locations'], ApiResource::class);
94
    }
95
96
    public function getLocation($locationId): ApiResource
97
    {
98
        $response = $this->get("locations/{$locationId}.json");
99
100
        return $this->transformItem($response['location'], ApiResource::class);
0 ignored issues
show
Bug introduced by
It seems like transformItem() 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

100
        return $this->/** @scrutinizer ignore-call */ transformItem($response['location'], ApiResource::class);
Loading history...
101
    }
102
103
    public function getLocationInventoryLevels($locationId, array $params = []): Collection
104
    {
105
        $response = $this->get("locations/{$locationId}/inventory_levels.json", $params);
106
107
        return $this->transformCollection($response['inventory_levels'], ApiResource::class);
108
    }
109
}
110