Refund::setFullShipping()   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\Order;
4
5
use Helix\Shopify\Base\AbstractEntity;
6
use Helix\Shopify\Base\AbstractEntity\CreateTrait;
7
use Helix\Shopify\Base\AbstractEntity\ImmutableInterface;
8
use Helix\Shopify\Order;
9
use Helix\Shopify\Order\Refund\Adjustment;
10
use Helix\Shopify\Order\Refund\RefundItem;
11
12
/**
13
 * A refund.
14
 *
15
 * @immutable Refunds can only be created.
16
 *
17
 * @see https://help.shopify.com/en/api/reference/orders/refund
18
 *
19
 * @method $this setCurrency            (string $currency) @depends create-only
20
 * @method $this setDiscrepancyReason   (string $reason) @depends create-only
21
 * @method $this setNote                (string $note) @depends create-only
22
 * @method $this setNotify              (bool $notify) @depends create-only
23
 * @method $this setProcessedAt         (string $iso8601) @depends create-only
24
 * @method $this setRefundLineItems     (RefundItem[] $items) @depends create-only
25
 * @method $this setTransactions        (Transaction[] $transactions) @depends create-only
26
 * @method $this setUserId              (string $id) @depends create-only
27
 *
28
 * @method string           getCreatedAt        ()
29
 * @method string           getId               ()
30
 * @method string           getNote             ()
31
 * @method Adjustment[]     getOrderAdjustments ()
32
 * @method string           getProcessedAt      ()
33
 * @method RefundItem[]     getRefundLineItems  ()
34
 * @method Transaction[]    getTransactions     ()
35
 * @method string           getUserId           ()
36
 *
37
 * @method bool hasOrderAdjustments ()
38
 * @method bool hasRefundLineItems  ()
39
 * @method bool hasTransactions     ()
40
 */
41
class Refund extends AbstractEntity implements ImmutableInterface
42
{
43
44
    use CreateTrait;
45
46
    const TYPE = 'refund';
47
    const DIR = 'refunds';
48
49
    const REASON_CUSTOMER = 'customer';
50
    const REASON_DAMAGE = 'damage';
51
    const REASON_OTHER = 'other';
52
    const REASON_RESTOCK = 'restock';
53
54
    const MAP = [
55
        'order_adjustments' => [Adjustment::class],
56
        'refund_line_items' => [RefundItem::class],
57
        'transactions' => [Transaction::class]
58
    ];
59
60
    /**
61
     * @var Order
62
     */
63
    protected $order;
64
65
    public function __construct(Order $order, array $data = [])
66
    {
67
        $this->order = $order;
68
        parent::__construct($order, $data);
69
    }
70
71
    protected function _container()
72
    {
73
        return $this->order;
74
    }
75
76
    /**
77
     * @return Order
78
     */
79
    public function getOrder()
80
    {
81
        return Order::load($this, $this->order->getId());
0 ignored issues
show
Bug introduced by
It seems like $this->order->getId() can also be of type null; however, parameter $id of Helix\Shopify\Base\AbstractEntity::load() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

81
        return Order::load($this, /** @scrutinizer ignore-type */ $this->order->getId());
Loading history...
82
    }
83
84
    /**
85
     * @return RefundItem
86
     */
87
    public function newItem()
88
    {
89
        return $this->api->factory($this, RefundItem::class);
90
    }
91
92
    /**
93
     * @return Transaction
94
     */
95
    public function newTransaction()
96
    {
97
        return $this->api->factory($this, Transaction::class, [
98
            'kind' => Transaction::KIND_REFUND
99
        ]);
100
    }
101
102
    /**
103
     * @depends create-only
104
     * @return $this
105
     */
106
    public function setFullShipping()
107
    {
108
        return $this->_set('shipping', ['full_refund' => true]);
109
    }
110
111
    /**
112
     * @depends create-only
113
     * @param string $amount
114
     * @return $this
115
     */
116
    public function setShippingAmount(string $amount)
117
    {
118
        return $this->_set('shipping', ['amount' => $amount]);
119
    }
120
}