Total Complexity | 69 |
Total Lines | 398 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like EwsProtectionRuleAndType often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EwsProtectionRuleAndType, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class EwsProtectionRuleAndType extends AbstractStructBase |
||
17 | { |
||
18 | /** |
||
19 | * The AllInternal |
||
20 | * Meta information extracted from the WSDL |
||
21 | * - base: xs:string |
||
22 | * - choice: AllInternal | And | RecipientIs | SenderDepartments | True |
||
23 | * - choiceMaxOccurs: unbounded |
||
24 | * - choiceMinOccurs: 1 |
||
25 | * - length: 0 |
||
26 | * @var string|null |
||
27 | */ |
||
28 | protected ?string $AllInternal = null; |
||
29 | /** |
||
30 | * The And |
||
31 | * Meta information extracted from the WSDL |
||
32 | * - choice: AllInternal | And | RecipientIs | SenderDepartments | True |
||
33 | * - choiceMaxOccurs: unbounded |
||
34 | * - choiceMinOccurs: 1 |
||
35 | * @var \StructType\EwsProtectionRuleAndType|null |
||
36 | */ |
||
37 | protected ?\StructType\EwsProtectionRuleAndType $And = null; |
||
38 | /** |
||
39 | * The RecipientIs |
||
40 | * Meta information extracted from the WSDL |
||
41 | * - choice: AllInternal | And | RecipientIs | SenderDepartments | True |
||
42 | * - choiceMaxOccurs: unbounded |
||
43 | * - choiceMinOccurs: 1 |
||
44 | * @var \StructType\EwsProtectionRuleRecipientIsType|null |
||
45 | */ |
||
46 | protected ?\StructType\EwsProtectionRuleRecipientIsType $RecipientIs = null; |
||
47 | /** |
||
48 | * The SenderDepartments |
||
49 | * Meta information extracted from the WSDL |
||
50 | * - choice: AllInternal | And | RecipientIs | SenderDepartments | True |
||
51 | * - choiceMaxOccurs: unbounded |
||
52 | * - choiceMinOccurs: 1 |
||
53 | * @var \StructType\EwsProtectionRuleSenderDepartmentsType|null |
||
54 | */ |
||
55 | protected ?\StructType\EwsProtectionRuleSenderDepartmentsType $SenderDepartments = null; |
||
56 | /** |
||
57 | * The True |
||
58 | * Meta information extracted from the WSDL |
||
59 | * - base: xs:string |
||
60 | * - choice: AllInternal | And | RecipientIs | SenderDepartments | True |
||
61 | * - choiceMaxOccurs: unbounded |
||
62 | * - choiceMinOccurs: 1 |
||
63 | * - length: 0 |
||
64 | * @var string|null |
||
65 | */ |
||
66 | protected ?string $True = null; |
||
67 | /** |
||
68 | * Constructor method for ProtectionRuleAndType |
||
69 | * @uses EwsProtectionRuleAndType::setAllInternal() |
||
70 | * @uses EwsProtectionRuleAndType::setAnd() |
||
71 | * @uses EwsProtectionRuleAndType::setRecipientIs() |
||
72 | * @uses EwsProtectionRuleAndType::setSenderDepartments() |
||
73 | * @uses EwsProtectionRuleAndType::setTrue() |
||
74 | * @param string $allInternal |
||
75 | * @param \StructType\EwsProtectionRuleAndType $and |
||
76 | * @param \StructType\EwsProtectionRuleRecipientIsType $recipientIs |
||
77 | * @param \StructType\EwsProtectionRuleSenderDepartmentsType $senderDepartments |
||
78 | * @param string $true |
||
79 | */ |
||
80 | public function __construct(?string $allInternal = null, ?\StructType\EwsProtectionRuleAndType $and = null, ?\StructType\EwsProtectionRuleRecipientIsType $recipientIs = null, ?\StructType\EwsProtectionRuleSenderDepartmentsType $senderDepartments = null, ?string $true = null) |
||
81 | { |
||
82 | $this |
||
83 | ->setAllInternal($allInternal) |
||
84 | ->setAnd($and) |
||
85 | ->setRecipientIs($recipientIs) |
||
86 | ->setSenderDepartments($senderDepartments) |
||
87 | ->setTrue($true); |
||
88 | } |
||
89 | /** |
||
90 | * Get AllInternal value |
||
91 | * @return string|null |
||
92 | */ |
||
93 | public function getAllInternal(): ?string |
||
94 | { |
||
95 | return isset($this->AllInternal) ? $this->AllInternal : null; |
||
96 | } |
||
97 | /** |
||
98 | * This method is responsible for validating the value passed to the setAllInternal method |
||
99 | * This method is willingly generated in order to preserve the one-line inline validation within the setAllInternal method |
||
100 | * This has to validate that the property which is being set is the only one among the given choices |
||
101 | * @param mixed $value |
||
102 | * @return string A non-empty message if the values does not match the validation rules |
||
103 | */ |
||
104 | public function validateAllInternalForChoiceConstraintsFromSetAllInternal($value): string |
||
105 | { |
||
106 | $message = ''; |
||
107 | if (is_null($value)) { |
||
108 | return $message; |
||
109 | } |
||
110 | $properties = [ |
||
111 | 'And', |
||
112 | 'RecipientIs', |
||
113 | 'SenderDepartments', |
||
114 | 'True', |
||
115 | ]; |
||
116 | try { |
||
117 | foreach ($properties as $property) { |
||
118 | if (isset($this->{$property})) { |
||
119 | throw new InvalidArgumentException(sprintf('The property AllInternal can\'t be set as the property %s is already set. Only one property must be set among these properties: AllInternal, %s.', $property, implode(', ', $properties)), __LINE__); |
||
120 | } |
||
121 | } |
||
122 | } catch (InvalidArgumentException $e) { |
||
123 | $message = $e->getMessage(); |
||
124 | } |
||
125 | |||
126 | return $message; |
||
127 | } |
||
128 | /** |
||
129 | * Set AllInternal value |
||
130 | * This property belongs to a choice that allows only one property to exist. It is |
||
131 | * therefore removable from the request, consequently if the value assigned to this |
||
132 | * property is null, the property is removed from this object |
||
133 | * @throws InvalidArgumentException |
||
134 | * @param string $allInternal |
||
135 | * @return \StructType\EwsProtectionRuleAndType |
||
136 | */ |
||
137 | public function setAllInternal(?string $allInternal = null): self |
||
138 | { |
||
139 | // validation for constraint: string |
||
140 | if (!is_null($allInternal) && !is_string($allInternal)) { |
||
|
|||
141 | throw new InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($allInternal, true), gettype($allInternal)), __LINE__); |
||
142 | } |
||
143 | // validation for constraint: choice(AllInternal, And, RecipientIs, SenderDepartments, True) |
||
144 | if ('' !== ($allInternalChoiceErrorMessage = self::validateAllInternalForChoiceConstraintsFromSetAllInternal($allInternal))) { |
||
145 | throw new InvalidArgumentException($allInternalChoiceErrorMessage, __LINE__); |
||
146 | } |
||
147 | // validation for constraint: length |
||
148 | if (!is_null($allInternal) && mb_strlen((string) $allInternal) !== 0) { |
||
149 | throw new InvalidArgumentException(sprintf('Invalid length of %s, the number of characters/octets contained by the literal must be equal to 0', mb_strlen((string) $allInternal)), __LINE__); |
||
150 | } |
||
151 | if (is_null($allInternal) || (is_array($allInternal) && empty($allInternal))) { |
||
152 | unset($this->AllInternal); |
||
153 | } else { |
||
154 | $this->AllInternal = $allInternal; |
||
155 | } |
||
156 | |||
157 | return $this; |
||
158 | } |
||
159 | /** |
||
160 | * Get And value |
||
161 | * @return \StructType\EwsProtectionRuleAndType|null |
||
162 | */ |
||
163 | public function getAnd(): ?\StructType\EwsProtectionRuleAndType |
||
164 | { |
||
165 | return isset($this->And) ? $this->And : null; |
||
166 | } |
||
167 | /** |
||
168 | * This method is responsible for validating the value passed to the setAnd method |
||
169 | * This method is willingly generated in order to preserve the one-line inline validation within the setAnd method |
||
170 | * This has to validate that the property which is being set is the only one among the given choices |
||
171 | * @param mixed $value |
||
172 | * @return string A non-empty message if the values does not match the validation rules |
||
173 | */ |
||
174 | public function validateAndForChoiceConstraintsFromSetAnd($value): string |
||
175 | { |
||
176 | $message = ''; |
||
177 | if (is_null($value)) { |
||
178 | return $message; |
||
179 | } |
||
180 | $properties = [ |
||
181 | 'AllInternal', |
||
182 | 'RecipientIs', |
||
183 | 'SenderDepartments', |
||
184 | 'True', |
||
185 | ]; |
||
186 | try { |
||
187 | foreach ($properties as $property) { |
||
188 | if (isset($this->{$property})) { |
||
189 | throw new InvalidArgumentException(sprintf('The property And can\'t be set as the property %s is already set. Only one property must be set among these properties: And, %s.', $property, implode(', ', $properties)), __LINE__); |
||
190 | } |
||
191 | } |
||
192 | } catch (InvalidArgumentException $e) { |
||
193 | $message = $e->getMessage(); |
||
194 | } |
||
195 | |||
196 | return $message; |
||
197 | } |
||
198 | /** |
||
199 | * Set And value |
||
200 | * This property belongs to a choice that allows only one property to exist. It is |
||
201 | * therefore removable from the request, consequently if the value assigned to this |
||
202 | * property is null, the property is removed from this object |
||
203 | * @throws InvalidArgumentException |
||
204 | * @param \StructType\EwsProtectionRuleAndType $and |
||
205 | * @return \StructType\EwsProtectionRuleAndType |
||
206 | */ |
||
207 | public function setAnd(?\StructType\EwsProtectionRuleAndType $and = null): self |
||
208 | { |
||
209 | // validation for constraint: choice(AllInternal, And, RecipientIs, SenderDepartments, True) |
||
210 | if ('' !== ($andChoiceErrorMessage = self::validateAndForChoiceConstraintsFromSetAnd($and))) { |
||
211 | throw new InvalidArgumentException($andChoiceErrorMessage, __LINE__); |
||
212 | } |
||
213 | if (is_null($and) || (is_array($and) && empty($and))) { |
||
214 | unset($this->And); |
||
215 | } else { |
||
216 | $this->And = $and; |
||
217 | } |
||
218 | |||
219 | return $this; |
||
220 | } |
||
221 | /** |
||
222 | * Get RecipientIs value |
||
223 | * @return \StructType\EwsProtectionRuleRecipientIsType|null |
||
224 | */ |
||
225 | public function getRecipientIs(): ?\StructType\EwsProtectionRuleRecipientIsType |
||
226 | { |
||
227 | return isset($this->RecipientIs) ? $this->RecipientIs : null; |
||
228 | } |
||
229 | /** |
||
230 | * This method is responsible for validating the value passed to the setRecipientIs method |
||
231 | * This method is willingly generated in order to preserve the one-line inline validation within the setRecipientIs method |
||
232 | * This has to validate that the property which is being set is the only one among the given choices |
||
233 | * @param mixed $value |
||
234 | * @return string A non-empty message if the values does not match the validation rules |
||
235 | */ |
||
236 | public function validateRecipientIsForChoiceConstraintsFromSetRecipientIs($value): string |
||
237 | { |
||
238 | $message = ''; |
||
239 | if (is_null($value)) { |
||
240 | return $message; |
||
241 | } |
||
242 | $properties = [ |
||
243 | 'AllInternal', |
||
244 | 'And', |
||
245 | 'SenderDepartments', |
||
246 | 'True', |
||
247 | ]; |
||
248 | try { |
||
249 | foreach ($properties as $property) { |
||
250 | if (isset($this->{$property})) { |
||
251 | throw new InvalidArgumentException(sprintf('The property RecipientIs can\'t be set as the property %s is already set. Only one property must be set among these properties: RecipientIs, %s.', $property, implode(', ', $properties)), __LINE__); |
||
252 | } |
||
253 | } |
||
254 | } catch (InvalidArgumentException $e) { |
||
255 | $message = $e->getMessage(); |
||
256 | } |
||
257 | |||
258 | return $message; |
||
259 | } |
||
260 | /** |
||
261 | * Set RecipientIs value |
||
262 | * This property belongs to a choice that allows only one property to exist. It is |
||
263 | * therefore removable from the request, consequently if the value assigned to this |
||
264 | * property is null, the property is removed from this object |
||
265 | * @throws InvalidArgumentException |
||
266 | * @param \StructType\EwsProtectionRuleRecipientIsType $recipientIs |
||
267 | * @return \StructType\EwsProtectionRuleAndType |
||
268 | */ |
||
269 | public function setRecipientIs(?\StructType\EwsProtectionRuleRecipientIsType $recipientIs = null): self |
||
270 | { |
||
271 | // validation for constraint: choice(AllInternal, And, RecipientIs, SenderDepartments, True) |
||
272 | if ('' !== ($recipientIsChoiceErrorMessage = self::validateRecipientIsForChoiceConstraintsFromSetRecipientIs($recipientIs))) { |
||
273 | throw new InvalidArgumentException($recipientIsChoiceErrorMessage, __LINE__); |
||
274 | } |
||
275 | if (is_null($recipientIs) || (is_array($recipientIs) && empty($recipientIs))) { |
||
276 | unset($this->RecipientIs); |
||
277 | } else { |
||
278 | $this->RecipientIs = $recipientIs; |
||
279 | } |
||
280 | |||
281 | return $this; |
||
282 | } |
||
283 | /** |
||
284 | * Get SenderDepartments value |
||
285 | * @return \StructType\EwsProtectionRuleSenderDepartmentsType|null |
||
286 | */ |
||
287 | public function getSenderDepartments(): ?\StructType\EwsProtectionRuleSenderDepartmentsType |
||
288 | { |
||
289 | return isset($this->SenderDepartments) ? $this->SenderDepartments : null; |
||
290 | } |
||
291 | /** |
||
292 | * This method is responsible for validating the value passed to the setSenderDepartments method |
||
293 | * This method is willingly generated in order to preserve the one-line inline validation within the setSenderDepartments method |
||
294 | * This has to validate that the property which is being set is the only one among the given choices |
||
295 | * @param mixed $value |
||
296 | * @return string A non-empty message if the values does not match the validation rules |
||
297 | */ |
||
298 | public function validateSenderDepartmentsForChoiceConstraintsFromSetSenderDepartments($value): string |
||
321 | } |
||
322 | /** |
||
323 | * Set SenderDepartments value |
||
324 | * This property belongs to a choice that allows only one property to exist. It is |
||
325 | * therefore removable from the request, consequently if the value assigned to this |
||
326 | * property is null, the property is removed from this object |
||
327 | * @throws InvalidArgumentException |
||
328 | * @param \StructType\EwsProtectionRuleSenderDepartmentsType $senderDepartments |
||
329 | * @return \StructType\EwsProtectionRuleAndType |
||
330 | */ |
||
331 | public function setSenderDepartments(?\StructType\EwsProtectionRuleSenderDepartmentsType $senderDepartments = null): self |
||
332 | { |
||
333 | // validation for constraint: choice(AllInternal, And, RecipientIs, SenderDepartments, True) |
||
334 | if ('' !== ($senderDepartmentsChoiceErrorMessage = self::validateSenderDepartmentsForChoiceConstraintsFromSetSenderDepartments($senderDepartments))) { |
||
335 | throw new InvalidArgumentException($senderDepartmentsChoiceErrorMessage, __LINE__); |
||
336 | } |
||
337 | if (is_null($senderDepartments) || (is_array($senderDepartments) && empty($senderDepartments))) { |
||
338 | unset($this->SenderDepartments); |
||
339 | } else { |
||
340 | $this->SenderDepartments = $senderDepartments; |
||
341 | } |
||
342 | |||
343 | return $this; |
||
344 | } |
||
345 | /** |
||
346 | * Get True value |
||
347 | * @return string|null |
||
348 | */ |
||
349 | public function getTrue(): ?string |
||
350 | { |
||
351 | return isset($this->True) ? $this->True : null; |
||
352 | } |
||
353 | /** |
||
354 | * This method is responsible for validating the value passed to the setTrue method |
||
355 | * This method is willingly generated in order to preserve the one-line inline validation within the setTrue method |
||
356 | * This has to validate that the property which is being set is the only one among the given choices |
||
357 | * @param mixed $value |
||
358 | * @return string A non-empty message if the values does not match the validation rules |
||
359 | */ |
||
360 | public function validateTrueForChoiceConstraintsFromSetTrue($value): string |
||
383 | } |
||
384 | /** |
||
385 | * Set True value |
||
386 | * This property belongs to a choice that allows only one property to exist. It is |
||
387 | * therefore removable from the request, consequently if the value assigned to this |
||
388 | * property is null, the property is removed from this object |
||
389 | * @throws InvalidArgumentException |
||
390 | * @param string $true |
||
391 | * @return \StructType\EwsProtectionRuleAndType |
||
392 | */ |
||
393 | public function setTrue(?string $true = null): self |
||
414 | } |
||
415 | } |
||
416 |