Passed
Push — master ( 199ece...6bc7da )
by y
02:13
created

Location::newInventoryLevel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Helix\Shopify;
4
5
use Helix\Shopify\Base\AbstractEntity;
6
use Helix\Shopify\Base\AbstractEntity\ImmutableInterface;
7
8
/**
9
 * A location.
10
 *
11
 * @immutable Cannot be modified via the API.
12
 *
13
 * @see https://shopify.dev/docs/admin-api/rest/reference/inventory/location
14
 *
15
 * @method bool     isActive                    ()
16
 * @method string   getAddress1                 ()
17
 * @method string   getAddress2                 ()
18
 * @method string   getCity                     ()
19
 * @method string   getCountryCode              ()
20
 * @method string   getCreatedAt                ()
21
 * @method bool     isLegacy                    ()
22
 * @method string   getLocalizedCountryName     ()
23
 * @method string   getLocalizedProvinceName    ()
24
 * @method string   getName                     ()
25
 * @method string   getPhone                    ()
26
 * @method string   getProvince                 ()
27
 * @method string   getProvinceCode             ()
28
 * @method string   getUpdatedAt                ()
29
 * @method string   getZip                      ()
30
 *
31
 * @method InventoryLevel[] selectInventoryLevels (callable $filter) `fn( InventoryLevel $level ): bool`
32
 */
33
class Location extends AbstractEntity implements ImmutableInterface {
34
35
    const TYPE = 'location';
36
    const DIR = 'locations';
37
38
    /**
39
     * @return InventoryLevel[]
40
     */
41
    public function getInventoryLevels () {
42
        $remote = $this->api->get("{$this}/inventory_levels")['inventory_levels'] ?? [];
43
        return $this->api->factoryAll($this, InventoryLevel::class, $remote);
44
    }
45
46
    /**
47
     * Factory.
48
     *
49
     * @param InventoryItem $item
50
     * @return InventoryLevel
51
     */
52
    public function newInventoryLevel (InventoryItem $item) {
53
        return $this->api->factory($this, InventoryLevel::class, [
54
            'location_id' => $this->getId(),
55
            'inventory_item_id' => $item->getId()
56
        ]);
57
    }
58
}