This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Bpost\BpostApiClient\Bpost\Order; |
||
3 | |||
4 | use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException; |
||
5 | |||
6 | /** |
||
7 | * bPost Customer class |
||
8 | * |
||
9 | * @author Tijs Verkoyen <[email protected]> |
||
10 | */ |
||
11 | class Customer |
||
12 | { |
||
13 | const TAG_NAME = 'customer'; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $name; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $company; |
||
24 | |||
25 | /** |
||
26 | * @var Address |
||
27 | */ |
||
28 | private $address; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $emailAddress; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | private $phoneNumber; |
||
39 | |||
40 | /** |
||
41 | * @param \Bpost\BpostApiClient\Bpost\Order\Address $address |
||
42 | */ |
||
43 | 12 | public function setAddress($address) |
|
44 | { |
||
45 | 12 | $this->address = $address; |
|
46 | 12 | } |
|
47 | |||
48 | /** |
||
49 | * @return \Bpost\BpostApiClient\Bpost\Order\Address |
||
50 | */ |
||
51 | 10 | public function getAddress() |
|
52 | { |
||
53 | 10 | return $this->address; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * @param string $company |
||
58 | */ |
||
59 | 12 | public function setCompany($company) |
|
60 | { |
||
61 | 12 | $this->company = $company; |
|
62 | 12 | } |
|
63 | |||
64 | /** |
||
65 | * @return string |
||
66 | */ |
||
67 | 12 | public function getCompany() |
|
68 | { |
||
69 | 12 | return $this->company; |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * @param string $emailAddress |
||
74 | * @throws BpostInvalidLengthException |
||
75 | */ |
||
76 | 15 | View Code Duplication | public function setEmailAddress($emailAddress) |
0 ignored issues
–
show
|
|||
77 | { |
||
78 | 15 | $length = 50; |
|
79 | 15 | if (mb_strlen($emailAddress) > $length) { |
|
80 | 3 | throw new BpostInvalidLengthException('emailAddress', mb_strlen($emailAddress), $length); |
|
81 | } |
||
82 | 12 | $this->emailAddress = $emailAddress; |
|
83 | 12 | } |
|
84 | |||
85 | /** |
||
86 | * @return string |
||
87 | */ |
||
88 | 10 | public function getEmailAddress() |
|
89 | { |
||
90 | 10 | return $this->emailAddress; |
|
91 | } |
||
92 | |||
93 | /** |
||
94 | * @param string $name |
||
95 | */ |
||
96 | 12 | public function setName($name) |
|
97 | { |
||
98 | 12 | $this->name = $name; |
|
99 | 12 | } |
|
100 | |||
101 | /** |
||
102 | * @return string |
||
103 | */ |
||
104 | 10 | public function getName() |
|
105 | { |
||
106 | 10 | return $this->name; |
|
107 | } |
||
108 | |||
109 | /** |
||
110 | * @param string $phoneNumber |
||
111 | * @throws BpostInvalidLengthException |
||
112 | */ |
||
113 | 15 | View Code Duplication | public function setPhoneNumber($phoneNumber) |
0 ignored issues
–
show
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. ![]() |
|||
114 | { |
||
115 | 15 | $length = 20; |
|
116 | 15 | if (mb_strlen($phoneNumber) > $length) { |
|
117 | 3 | throw new BpostInvalidLengthException('phoneNumber', mb_strlen($phoneNumber), $length); |
|
118 | } |
||
119 | 12 | $this->phoneNumber = $phoneNumber; |
|
120 | 12 | } |
|
121 | |||
122 | /** |
||
123 | * @return string |
||
124 | */ |
||
125 | 10 | public function getPhoneNumber() |
|
126 | { |
||
127 | 10 | return $this->phoneNumber; |
|
128 | } |
||
129 | |||
130 | /** |
||
131 | * Return the object as an array for usage in the XML |
||
132 | * |
||
133 | * @param \DomDocument $document |
||
134 | * @param string $prefix |
||
0 ignored issues
–
show
Should the type for parameter
$prefix not be string|null ?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types. ![]() |
|||
135 | * @return \DomElement |
||
136 | */ |
||
137 | 9 | public function toXML(\DomDocument $document, $prefix = null) |
|
138 | { |
||
139 | 9 | $tagName = static::TAG_NAME; |
|
140 | 9 | if ($prefix !== null) { |
|
141 | 3 | $tagName = $prefix . ':' . $tagName; |
|
142 | 3 | } |
|
143 | |||
144 | 9 | $customer = $document->createElement($tagName); |
|
145 | |||
146 | 9 | if ($this->getName() !== null) { |
|
147 | 9 | $customer->appendChild( |
|
148 | 9 | $document->createElement( |
|
149 | 9 | 'common:name', |
|
150 | 9 | $this->getName() |
|
151 | 9 | ) |
|
152 | 9 | ); |
|
153 | 9 | } |
|
154 | 9 | if ($this->getCompany() !== null) { |
|
155 | 9 | $customer->appendChild( |
|
156 | 9 | $document->createElement( |
|
157 | 9 | 'common:company', |
|
158 | 9 | $this->getCompany() |
|
159 | 9 | ) |
|
160 | 9 | ); |
|
161 | 9 | } |
|
162 | 9 | if ($this->getAddress() !== null) { |
|
163 | 9 | $customer->appendChild( |
|
164 | 9 | $this->getAddress()->toXML($document) |
|
165 | 9 | ); |
|
166 | 9 | } |
|
167 | 9 | if ($this->getEmailAddress() !== null) { |
|
168 | 9 | $customer->appendChild( |
|
169 | 9 | $document->createElement( |
|
170 | 9 | 'common:emailAddress', |
|
171 | 9 | $this->getEmailAddress() |
|
172 | 9 | ) |
|
173 | 9 | ); |
|
174 | 9 | } |
|
175 | 9 | if ($this->getPhoneNumber() !== null) { |
|
176 | 9 | $customer->appendChild( |
|
177 | 9 | $document->createElement( |
|
178 | 9 | 'common:phoneNumber', |
|
179 | 9 | $this->getPhoneNumber() |
|
180 | 9 | ) |
|
181 | 9 | ); |
|
182 | 9 | } |
|
183 | |||
184 | 9 | return $customer; |
|
185 | } |
||
186 | |||
187 | /** |
||
188 | * @param \SimpleXMLElement $xml |
||
189 | * @param Customer $instance |
||
190 | * |
||
191 | * @return Customer |
||
192 | * @throws BpostInvalidLengthException |
||
193 | */ |
||
194 | 3 | public static function createFromXMLHelper(\SimpleXMLElement $xml, Customer $instance) |
|
195 | { |
||
196 | 3 | if (isset($xml->name) && $xml->name != '') { |
|
197 | 3 | $instance->setName((string) $xml->name); |
|
198 | 3 | } |
|
199 | 3 | if (isset($xml->company) && $xml->company != '') { |
|
200 | 3 | $instance->setCompany((string) $xml->company); |
|
201 | 3 | } |
|
202 | 3 | if (isset($xml->address)) { |
|
203 | 3 | $instance->setAddress( |
|
204 | 3 | Address::createFromXML($xml->address) |
|
205 | 3 | ); |
|
206 | 3 | } |
|
207 | 3 | if (isset($xml->emailAddress) && $xml->emailAddress != '') { |
|
208 | 3 | $instance->setEmailAddress( |
|
209 | 3 | (string) $xml->emailAddress |
|
210 | 3 | ); |
|
211 | 3 | } |
|
212 | 3 | if (isset($xml->phoneNumber) && $xml->phoneNumber != '') { |
|
213 | 3 | $instance->setPhoneNumber((string) $xml->phoneNumber); |
|
214 | 3 | } |
|
215 | |||
216 | 3 | return $instance; |
|
217 | } |
||
218 | } |
||
219 |
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.