Label::COD()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
3
namespace OceanApplications\Postmen\Requests;
4
5
use OceanApplications\Postmen\Models\Billing;
6
use OceanApplications\Postmen\Models\Customs;
7
use OceanApplications\Postmen\Models\Invoice;
8
use OceanApplications\Postmen\Models\Model;
9
use OceanApplications\Postmen\Models\Money;
10
use OceanApplications\Postmen\Models\Shipment;
11
12
class Label extends Model
13
{
14
    public $paper_size = 'default';
15
    public $service_type;
16
    public $is_document = false;
17
    public $shipper_account;
18
    public $shipment;
19
    public $async = false;
20
    public $return_shipment = false;
21
    public $ship_date;
22
    public $service_options = null;
23
    public $invoice;
24
    public $references;
25
    public $billing;
26
    public $customs;
27
28
    public function __construct()
29
    {
30
        $this->ship_date = date('Y-m-d', strtotime('tomorrow'));
31
    }
32
33
    /**
34
     * @param string $size
35
     *
36
     * @return $this
37
     */
38
    public function paper_size($size = 'default')
39
    {
40
        $this->paper_size = $size;
41
42
        return $this;
43
    }
44
45
    /**
46
     * @param $service
47
     *
48
     * @return $this
49
     */
50
    public function service_type($service)
51
    {
52
        $this->service_type = $service;
53
54
        return $this;
55
    }
56
57
    /**
58
     * @param bool $value
59
     *
60
     * @return $this
61
     */
62
    public function is_document($value = true)
63
    {
64
        if ($value == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
65
            $$this->is_document = true;
66
        } elseif ($value == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
67
            $this->is_document = false;
68
        }
69
70
        return $this;
71
    }
72
73
    /**
74
     * @param $id
75
     *
76
     * @return $this
77
     */
78
    public function shipper_account($id)
79
    {
80
        $shipper_account = new \stdClass();
81
        $shipper_account->id = $id;
82
        $this->shipper_account = $shipper_account;
83
84
        return $this;
85
    }
86
87
    /**
88
     * @param Shipment $shipment
89
     *
90
     * @return $this
91
     */
92
    public function shipment(Shipment $shipment)
93
    {
94
        $this->shipment = $shipment;
95
96
        return $this;
97
    }
98
99
    /**
100
     * @param bool $value
101
     *
102
     * @return $this
103
     */
104
    public function async($value = true)
105
    {
106
        if ($value == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
107
            $$this->async = true;
108
        } elseif ($value == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
109
            $this->async = false;
110
        }
111
112
        return $this;
113
    }
114
115
    /**
116
     * @param bool $value
117
     *
118
     * @return $this
119
     */
120
    public function return_shipment($value = true)
121
    {
122
        if ($value == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
123
            $$this->return_shipment = true;
124
        } elseif ($value == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
125
            $this->return_shipment = false;
126
        }
127
128
        return $this;
129
    }
130
131
    /**
132
     * @param $value YYYY-MM-DD formatted date
133
     *
134
     * @return $this
135
     */
136
    public function ship_date($value)
137
    {
138
        $this->ship_date = $value;
139
140
        return $this;
141
    }
142
143
    /**
144
     * @param Money $money
145
     *
146
     * @return $this
147
     */
148
    public function COD(Money $money)
149
    {
150
        if ($this->service_options == null) {
151
            $this->service_options = [];
152
        }
153
        $option = new \stdClass();
154
        $option->type = 'cod';
155
        $option->cod_value = $money;
156
        array_push($this->service_options, $option);
157
158
        return $this;
159
    }
160
161
    /**
162
     * @param Invoice $invoice
163
     *
164
     * @return $this
165
     */
166
    public function invoice(Invoice $invoice)
167
    {
168
        $this->invoice = $invoice;
169
170
        return $this;
171
    }
172
173
    /**
174
     * @param array $references
175
     *
176
     * @return $this
177
     */
178
    public function references(array $references)
179
    {
180
        $this->references = $references;
181
182
        return $this;
183
    }
184
185
    public function billing(Billing $billing)
186
    {
187
        $this->billing = $billing;
188
189
        return $this;
190
    }
191
192
    /**
193
     * @param Customs $customs
194
     *
195
     * @return $this
196
     */
197
    public function customs(Customs $customs)
198
    {
199
        $this->customs = $customs;
200
201
        return $this;
202
    }
203
}
204