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

Address::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
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 2
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
    use CrudTrait;
47
48
    const TYPE = 'customer_address';
49
    const DIR = 'addresses';
50
51
    protected function _container () {
52
        return $this->getCustomer();
53
    }
54
55
    protected function _onDelete (): void {
56
        parent::_onDelete();
57
        $this->getCustomer()->_reload('addresses');
58
    }
59
60
    protected function _onSave (): void {
61
        parent::_onSave();
62
        $customer = $this->getCustomer();
63
        $customer->_reload('addresses');
64
        if (!$customer->hasPhone() and $this->hasPhone()) {
65
            $customer->_reload('phone');
66
        }
67
    }
68
69
    /**
70
     * @return Customer
71
     */
72
    public function getCustomer () {
73
        return Customer::load($this, $this->getCustomerId());
74
    }
75
76
    /**
77
     * Alias for {@link getProvince()}
78
     *
79
     * @return string
80
     */
81
    final public function getState () {
82
        return $this->getProvince();
83
    }
84
85
    /**
86
     * Alias for {@link getProvinceCode()}
87
     *
88
     * @return string
89
     */
90
    final public function getStateCode () {
91
        return $this->getProvinceCode();
92
    }
93
94
    /**
95
     * Sets the address as the default.
96
     *
97
     * @return $this
98
     */
99
    public function setDefault () {
100
        assert($this->hasId());
101
        // tell the prior default address.
102
        if ($default = $this->getCustomer()->getDefaultAddress()) {
103
            $default->data['default'] = false;
104
            $this->pool->add($default);
105
        }
106
        return $this->_set('default', true)->update();
107
    }
108
109
    /**
110
     * Alias for {@link setProvince()}
111
     *
112
     * @param string $state
113
     * @return $this
114
     */
115
    final public function setState (string $state) {
116
        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

116
        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...
117
    }
118
119
}