Address::getCustomer()   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
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Helix\Shopify\Customer;
4
5
use Helix\Shopify\Base\AbstractEntity;
6
use Helix\Shopify\Base\AbstractEntity\CrudTrait;
7
use Helix\Shopify\Customer;
8
9
/**
10
 * A customer's address.
11
 *
12
 * @see https://shopify.dev/docs/admin-api/rest/reference/customers/customer-address
13
 *
14
 * @see Customer::newAddress()
15
 *
16
 * @method string   getAddress1     ()
17
 * @method string   getAddress2     ()
18
 * @method string   getCity         ()
19
 * @method string   getCompany      ()
20
 * @method string   getCountry      ()
21
 * @method string   getCountryCode  () read-only
22
 * @method string   getCountryName  ()
23
 * @method string   getCustomerId   () injected
24
 * @method bool     isDefault       ()
25
 * @method string   getName         ()
26
 * @method string   getPhone        () non-unique
27
 * @method string   getProvince     ()
28
 * @method string   getProvinceCode () read-only
29
 * @method string   getZip          ()
30
 *
31
 * @method bool     hasPhone        ()
32
 *
33
 * @method $this    setAddress1     (string $address1)
34
 * @method $this    setAddress2     (string $address2)
35
 * @method $this    setCity         (string $city)
36
 * @method $this    setCompany      (string $company)
37
 * @method $this    setCountry      (string $country)
38
 * @method $this    setCountryName  (string $name)
39
 * @method $this    setName         (string $name)
40
 * @method $this    setPhone        (string $phone)
41
 * @method $this    setProvince     (string $province)
42
 * @method $this    setZip          (string $zip)
43
 */
44
class Address extends AbstractEntity
45
{
46
47
    use CrudTrait;
48
49
    const TYPE = 'customer_address';
50
    const DIR = 'addresses';
51
52
    protected function _container()
53
    {
54
        return $this->getCustomer();
55
    }
56
57
    protected function _onDelete(): void
58
    {
59
        parent::_onDelete();
60
        $this->getCustomer()->_reload('addresses');
61
    }
62
63
    protected function _onSave(): void
64
    {
65
        parent::_onSave();
66
        $customer = $this->getCustomer();
67
        $customer->_reload('addresses');
68
        if (!$customer->hasPhone() and $this->hasPhone()) {
69
            $customer->_reload('phone');
70
        }
71
    }
72
73
    /**
74
     * @return Customer
75
     */
76
    public function getCustomer()
77
    {
78
        return Customer::load($this, $this->getCustomerId());
79
    }
80
81
    /**
82
     * Alias for {@link getProvince()}
83
     *
84
     * @return string
85
     */
86
    final public function getState()
87
    {
88
        return $this->getProvince();
89
    }
90
91
    /**
92
     * Alias for {@link getProvinceCode()}
93
     *
94
     * @return string
95
     */
96
    final public function getStateCode()
97
    {
98
        return $this->getProvinceCode();
99
    }
100
101
    /**
102
     * Sets the address as the default.
103
     *
104
     * @return $this
105
     */
106
    public function setDefault()
107
    {
108
        assert($this->hasId());
109
        // tell the prior default address.
110
        if ($default = $this->getCustomer()->getDefaultAddress()) {
111
            $default->data['default'] = false;
112
            $this->pool->add($default);
113
        }
114
        return $this->_set('default', true)->update();
115
    }
116
117
    /**
118
     * Alias for {@link setProvince()}
119
     *
120
     * @param string $state
121
     * @return $this
122
     */
123
    final public function setState(string $state)
124
    {
125
        return $this->setProvince($state);
0 ignored issues
show
Unused Code introduced by
The call to Helix\Shopify\Customer\Address::setProvince() has too many arguments starting with $state. ( Ignorable by Annotation )

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

125
        return $this->/** @scrutinizer ignore-call */ setProvince($state);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
126
    }
127
128
}