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 | /** |
||
16 | * Set the 'person_udf#' field. |
||
17 | * |
||
18 | * @param int $num Which field to fetch. Can be from 1 till 50 |
||
19 | * @param string $value Custom fields for the Acquia Lift Person Capture Phase |
||
20 | * |
||
21 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
22 | * |
||
23 | * @return \Acquia\LiftClient\Entity\Capture |
||
24 | */ |
||
25 | View Code Duplication | public function setPersonUdf($num, $value) |
|
40 | |||
41 | /** |
||
42 | * Set the 'event_udf#' field. |
||
43 | * |
||
44 | * @param int $num Which field to fetch. Can be from 1 till 50 |
||
45 | * @param string $value Custom fields for the Acquia Lift Event Capture Phase |
||
46 | * |
||
47 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
48 | * |
||
49 | * @return \Acquia\LiftClient\Entity\Capture |
||
50 | */ |
||
51 | View Code Duplication | public function setEventUdf($num, $value) |
|
66 | |||
67 | /** |
||
68 | * Set the 'touch_udf#' field. |
||
69 | * |
||
70 | * @param int $num Which field to fetch. Can be from 1 till 20 |
||
71 | * @param string $value Custom fields for the Acquia Lift Touch Capture Phase |
||
72 | * |
||
73 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
74 | * |
||
75 | * @return \Acquia\LiftClient\Entity\Capture |
||
76 | */ |
||
77 | View Code Duplication | public function setTouchUdf($num, $value) |
|
92 | |||
93 | /** |
||
94 | * Sets the 'event_name' parameter. |
||
95 | * |
||
96 | * @param string $eventName Event name corresponding to the captured information - the event type matching this |
||
97 | * event name must match the master list of events created in Acquia Lift Web |
||
98 | * |
||
99 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
100 | * |
||
101 | * @return \Acquia\LiftClient\Entity\Capture |
||
102 | */ |
||
103 | public function setEventName($eventName) |
||
112 | |||
113 | /** |
||
114 | * Sets the 'event_source' parameter. |
||
115 | * |
||
116 | * @param string $eventSource Source of the event - can be used to pass event data from tools you have set up to |
||
117 | * send data to Acquia Lift Web (the default Acquia Lift Web value is web; depending on |
||
118 | * your website's configuration, examples may include csrtool1 and promo1) |
||
119 | * |
||
120 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
121 | * |
||
122 | * @return \Acquia\LiftClient\Entity\Capture |
||
123 | */ |
||
124 | public function setEventSource($eventSource) |
||
133 | |||
134 | /** |
||
135 | * Sets the 'event_date' parameter. |
||
136 | * |
||
137 | * @param DateTime $eventDate |
||
138 | * |
||
139 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
140 | * |
||
141 | * @return \Acquia\LiftClient\Entity\Capture |
||
142 | */ |
||
143 | public function setEventDate(DateTime $eventDate) |
||
149 | |||
150 | /** |
||
151 | * Sets the 'identities' parameter. |
||
152 | * |
||
153 | * @param array $identities Additional identity information |
||
154 | * |
||
155 | * Example of how to structure the $identities parameter: |
||
156 | * <code> |
||
157 | * $options = [ |
||
158 | * '[email protected]' => 'email', |
||
159 | * 'John Smith' => 'name', |
||
160 | * ]; |
||
161 | * </code> |
||
162 | * |
||
163 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
164 | * |
||
165 | * @return \Acquia\LiftClient\Entity\Capture |
||
166 | */ |
||
167 | public function setIdentities(array $identities) |
||
176 | |||
177 | /** |
||
178 | * Sets the 'url' parameter. |
||
179 | * |
||
180 | * @param string $url Event's URL |
||
181 | * |
||
182 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
183 | * |
||
184 | * @return \Acquia\LiftClient\Entity\Capture |
||
185 | */ |
||
186 | View Code Duplication | public function setUrl($url) |
|
195 | |||
196 | /** |
||
197 | * Sets the 'site_id' parameter. |
||
198 | * |
||
199 | * @param string $siteId The customer site matching external_site_id in the configuration database |
||
200 | * |
||
201 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
202 | * |
||
203 | * @return \Acquia\LiftClient\Entity\Capture |
||
204 | */ |
||
205 | View Code Duplication | public function setSiteId($siteId) |
|
214 | |||
215 | /** |
||
216 | * Sets the 'referral_url' parameter. |
||
217 | * |
||
218 | * @param string $referralUrl Referrer's URL |
||
219 | * |
||
220 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
221 | * |
||
222 | * @return \Acquia\LiftClient\Entity\Capture |
||
223 | */ |
||
224 | public function setReferralUrl($referralUrl) |
||
233 | |||
234 | /** |
||
235 | * Sets the 'content_title' parameter. |
||
236 | * |
||
237 | * @param string $contentTitle Page title |
||
238 | * |
||
239 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
240 | * |
||
241 | * @return \Acquia\LiftClient\Entity\Capture |
||
242 | */ |
||
243 | public function setContentTitle($contentTitle) |
||
252 | |||
253 | /** |
||
254 | * Sets the 'user_agent' parameter. |
||
255 | * |
||
256 | * @param string $userAgent Visitor's user agent |
||
257 | * |
||
258 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
259 | * |
||
260 | * @return \Acquia\LiftClient\Entity\Capture |
||
261 | */ |
||
262 | public function setUserAgent($userAgent) |
||
271 | |||
272 | /** |
||
273 | * Sets the 'platform' parameter. |
||
274 | * |
||
275 | * @param string $platform Visitor's platform |
||
276 | * |
||
277 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
278 | * |
||
279 | * @return \Acquia\LiftClient\Entity\Capture |
||
280 | */ |
||
281 | public function setPlatform($platform) |
||
290 | |||
291 | /** |
||
292 | * Sets the 'ip_address' parameter. |
||
293 | * |
||
294 | * @param string $ipAddress Visitor's IP address (supports both IPv4 and IPv6 addresses) |
||
295 | * |
||
296 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
297 | * |
||
298 | * @return \Acquia\LiftClient\Entity\Capture |
||
299 | */ |
||
300 | public function setIpAddress($ipAddress) |
||
309 | |||
310 | /** |
||
311 | * Sets the 'persona' parameter. |
||
312 | * |
||
313 | * @param string $persona User-defined category into which a visitor fits, based on their viewing of particular |
||
314 | * content |
||
315 | * |
||
316 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
317 | * |
||
318 | * @return \Acquia\LiftClient\Entity\Capture |
||
319 | */ |
||
320 | public function setPersona($persona) |
||
329 | |||
330 | /** |
||
331 | * Sets the 'engagement_score' parameter. |
||
332 | * |
||
333 | * @param int $engagementScore The number that you have chosen to signify the importance of a visitor's interest in |
||
334 | * an event |
||
335 | * |
||
336 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
337 | * |
||
338 | * @return \Acquia\LiftClient\Entity\Capture |
||
339 | */ |
||
340 | public function setEngagementScore($engagementScore) |
||
349 | |||
350 | /** |
||
351 | * Sets the 'personalization_name' parameter. |
||
352 | * |
||
353 | * @param string $personalizationName Name of personalization associated with an event |
||
354 | * |
||
355 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
356 | * |
||
357 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
358 | * |
||
359 | * @return \Acquia\LiftClient\Entity\Capture |
||
360 | */ |
||
361 | public function setPersonalizationName($personalizationName) |
||
370 | |||
371 | /** |
||
372 | * Sets the 'personalization_machine_name' parameter. |
||
373 | * |
||
374 | * @param string $personalizationMachineName Machine name of personalization associated with an event |
||
375 | * |
||
376 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
377 | * |
||
378 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
379 | * |
||
380 | * @return \Acquia\LiftClient\Entity\Capture |
||
381 | */ |
||
382 | public function setPersonalizationMachineName($personalizationMachineName) |
||
391 | |||
392 | /** |
||
393 | * Sets the 'personalization_chosen_variation' parameter. |
||
394 | * |
||
395 | * @param string $personalizationChosenVariation The variation (decision) chosen for an event |
||
396 | * |
||
397 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
398 | * |
||
399 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
400 | * |
||
401 | * @return \Acquia\LiftClient\Entity\Capture |
||
402 | */ |
||
403 | public function setPersonalizationChosenVariation($personalizationChosenVariation) |
||
412 | |||
413 | /** |
||
414 | * Sets the 'personalization_audience_name' parameter. |
||
415 | * |
||
416 | * @param string $personalizationAudienceName The name of the audience |
||
417 | * |
||
418 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
419 | * |
||
420 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
421 | * |
||
422 | * @return \Acquia\LiftClient\Entity\Capture |
||
423 | */ |
||
424 | public function setPersonalizationAudienceName($personalizationAudienceName) |
||
433 | |||
434 | /** |
||
435 | * Sets the 'personalization_decision_policy' parameter. |
||
436 | * |
||
437 | * @param string $personalizationDecisionPolicy The decision policy used - for example, explore or target |
||
438 | * |
||
439 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
440 | * |
||
441 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
442 | * |
||
443 | * @return \Acquia\LiftClient\Entity\Capture |
||
444 | */ |
||
445 | public function setPersonalizationDecisionPolicy($personalizationDecisionPolicy) |
||
454 | |||
455 | /** |
||
456 | * Sets the 'personalization_goal_name' parameter. |
||
457 | * |
||
458 | * @param string $personalizationGoalName The name of the goal reached |
||
459 | * |
||
460 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
461 | * |
||
462 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
463 | * |
||
464 | * @return \Acquia\LiftClient\Entity\Capture |
||
465 | */ |
||
466 | public function setPersonalizationGoalName($personalizationGoalName) |
||
475 | |||
476 | /** |
||
477 | * Sets the 'personalization_goal_value' parameter. |
||
478 | * |
||
479 | * @param string $personalizationGoalValue The value of the goal reached |
||
480 | * |
||
481 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
482 | * |
||
483 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
484 | * |
||
485 | * @return \Acquia\LiftClient\Entity\Capture |
||
486 | */ |
||
487 | public function setPersonalizationGoalValue($personalizationGoalValue) |
||
496 | |||
497 | /** |
||
498 | * Sets the 'decision_slot_id' parameter. |
||
499 | * |
||
500 | * @param string $decisionSlotId Decision Slot Id |
||
501 | * |
||
502 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
503 | * |
||
504 | * @return \Acquia\LiftClient\Entity\Capture |
||
505 | */ |
||
506 | public function setDecisionSlotId($decisionSlotId) |
||
515 | |||
516 | /** |
||
517 | * Sets the 'decision_slot_name' parameter. |
||
518 | * |
||
519 | * @param string $decisionSlotName Decision Slot Name |
||
520 | * |
||
521 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
522 | * |
||
523 | * @return \Acquia\LiftClient\Entity\Capture |
||
524 | */ |
||
525 | public function setDecisionSlotName($decisionSlotName) |
||
534 | |||
535 | /** |
||
536 | * Sets the 'decision_rule_id' parameter. |
||
537 | * |
||
538 | * @param string $decisionRuleId Decision Slot Name |
||
539 | * |
||
540 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
541 | * |
||
542 | * @return \Acquia\LiftClient\Entity\Capture |
||
543 | */ |
||
544 | public function setDecisionRuleId($decisionRuleId) |
||
553 | |||
554 | /** |
||
555 | * Sets the 'decision_rule_name' parameter. |
||
556 | * |
||
557 | * @param string $decisionRuleName Decision Slot Name |
||
558 | * |
||
559 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
560 | * |
||
561 | * @return \Acquia\LiftClient\Entity\Capture |
||
562 | */ |
||
563 | public function setDecisionRuleName($decisionRuleName) |
||
572 | |||
573 | /** |
||
574 | * Sets the 'decision_content_id' parameter. |
||
575 | * |
||
576 | * @param string $decisionContentId Decision Content Id |
||
577 | * |
||
578 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
579 | * |
||
580 | * @return \Acquia\LiftClient\Entity\Capture |
||
581 | */ |
||
582 | public function setDecisionContentId($decisionContentId) |
||
591 | |||
592 | /** |
||
593 | * Sets the 'decision_content_name' parameter. |
||
594 | * |
||
595 | * @param string $decisionContentName Decision Content Name |
||
596 | * |
||
597 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
598 | * |
||
599 | * @return \Acquia\LiftClient\Entity\Capture |
||
600 | */ |
||
601 | public function setDecisionContentName($decisionContentName) |
||
610 | |||
611 | /** |
||
612 | * Sets the 'decision_goal_id' parameter. |
||
613 | * |
||
614 | * @param string $decisionGoalId Decision Goal Id |
||
615 | * |
||
616 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
617 | * |
||
618 | * @return \Acquia\LiftClient\Entity\Capture |
||
619 | */ |
||
620 | public function setDecisionGoalId($decisionGoalId) |
||
629 | |||
630 | /** |
||
631 | * Sets the 'decision_goal_name' parameter. |
||
632 | * |
||
633 | * @param string $decisionGoalName Decision Goal Name |
||
634 | * |
||
635 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
636 | * |
||
637 | * @return \Acquia\LiftClient\Entity\Capture |
||
638 | */ |
||
639 | public function setDecisionGoalName($decisionGoalName) |
||
648 | |||
649 | /** |
||
650 | * Sets the 'decision_goal_value' parameter. |
||
651 | * |
||
652 | * @param string $decisionGoalValue Decision Goal Value |
||
653 | * |
||
654 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
655 | * |
||
656 | * @return \Acquia\LiftClient\Entity\Capture |
||
657 | */ |
||
658 | public function setDecisionGoalValue($decisionGoalValue) |
||
667 | |||
668 | /** |
||
669 | * Sets the 'decision_view_mode' parameter. |
||
670 | * |
||
671 | * @param string $decisionViewMode Decision View Mode |
||
672 | * |
||
673 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
674 | * |
||
675 | * @return \Acquia\LiftClient\Entity\Capture |
||
676 | */ |
||
677 | public function setDecisionViewMode($decisionViewMode) |
||
686 | |||
687 | /** |
||
688 | * Sets the 'decision_policy' parameter. |
||
689 | * |
||
690 | * @param string $decisionPolicy The decision policy used - for example, explore or target |
||
691 | * |
||
692 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
693 | * |
||
694 | * @return \Acquia\LiftClient\Entity\Capture |
||
695 | */ |
||
696 | public function setDecisionPolicy($decisionPolicy) |
||
705 | |||
706 | /** |
||
707 | * Sets the 'capture_identifier' parameter. |
||
708 | * |
||
709 | * @param string $captureIdentifier Unique identifier for the capture |
||
710 | * |
||
711 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
712 | * |
||
713 | * @return \Acquia\LiftClient\Entity\Capture |
||
714 | */ |
||
715 | public function setCaptureIdentifier($captureIdentifier) |
||
724 | |||
725 | /** |
||
726 | * Sets the 'client_timezone' parameter. |
||
727 | * |
||
728 | * @param string $clientTimezone Client Timezone |
||
729 | * |
||
730 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
731 | * |
||
732 | * @return \Acquia\LiftClient\Entity\Capture |
||
733 | */ |
||
734 | public function setClientTimezone($clientTimezone) |
||
743 | |||
744 | /** |
||
745 | * Sets the 'javascript_version' parameter. |
||
746 | * |
||
747 | * @param string $javascriptVersion version of the javascript that generated the capture |
||
748 | * |
||
749 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
750 | * |
||
751 | * @return \Acquia\LiftClient\Entity\Capture |
||
752 | */ |
||
753 | public function setJavascriptVersion($javascriptVersion) |
||
762 | |||
763 | /** |
||
764 | * Sets the 'post_id' parameter. |
||
765 | * |
||
766 | * @param string $postId Post id of an article |
||
767 | * |
||
768 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
769 | * |
||
770 | * @return \Acquia\LiftClient\Entity\Capture |
||
771 | */ |
||
772 | public function setPostId($postId) |
||
781 | |||
782 | /** |
||
783 | * Sets the 'content_id' parameter. |
||
784 | * |
||
785 | * @param string $contentId Content id of an article |
||
786 | * |
||
787 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
788 | * |
||
789 | * @return \Acquia\LiftClient\Entity\Capture |
||
790 | */ |
||
791 | View Code Duplication | public function setContentId($contentId) |
|
800 | |||
801 | /** |
||
802 | * Sets the 'content_type' parameter. |
||
803 | * |
||
804 | * @param string $contentType Content-type to which a piece of visitor-viewed content belongs |
||
805 | * |
||
806 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
807 | * |
||
808 | * @return \Acquia\LiftClient\Entity\Capture |
||
809 | */ |
||
810 | public function setContentType($contentType) |
||
819 | |||
820 | /** |
||
821 | * Sets the 'content_section' parameter. |
||
822 | * |
||
823 | * @param string $contentSection Content section of an article |
||
824 | * |
||
825 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
826 | * |
||
827 | * @return \Acquia\LiftClient\Entity\Capture |
||
828 | */ |
||
829 | public function setContentSection($contentSection) |
||
838 | |||
839 | /** |
||
840 | * Sets the 'content_keywords' parameter. |
||
841 | * |
||
842 | * @param string $contentKeywords Content keywords of an article |
||
843 | * |
||
844 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
845 | * |
||
846 | * @return \Acquia\LiftClient\Entity\Capture |
||
847 | */ |
||
848 | public function setContentKeywords($contentKeywords) |
||
857 | |||
858 | /** |
||
859 | * Sets the 'author' parameter. |
||
860 | * |
||
861 | * @param string $author Author of an article |
||
862 | * |
||
863 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
864 | * |
||
865 | * @return \Acquia\LiftClient\Entity\Capture |
||
866 | */ |
||
867 | public function setAuthor($author) |
||
876 | |||
877 | /** |
||
878 | * Sets the 'page_type' parameter. |
||
879 | * |
||
880 | * @param string $pageType Category of page the visitor viewed (examples include article page, tag page, and home page) |
||
881 | * |
||
882 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
883 | * |
||
884 | * @return \Acquia\LiftClient\Entity\Capture |
||
885 | */ |
||
886 | public function setPageType($pageType) |
||
895 | |||
896 | /** |
||
897 | * Sets the 'thumbnail_url' parameter. |
||
898 | * |
||
899 | * @param string $thumbnailUrl Thumbnail URL of an article |
||
900 | * |
||
901 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
902 | * |
||
903 | * @return \Acquia\LiftClient\Entity\Capture |
||
904 | */ |
||
905 | public function setThumbnailUrl($thumbnailUrl) |
||
914 | |||
915 | /** |
||
916 | * Sets the 'published_date' parameter. |
||
917 | * |
||
918 | * @param DateTime $publishedDate Publish date of an article |
||
919 | * |
||
920 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
921 | * |
||
922 | * @return \Acquia\LiftClient\Entity\Capture |
||
923 | */ |
||
924 | public function setPublishedDate(DateTime $publishedDate) |
||
930 | } |
||
931 |