Shipper::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of Smsa WebService package.
5
 * (c) Hamoud Alhoqbani <[email protected]>
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Alhoqbani\SmsaWebService\Models;
11
12
use Alhoqbani\SmsaWebService\Soap\Type\AddShip;
13
use Alhoqbani\SmsaWebService\Soap\Type\AddShipment;
14
use WsdlToPhp\PackageBase\AbstractStructBase;
15
16
class Shipper
17
{
18
19
    /**
20
     * Shipper Name.
21
     * Mandatory
22
     * Correspond to (sName)
23
     *
24
     * @var string
25
     */
26
    private $name;
27
    /**
28
     * Shipper Contact name.
29
     * Mandatory
30
     * Correspond to (sContact)
31
     *
32
     * @var string
33
     */
34
    private $contactName;
35
    /**
36
     * Shipper Address Line 1.
37
     * Mandatory
38
     * Correspond to (sAddr1)
39
     *
40
     * @var string
41
     */
42
    private $addressLine1;
43
    /**
44
     * Shipper Address Line 2.
45
     * Optional
46
     * Correspond to (sAddr2)
47
     *
48
     * @var string
49
     */
50
    private $addressLine2;
51
    /**
52
     * Shipper City.
53
     * Mandatory
54
     * Correspond to (sCity)
55
     *
56
     * @var string
57
     */
58
    private $city;
59
    /**
60
     * Shipper country.
61
     * Mandatory
62
     * Correspond to (sCntry)
63
     *
64
     * @var string
65
     */
66
    private $country;
67
    /**
68
     * Shipper phone number.
69
     * Mandatory
70
     * Correspond to (sPhone)
71
     *
72
     * @var string
73
     */
74
    private $phone;
75
76
    /**
77
     * Shipper constructor.
78
     *
79
     * @param string $name
80
     * @param string $contactName
81
     * @param string $addressLine1
82
     * @param string $city
83
     * @param string $country
84
     * @param string $phone
85
     */
86 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
        string $name,
88
        string $contactName,
89
        string $addressLine1,
90
        string $city,
91
        string $country,
92
        string $phone
93
    ) {
94
        $this->name = $name;
95
        $this->contactName = $contactName;
96
        $this->addressLine1 = $addressLine1;
97
        $this->city = $city;
98
        $this->country = $country;
99
        $this->phone = $phone;
100
    }
101
102
    /**
103
     * Add customer details to the shipment object.
104
     *
105
     * @param AddShipment|AddShip $shipment
106
     *
107
     * @return AddShipment|AddShip
108
     */
109
    public function prepareForShipment($shipment): AbstractStructBase
110
    {
111
        return $shipment
0 ignored issues
show
Bug introduced by
The method setSName does only exist in Alhoqbani\SmsaWebService\Soap\Type\AddShip, but not in Alhoqbani\SmsaWebService\Soap\Type\AddShipment.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
112
            // Required fields
113
            ->setSName($this->name)
114
            ->setSContact($this->contactName)
115
            ->setSAddr1($this->addressLine1)
116
            ->setSAddr2($this->addressLine2)
117
            ->setSCity($this->city)
118
            ->setSCntry($this->country)
119
            ->setSCity($this->city)
120
            ->setSPhone($this->phone);
121
    }
122
123
    /* **************************************************************************************************************
124
     *  Setters and Getters
125
     * **************************************************************************************************************/
126
127
    /**
128
     * @return string
129
     */
130
    public function getName(): string
131
    {
132
        return $this->name;
133
    }
134
135
    /**
136
     * @param string $name
137
     *
138
     * @return Shipper
139
     */
140
    public function setName(string $name): self
141
    {
142
        $this->name = $name;
143
144
        return $this;
145
    }
146
147
    /**
148
     * @return string
149
     */
150
    public function getContactName(): string
151
    {
152
        return $this->contactName;
153
    }
154
155
    /**
156
     * @param string $contactName
157
     *
158
     * @return Shipper
159
     */
160
    public function setContactName(string $contactName): self
161
    {
162
        $this->contactName = $contactName;
163
164
        return $this;
165
    }
166
167
    /**
168
     * @return string
169
     */
170
    public function getAddressLine1(): string
171
    {
172
        return $this->addressLine1;
173
    }
174
175
    /**
176
     * @param string $addressLine1
177
     *
178
     * @return Shipper
179
     */
180
    public function setAddressLine1(string $addressLine1): self
181
    {
182
        $this->addressLine1 = $addressLine1;
183
184
        return $this;
185
    }
186
187
    /**
188
     * @return string
189
     */
190
    public function getAddressLine2()
191
    {
192
        return $this->addressLine2;
193
    }
194
195
    /**
196
     * @param string $addressLine2
197
     *
198
     * @return Shipper
199
     */
200
    public function setAddressLine2(string $addressLine2): self
201
    {
202
        $this->addressLine2 = $addressLine2;
203
204
        return $this;
205
    }
206
207
    /**
208
     * @return string
209
     */
210
    public function getCity(): string
211
    {
212
        return $this->city;
213
    }
214
215
    /**
216
     * @param string $city
217
     *
218
     * @return Shipper
219
     */
220
    public function setCity(string $city): self
221
    {
222
        $this->city = $city;
223
224
        return $this;
225
    }
226
227
    /**
228
     * @return string
229
     */
230
    public function getCountry(): string
231
    {
232
        return $this->country;
233
    }
234
235
    /**
236
     * @param string $country
237
     *
238
     * @return Shipper
239
     */
240
    public function setCountry(string $country): self
241
    {
242
        $this->country = $country;
243
244
        return $this;
245
    }
246
247
    /**
248
     * @return string
249
     */
250
    public function getPhone(): string
251
    {
252
        return $this->phone;
253
    }
254
255
    /**
256
     * @param string $phone
257
     *
258
     * @return Shipper
259
     */
260
    public function setPhone(string $phone): self
261
    {
262
        $this->phone = $phone;
263
264
        return $this;
265
    }
266
}
267