Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Capture 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 Capture, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | class Capture extends Entity |
||
10 | { |
||
11 | const PERSON_UDF_COUNT = 50; |
||
12 | const EVENT_UDF_COUNT = 50; |
||
13 | const TOUCH_UDF_COUNT = 20; |
||
14 | |||
15 | const UUID_PATTERN = '/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/i'; |
||
16 | |||
17 | /** |
||
18 | * Set the 'person_udf#' field. |
||
19 | * |
||
20 | * @param int $num Which field to fetch. Can be from 1 till 50 |
||
21 | * @param string $value Custom fields for the Acquia Lift Person Capture Phase |
||
22 | * |
||
23 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
24 | * |
||
25 | * @return \Acquia\LiftClient\Entity\Capture |
||
26 | */ |
||
27 | 24 | View Code Duplication | public function setPersonUdf($num, $value) |
42 | |||
43 | /** |
||
44 | * Set the 'event_udf#' field. |
||
45 | * |
||
46 | * @param int $num Which field to fetch. Can be from 1 till 50 |
||
47 | * @param string $value Custom fields for the Acquia Lift Event Capture Phase |
||
48 | * |
||
49 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
50 | * |
||
51 | * @return \Acquia\LiftClient\Entity\Capture |
||
52 | */ |
||
53 | 27 | View Code Duplication | public function setEventUdf($num, $value) |
68 | |||
69 | /** |
||
70 | * Set the 'touch_udf#' field. |
||
71 | * |
||
72 | * @param int $num Which field to fetch. Can be from 1 till 20 |
||
73 | * @param string $value Custom fields for the Acquia Lift Touch Capture Phase |
||
74 | * |
||
75 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
76 | * |
||
77 | * @return \Acquia\LiftClient\Entity\Capture |
||
78 | */ |
||
79 | 21 | View Code Duplication | public function setTouchUdf($num, $value) |
94 | |||
95 | /** |
||
96 | * Sets the 'event_name' parameter. |
||
97 | * |
||
98 | * @param string $eventName Event name corresponding to the captured information - the event type matching this |
||
99 | * event name must match the master list of events created in Acquia Lift Web |
||
100 | * |
||
101 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
102 | * |
||
103 | * @return \Acquia\LiftClient\Entity\Capture |
||
104 | */ |
||
105 | 18 | public function setEventName($eventName) |
|
114 | |||
115 | /** |
||
116 | * Sets the 'event_source' parameter. |
||
117 | * |
||
118 | * @param string $eventSource Source of the event - can be used to pass event data from tools you have set up to |
||
119 | * send data to Acquia Lift Web (the default Acquia Lift Web value is web; depending on |
||
120 | * your website's configuration, examples may include csrtool1 and promo1) |
||
121 | * |
||
122 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
123 | * |
||
124 | * @return \Acquia\LiftClient\Entity\Capture |
||
125 | */ |
||
126 | 18 | public function setEventSource($eventSource) |
|
135 | |||
136 | /** |
||
137 | * Sets the 'event_date' parameter. |
||
138 | * |
||
139 | * @param DateTime $eventDate |
||
140 | * |
||
141 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
142 | * |
||
143 | * @return \Acquia\LiftClient\Entity\Capture |
||
144 | */ |
||
145 | 15 | public function setEventDate(DateTime $eventDate) |
|
153 | |||
154 | /** |
||
155 | * Sets the 'identities' parameter. |
||
156 | * |
||
157 | * @param array $identities Additional identity information |
||
158 | * |
||
159 | * Example of how to structure the $identities parameter: |
||
160 | * <code> |
||
161 | * $options = [ |
||
162 | * '[email protected]' => 'email', |
||
163 | * 'John Smith' => 'name', |
||
164 | * ]; |
||
165 | * </code> |
||
166 | * |
||
167 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
168 | * |
||
169 | * @return \Acquia\LiftClient\Entity\Capture |
||
170 | */ |
||
171 | 18 | public function setIdentities(array $identities) |
|
180 | |||
181 | /** |
||
182 | * Sets the 'url' parameter. |
||
183 | * |
||
184 | * @param string $url Event's URL |
||
185 | * |
||
186 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
187 | * |
||
188 | * @return \Acquia\LiftClient\Entity\Capture |
||
189 | */ |
||
190 | 18 | View Code Duplication | public function setUrl($url) |
199 | |||
200 | /** |
||
201 | * Sets the 'referral_url' parameter. |
||
202 | * |
||
203 | * @param string $referralUrl Referrer's URL |
||
204 | * |
||
205 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
206 | * |
||
207 | * @return \Acquia\LiftClient\Entity\Capture |
||
208 | */ |
||
209 | 18 | public function setReferralUrl($referralUrl) |
|
218 | |||
219 | /** |
||
220 | * Sets the 'content_title' parameter. |
||
221 | * |
||
222 | * @param string $contentTitle Page title |
||
223 | * |
||
224 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
225 | * |
||
226 | * @return \Acquia\LiftClient\Entity\Capture |
||
227 | */ |
||
228 | 18 | public function setContentTitle($contentTitle) |
|
237 | |||
238 | /** |
||
239 | * Sets the 'user_agent' parameter. |
||
240 | * |
||
241 | * @param string $userAgent Visitor's user agent |
||
242 | * |
||
243 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
244 | * |
||
245 | * @return \Acquia\LiftClient\Entity\Capture |
||
246 | */ |
||
247 | 18 | public function setUserAgent($userAgent) |
|
256 | |||
257 | /** |
||
258 | * Sets the 'platform' parameter. |
||
259 | * |
||
260 | * @param string $platform Visitor's platform |
||
261 | * |
||
262 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
263 | * |
||
264 | * @return \Acquia\LiftClient\Entity\Capture |
||
265 | */ |
||
266 | 18 | public function setPlatform($platform) |
|
275 | |||
276 | /** |
||
277 | * Sets the 'ip_address' parameter. |
||
278 | * |
||
279 | * @param string $ipAddress Visitor's IP address (supports both IPv4 and IPv6 addresses) |
||
280 | * |
||
281 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
282 | * |
||
283 | * @return \Acquia\LiftClient\Entity\Capture |
||
284 | */ |
||
285 | 21 | public function setIpAddress($ipAddress) |
|
294 | |||
295 | /** |
||
296 | * Sets the 'persona' parameter. |
||
297 | * |
||
298 | * @param string $persona User-defined category into which a visitor fits, based on their viewing of particular |
||
299 | * content |
||
300 | * |
||
301 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
302 | * |
||
303 | * @return \Acquia\LiftClient\Entity\Capture |
||
304 | */ |
||
305 | 18 | public function setPersona($persona) |
|
314 | |||
315 | /** |
||
316 | * Sets the 'engagement_score' parameter. |
||
317 | * |
||
318 | * @param int $engagementScore The number that you have chosen to signify the importance of a visitor's interest in |
||
319 | * an event |
||
320 | * |
||
321 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
322 | * |
||
323 | * @return \Acquia\LiftClient\Entity\Capture |
||
324 | */ |
||
325 | 18 | public function setEngagementScore($engagementScore) |
|
334 | |||
335 | /** |
||
336 | * Sets the 'personalization_name' parameter. |
||
337 | * |
||
338 | * @param string $personalizationName Name of personalization associated with an event |
||
339 | * |
||
340 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
341 | * |
||
342 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
343 | * |
||
344 | * @return \Acquia\LiftClient\Entity\Capture |
||
345 | */ |
||
346 | public function setPersonalizationName($personalizationName) |
||
355 | |||
356 | /** |
||
357 | * Sets the 'personalization_machine_name' parameter. |
||
358 | * |
||
359 | * @param string $personalizationMachineName Machine name of personalization associated with an event |
||
360 | * |
||
361 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
362 | * |
||
363 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
364 | * |
||
365 | * @return \Acquia\LiftClient\Entity\Capture |
||
366 | */ |
||
367 | public function setPersonalizationMachineName($personalizationMachineName) |
||
376 | |||
377 | /** |
||
378 | * Sets the 'personalization_chosen_variation' parameter. |
||
379 | * |
||
380 | * @param string $personalizationChosenVariation The variation (decision) chosen for an event |
||
381 | * |
||
382 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
383 | * |
||
384 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
385 | * |
||
386 | * @return \Acquia\LiftClient\Entity\Capture |
||
387 | */ |
||
388 | public function setPersonalizationChosenVariation($personalizationChosenVariation) |
||
397 | |||
398 | /** |
||
399 | * Sets the 'personalization_audience_name' parameter. |
||
400 | * |
||
401 | * @param string $personalizationAudienceName The name of the audience |
||
402 | * |
||
403 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
404 | * |
||
405 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
406 | * |
||
407 | * @return \Acquia\LiftClient\Entity\Capture |
||
408 | */ |
||
409 | public function setPersonalizationAudienceName($personalizationAudienceName) |
||
418 | |||
419 | /** |
||
420 | * Sets the 'personalization_decision_policy' parameter. |
||
421 | * |
||
422 | * @param string $personalizationDecisionPolicy The decision policy used - for example, explore or target |
||
423 | * |
||
424 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
425 | * |
||
426 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
427 | * |
||
428 | * @return \Acquia\LiftClient\Entity\Capture |
||
429 | */ |
||
430 | public function setPersonalizationDecisionPolicy($personalizationDecisionPolicy) |
||
439 | |||
440 | /** |
||
441 | * Sets the 'personalization_goal_name' parameter. |
||
442 | * |
||
443 | * @param string $personalizationGoalName The name of the goal reached |
||
444 | * |
||
445 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
446 | * |
||
447 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
448 | * |
||
449 | * @return \Acquia\LiftClient\Entity\Capture |
||
450 | */ |
||
451 | public function setPersonalizationGoalName($personalizationGoalName) |
||
460 | |||
461 | /** |
||
462 | * Sets the 'personalization_goal_value' parameter. |
||
463 | * |
||
464 | * @param string $personalizationGoalValue The value of the goal reached |
||
465 | * |
||
466 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
467 | * |
||
468 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
469 | * |
||
470 | * @return \Acquia\LiftClient\Entity\Capture |
||
471 | */ |
||
472 | public function setPersonalizationGoalValue($personalizationGoalValue) |
||
481 | |||
482 | /** |
||
483 | * Sets the 'decision_slot_id' parameter. |
||
484 | * |
||
485 | * @param string $decisionSlotId Decision Slot Id |
||
486 | * |
||
487 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
488 | * |
||
489 | * @return \Acquia\LiftClient\Entity\Capture |
||
490 | */ |
||
491 | 18 | public function setDecisionSlotId($decisionSlotId) |
|
500 | |||
501 | /** |
||
502 | * Sets the 'decision_slot_name' parameter. |
||
503 | * |
||
504 | * @param string $decisionSlotName Decision Slot Name |
||
505 | * |
||
506 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
507 | * |
||
508 | * @return \Acquia\LiftClient\Entity\Capture |
||
509 | */ |
||
510 | 18 | public function setDecisionSlotName($decisionSlotName) |
|
519 | |||
520 | /** |
||
521 | * Sets the 'decision_rule_id' parameter. |
||
522 | * |
||
523 | * @param string $decisionRuleId Decision Slot Name |
||
524 | * |
||
525 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
526 | * |
||
527 | * @return \Acquia\LiftClient\Entity\Capture |
||
528 | */ |
||
529 | 18 | public function setDecisionRuleId($decisionRuleId) |
|
538 | |||
539 | /** |
||
540 | * Sets the 'decision_rule_name' parameter. |
||
541 | * |
||
542 | * @param string $decisionRuleName Decision Slot Name |
||
543 | * |
||
544 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
545 | * |
||
546 | * @return \Acquia\LiftClient\Entity\Capture |
||
547 | */ |
||
548 | 18 | public function setDecisionRuleName($decisionRuleName) |
|
557 | |||
558 | /** |
||
559 | * Sets the 'decision_content_id' parameter. |
||
560 | * |
||
561 | * @param string $decisionContentId Decision Content Id |
||
562 | * |
||
563 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
564 | * |
||
565 | * @return \Acquia\LiftClient\Entity\Capture |
||
566 | */ |
||
567 | 18 | public function setDecisionContentId($decisionContentId) |
|
576 | |||
577 | /** |
||
578 | * Sets the 'decision_content_name' parameter. |
||
579 | * |
||
580 | * @param string $decisionContentName Decision Content Name |
||
581 | * |
||
582 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
583 | * |
||
584 | * @return \Acquia\LiftClient\Entity\Capture |
||
585 | */ |
||
586 | 18 | public function setDecisionContentName($decisionContentName) |
|
595 | |||
596 | /** |
||
597 | * Sets the 'decision_goal_id' parameter. |
||
598 | * |
||
599 | * @param string $decisionGoalId Decision Goal Id |
||
600 | * |
||
601 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
602 | * |
||
603 | * @return \Acquia\LiftClient\Entity\Capture |
||
604 | */ |
||
605 | 18 | public function setDecisionGoalId($decisionGoalId) |
|
614 | |||
615 | /** |
||
616 | * Sets the 'decision_goal_name' parameter. |
||
617 | * |
||
618 | * @param string $decisionGoalName Decision Goal Name |
||
619 | * |
||
620 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
621 | * |
||
622 | * @return \Acquia\LiftClient\Entity\Capture |
||
623 | */ |
||
624 | 18 | public function setDecisionGoalName($decisionGoalName) |
|
633 | |||
634 | /** |
||
635 | * Sets the 'decision_goal_value' parameter. |
||
636 | * |
||
637 | * @param string $decisionGoalValue Decision Goal Value |
||
638 | * |
||
639 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
640 | * |
||
641 | * @return \Acquia\LiftClient\Entity\Capture |
||
642 | */ |
||
643 | 18 | public function setDecisionGoalValue($decisionGoalValue) |
|
652 | |||
653 | /** |
||
654 | * Sets the 'decision_view_mode' parameter. |
||
655 | * |
||
656 | * @param string $decisionViewMode Decision View Mode |
||
657 | * |
||
658 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
659 | * |
||
660 | * @return \Acquia\LiftClient\Entity\Capture |
||
661 | */ |
||
662 | 18 | public function setDecisionViewMode($decisionViewMode) |
|
671 | |||
672 | /** |
||
673 | * Sets the 'decision_policy' parameter. |
||
674 | * |
||
675 | * @param string $decisionPolicy The decision policy used - for example, explore or target |
||
676 | * |
||
677 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
678 | * |
||
679 | * @return \Acquia\LiftClient\Entity\Capture |
||
680 | */ |
||
681 | 18 | public function setDecisionPolicy($decisionPolicy) |
|
690 | |||
691 | /** |
||
692 | * Sets the 'capture_identifier' parameter. |
||
693 | * |
||
694 | * @param string $captureIdentifier Unique identifier for the capture |
||
695 | * |
||
696 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
697 | * |
||
698 | * @return \Acquia\LiftClient\Entity\Capture |
||
699 | */ |
||
700 | 18 | public function setCaptureIdentifier($captureIdentifier) |
|
709 | |||
710 | /** |
||
711 | * Sets the 'client_timezone' parameter. |
||
712 | * |
||
713 | * @param string $clientTimezone Client Timezone |
||
714 | * |
||
715 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
716 | * |
||
717 | * @return \Acquia\LiftClient\Entity\Capture |
||
718 | */ |
||
719 | 18 | public function setClientTimezone($clientTimezone) |
|
728 | |||
729 | /** |
||
730 | * Sets the 'javascript_version' parameter. |
||
731 | * |
||
732 | * @param string $javascriptVersion version of the javascript that generated the capture |
||
733 | * |
||
734 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
735 | * |
||
736 | * @return \Acquia\LiftClient\Entity\Capture |
||
737 | */ |
||
738 | 18 | public function setJavascriptVersion($javascriptVersion) |
|
747 | |||
748 | /** |
||
749 | * Sets the 'post_id' parameter. |
||
750 | * |
||
751 | * @param string $postId Post id of an article |
||
752 | * |
||
753 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
754 | * |
||
755 | * @return \Acquia\LiftClient\Entity\Capture |
||
756 | */ |
||
757 | 18 | public function setPostId($postId) |
|
766 | |||
767 | /** |
||
768 | * Sets the 'content_id' parameter. |
||
769 | * |
||
770 | * @param string $contentId Content id of an article |
||
771 | * |
||
772 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
773 | * |
||
774 | * @return \Acquia\LiftClient\Entity\Capture |
||
775 | */ |
||
776 | 18 | public function setContentId($contentId) |
|
785 | |||
786 | /** |
||
787 | * Sets the 'content_uuid' parameter. |
||
788 | * |
||
789 | * @param string $contentUuid UUID of an article |
||
790 | * |
||
791 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
792 | * |
||
793 | * @return \Acquia\LiftClient\Entity\Capture |
||
794 | */ |
||
795 | 18 | public function setContentUuid($contentUuid) |
|
804 | |||
805 | /** |
||
806 | * Sets the 'content_type' parameter. |
||
807 | * |
||
808 | * @param string $contentType Content-type to which a piece of visitor-viewed content belongs |
||
809 | * |
||
810 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
811 | * |
||
812 | * @return \Acquia\LiftClient\Entity\Capture |
||
813 | */ |
||
814 | 18 | public function setContentType($contentType) |
|
823 | |||
824 | /** |
||
825 | * Sets the 'content_section' parameter. |
||
826 | * |
||
827 | * @param string $contentSection Content section of an article |
||
828 | * |
||
829 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
830 | * |
||
831 | * @return \Acquia\LiftClient\Entity\Capture |
||
832 | */ |
||
833 | 18 | public function setContentSection($contentSection) |
|
842 | |||
843 | /** |
||
844 | * Sets the 'content_keywords' parameter. |
||
845 | * |
||
846 | * @param string $contentKeywords Content keywords of an article |
||
847 | * |
||
848 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
849 | * |
||
850 | * @return \Acquia\LiftClient\Entity\Capture |
||
851 | */ |
||
852 | 18 | public function setContentKeywords($contentKeywords) |
|
861 | |||
862 | /** |
||
863 | * Sets the 'author' parameter. |
||
864 | * |
||
865 | * @param string $author Author of an article |
||
866 | * |
||
867 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
868 | * |
||
869 | * @return \Acquia\LiftClient\Entity\Capture |
||
870 | */ |
||
871 | 24 | public function setAuthor($author) |
|
880 | |||
881 | /** |
||
882 | * Sets the 'page_type' parameter. |
||
883 | * |
||
884 | * @param string $pageType Category of page the visitor viewed (examples include article page, tag page, and home page) |
||
885 | * |
||
886 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
887 | * |
||
888 | * @return \Acquia\LiftClient\Entity\Capture |
||
889 | */ |
||
890 | 18 | public function setPageType($pageType) |
|
899 | |||
900 | /** |
||
901 | * Sets the 'thumbnail_url' parameter. |
||
902 | * |
||
903 | * @param string $thumbnailUrl Thumbnail URL of an article |
||
904 | * |
||
905 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
906 | * |
||
907 | * @return \Acquia\LiftClient\Entity\Capture |
||
908 | */ |
||
909 | 18 | public function setThumbnailUrl($thumbnailUrl) |
|
918 | |||
919 | /** |
||
920 | * Sets the 'published_date' parameter. |
||
921 | * |
||
922 | * @param DateTime $publishedDate Publish date of an article |
||
923 | * |
||
924 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
925 | * |
||
926 | * @return \Acquia\LiftClient\Entity\Capture |
||
927 | */ |
||
928 | 15 | public function setPublishedDate(DateTime $publishedDate) |
|
936 | } |
||
937 |