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) |
||
152 | |||
153 | /** |
||
154 | * Sets the 'identities' parameter. |
||
155 | * |
||
156 | * @param array $identities Additional identity information |
||
157 | * |
||
158 | * Example of how to structure the $identities parameter: |
||
159 | * <code> |
||
160 | * $options = [ |
||
161 | * '[email protected]' => 'email', |
||
162 | * 'John Smith' => 'name', |
||
163 | * ]; |
||
164 | * </code> |
||
165 | * |
||
166 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
167 | * |
||
168 | * @return \Acquia\LiftClient\Entity\Capture |
||
169 | */ |
||
170 | public function setIdentities(array $identities) |
||
179 | |||
180 | /** |
||
181 | * Sets the 'url' parameter. |
||
182 | * |
||
183 | * @param string $url Event's URL |
||
184 | * |
||
185 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
186 | * |
||
187 | * @return \Acquia\LiftClient\Entity\Capture |
||
188 | */ |
||
189 | View Code Duplication | public function setUrl($url) |
|
198 | |||
199 | /** |
||
200 | * Sets the 'referral_url' parameter. |
||
201 | * |
||
202 | * @param string $referralUrl Referrer's URL |
||
203 | * |
||
204 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
205 | * |
||
206 | * @return \Acquia\LiftClient\Entity\Capture |
||
207 | */ |
||
208 | public function setReferralUrl($referralUrl) |
||
217 | |||
218 | /** |
||
219 | * Sets the 'content_title' parameter. |
||
220 | * |
||
221 | * @param string $contentTitle Page title |
||
222 | * |
||
223 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
224 | * |
||
225 | * @return \Acquia\LiftClient\Entity\Capture |
||
226 | */ |
||
227 | public function setContentTitle($contentTitle) |
||
236 | |||
237 | /** |
||
238 | * Sets the 'user_agent' parameter. |
||
239 | * |
||
240 | * @param string $userAgent Visitor's user agent |
||
241 | * |
||
242 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
243 | * |
||
244 | * @return \Acquia\LiftClient\Entity\Capture |
||
245 | */ |
||
246 | public function setUserAgent($userAgent) |
||
255 | |||
256 | /** |
||
257 | * Sets the 'platform' parameter. |
||
258 | * |
||
259 | * @param string $platform Visitor's platform |
||
260 | * |
||
261 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
262 | * |
||
263 | * @return \Acquia\LiftClient\Entity\Capture |
||
264 | */ |
||
265 | public function setPlatform($platform) |
||
274 | |||
275 | /** |
||
276 | * Sets the 'ip_address' parameter. |
||
277 | * |
||
278 | * @param string $ipAddress Visitor's IP address (supports both IPv4 and IPv6 addresses) |
||
279 | * |
||
280 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
281 | * |
||
282 | * @return \Acquia\LiftClient\Entity\Capture |
||
283 | */ |
||
284 | public function setIpAddress($ipAddress) |
||
293 | |||
294 | /** |
||
295 | * Sets the 'persona' parameter. |
||
296 | * |
||
297 | * @param string $persona User-defined category into which a visitor fits, based on their viewing of particular |
||
298 | * content |
||
299 | * |
||
300 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
301 | * |
||
302 | * @return \Acquia\LiftClient\Entity\Capture |
||
303 | */ |
||
304 | public function setPersona($persona) |
||
313 | |||
314 | /** |
||
315 | * Sets the 'engagement_score' parameter. |
||
316 | * |
||
317 | * @param int $engagementScore The number that you have chosen to signify the importance of a visitor's interest in |
||
318 | * an event |
||
319 | * |
||
320 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
321 | * |
||
322 | * @return \Acquia\LiftClient\Entity\Capture |
||
323 | */ |
||
324 | public function setEngagementScore($engagementScore) |
||
333 | |||
334 | /** |
||
335 | * Sets the 'personalization_name' parameter. |
||
336 | * |
||
337 | * @param string $personalizationName Name of personalization associated with an event |
||
338 | * |
||
339 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
340 | * |
||
341 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
342 | * |
||
343 | * @return \Acquia\LiftClient\Entity\Capture |
||
344 | */ |
||
345 | public function setPersonalizationName($personalizationName) |
||
354 | |||
355 | /** |
||
356 | * Sets the 'personalization_machine_name' parameter. |
||
357 | * |
||
358 | * @param string $personalizationMachineName Machine name of personalization associated with an event |
||
359 | * |
||
360 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
361 | * |
||
362 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
363 | * |
||
364 | * @return \Acquia\LiftClient\Entity\Capture |
||
365 | */ |
||
366 | public function setPersonalizationMachineName($personalizationMachineName) |
||
375 | |||
376 | /** |
||
377 | * Sets the 'personalization_chosen_variation' parameter. |
||
378 | * |
||
379 | * @param string $personalizationChosenVariation The variation (decision) chosen for an event |
||
380 | * |
||
381 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
382 | * |
||
383 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
384 | * |
||
385 | * @return \Acquia\LiftClient\Entity\Capture |
||
386 | */ |
||
387 | public function setPersonalizationChosenVariation($personalizationChosenVariation) |
||
396 | |||
397 | /** |
||
398 | * Sets the 'personalization_audience_name' parameter. |
||
399 | * |
||
400 | * @param string $personalizationAudienceName The name of the audience |
||
401 | * |
||
402 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
403 | * |
||
404 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
405 | * |
||
406 | * @return \Acquia\LiftClient\Entity\Capture |
||
407 | */ |
||
408 | public function setPersonalizationAudienceName($personalizationAudienceName) |
||
417 | |||
418 | /** |
||
419 | * Sets the 'personalization_decision_policy' parameter. |
||
420 | * |
||
421 | * @param string $personalizationDecisionPolicy The decision policy used - for example, explore or target |
||
422 | * |
||
423 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
424 | * |
||
425 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
426 | * |
||
427 | * @return \Acquia\LiftClient\Entity\Capture |
||
428 | */ |
||
429 | public function setPersonalizationDecisionPolicy($personalizationDecisionPolicy) |
||
438 | |||
439 | /** |
||
440 | * Sets the 'personalization_goal_name' parameter. |
||
441 | * |
||
442 | * @param string $personalizationGoalName The name of the goal reached |
||
443 | * |
||
444 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
445 | * |
||
446 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
447 | * |
||
448 | * @return \Acquia\LiftClient\Entity\Capture |
||
449 | */ |
||
450 | public function setPersonalizationGoalName($personalizationGoalName) |
||
459 | |||
460 | /** |
||
461 | * Sets the 'personalization_goal_value' parameter. |
||
462 | * |
||
463 | * @param string $personalizationGoalValue The value of the goal reached |
||
464 | * |
||
465 | * @deprecated Only used in Lift 2. For Lift 3, please use fields with prefix decision |
||
466 | * |
||
467 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
468 | * |
||
469 | * @return \Acquia\LiftClient\Entity\Capture |
||
470 | */ |
||
471 | public function setPersonalizationGoalValue($personalizationGoalValue) |
||
480 | |||
481 | /** |
||
482 | * Sets the 'decision_slot_id' parameter. |
||
483 | * |
||
484 | * @param string $decisionSlotId Decision Slot Id |
||
485 | * |
||
486 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
487 | * |
||
488 | * @return \Acquia\LiftClient\Entity\Capture |
||
489 | */ |
||
490 | public function setDecisionSlotId($decisionSlotId) |
||
499 | |||
500 | /** |
||
501 | * Sets the 'decision_slot_name' parameter. |
||
502 | * |
||
503 | * @param string $decisionSlotName Decision Slot Name |
||
504 | * |
||
505 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
506 | * |
||
507 | * @return \Acquia\LiftClient\Entity\Capture |
||
508 | */ |
||
509 | public function setDecisionSlotName($decisionSlotName) |
||
518 | |||
519 | /** |
||
520 | * Sets the 'decision_rule_id' parameter. |
||
521 | * |
||
522 | * @param string $decisionRuleId Decision Slot Name |
||
523 | * |
||
524 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
525 | * |
||
526 | * @return \Acquia\LiftClient\Entity\Capture |
||
527 | */ |
||
528 | public function setDecisionRuleId($decisionRuleId) |
||
537 | |||
538 | /** |
||
539 | * Sets the 'decision_rule_name' parameter. |
||
540 | * |
||
541 | * @param string $decisionRuleName Decision Slot Name |
||
542 | * |
||
543 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
544 | * |
||
545 | * @return \Acquia\LiftClient\Entity\Capture |
||
546 | */ |
||
547 | public function setDecisionRuleName($decisionRuleName) |
||
556 | |||
557 | /** |
||
558 | * Sets the 'decision_content_id' parameter. |
||
559 | * |
||
560 | * @param string $decisionContentId Decision Content Id |
||
561 | * |
||
562 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
563 | * |
||
564 | * @return \Acquia\LiftClient\Entity\Capture |
||
565 | */ |
||
566 | public function setDecisionContentId($decisionContentId) |
||
575 | |||
576 | /** |
||
577 | * Sets the 'decision_content_name' parameter. |
||
578 | * |
||
579 | * @param string $decisionContentName Decision Content Name |
||
580 | * |
||
581 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
582 | * |
||
583 | * @return \Acquia\LiftClient\Entity\Capture |
||
584 | */ |
||
585 | public function setDecisionContentName($decisionContentName) |
||
594 | |||
595 | /** |
||
596 | * Sets the 'decision_goal_id' parameter. |
||
597 | * |
||
598 | * @param string $decisionGoalId Decision Goal Id |
||
599 | * |
||
600 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
601 | * |
||
602 | * @return \Acquia\LiftClient\Entity\Capture |
||
603 | */ |
||
604 | public function setDecisionGoalId($decisionGoalId) |
||
613 | |||
614 | /** |
||
615 | * Sets the 'decision_goal_name' parameter. |
||
616 | * |
||
617 | * @param string $decisionGoalName Decision Goal Name |
||
618 | * |
||
619 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
620 | * |
||
621 | * @return \Acquia\LiftClient\Entity\Capture |
||
622 | */ |
||
623 | public function setDecisionGoalName($decisionGoalName) |
||
632 | |||
633 | /** |
||
634 | * Sets the 'decision_goal_value' parameter. |
||
635 | * |
||
636 | * @param string $decisionGoalValue Decision Goal Value |
||
637 | * |
||
638 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
639 | * |
||
640 | * @return \Acquia\LiftClient\Entity\Capture |
||
641 | */ |
||
642 | public function setDecisionGoalValue($decisionGoalValue) |
||
651 | |||
652 | /** |
||
653 | * Sets the 'decision_view_mode' parameter. |
||
654 | * |
||
655 | * @param string $decisionViewMode Decision View Mode |
||
656 | * |
||
657 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
658 | * |
||
659 | * @return \Acquia\LiftClient\Entity\Capture |
||
660 | */ |
||
661 | public function setDecisionViewMode($decisionViewMode) |
||
670 | |||
671 | /** |
||
672 | * Sets the 'decision_policy' parameter. |
||
673 | * |
||
674 | * @param string $decisionPolicy The decision policy used - for example, explore or target |
||
675 | * |
||
676 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
677 | * |
||
678 | * @return \Acquia\LiftClient\Entity\Capture |
||
679 | */ |
||
680 | public function setDecisionPolicy($decisionPolicy) |
||
689 | |||
690 | /** |
||
691 | * Sets the 'capture_identifier' parameter. |
||
692 | * |
||
693 | * @param string $captureIdentifier Unique identifier for the capture |
||
694 | * |
||
695 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
696 | * |
||
697 | * @return \Acquia\LiftClient\Entity\Capture |
||
698 | */ |
||
699 | public function setCaptureIdentifier($captureIdentifier) |
||
708 | |||
709 | /** |
||
710 | * Sets the 'client_timezone' parameter. |
||
711 | * |
||
712 | * @param string $clientTimezone Client Timezone |
||
713 | * |
||
714 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
715 | * |
||
716 | * @return \Acquia\LiftClient\Entity\Capture |
||
717 | */ |
||
718 | public function setClientTimezone($clientTimezone) |
||
727 | |||
728 | /** |
||
729 | * Sets the 'javascript_version' parameter. |
||
730 | * |
||
731 | * @param string $javascriptVersion version of the javascript that generated the capture |
||
732 | * |
||
733 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
734 | * |
||
735 | * @return \Acquia\LiftClient\Entity\Capture |
||
736 | */ |
||
737 | public function setJavascriptVersion($javascriptVersion) |
||
746 | |||
747 | /** |
||
748 | * Sets the 'post_id' parameter. |
||
749 | * |
||
750 | * @param string $postId Post id of an article |
||
751 | * |
||
752 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
753 | * |
||
754 | * @return \Acquia\LiftClient\Entity\Capture |
||
755 | */ |
||
756 | public function setPostId($postId) |
||
765 | |||
766 | /** |
||
767 | * Sets the 'content_id' parameter. |
||
768 | * |
||
769 | * @param string $contentId Content id of an article |
||
770 | * |
||
771 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
772 | * |
||
773 | * @return \Acquia\LiftClient\Entity\Capture |
||
774 | */ |
||
775 | public function setContentId($contentId) |
||
776 | { |
||
777 | if (!is_string($contentId)) { |
||
778 | throw new LiftSdkException('Argument must be an instance of string.'); |
||
779 | } |
||
780 | $this['content_id'] = $contentId; |
||
781 | |||
782 | return $this; |
||
783 | } |
||
784 | |||
785 | /** |
||
786 | * Sets the 'content_type' parameter. |
||
787 | * |
||
788 | * @param string $contentType Content-type to which a piece of visitor-viewed content belongs |
||
789 | * |
||
790 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
791 | * |
||
792 | * @return \Acquia\LiftClient\Entity\Capture |
||
793 | */ |
||
794 | public function setContentType($contentType) |
||
803 | |||
804 | /** |
||
805 | * Sets the 'content_section' parameter. |
||
806 | * |
||
807 | * @param string $contentSection Content section of an article |
||
808 | * |
||
809 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
810 | * |
||
811 | * @return \Acquia\LiftClient\Entity\Capture |
||
812 | */ |
||
813 | public function setContentSection($contentSection) |
||
822 | |||
823 | /** |
||
824 | * Sets the 'content_keywords' parameter. |
||
825 | * |
||
826 | * @param string $contentKeywords Content keywords of an article |
||
827 | * |
||
828 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
829 | * |
||
830 | * @return \Acquia\LiftClient\Entity\Capture |
||
831 | */ |
||
832 | public function setContentKeywords($contentKeywords) |
||
841 | |||
842 | /** |
||
843 | * Sets the 'author' parameter. |
||
844 | * |
||
845 | * @param string $author Author of an article |
||
846 | * |
||
847 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
848 | * |
||
849 | * @return \Acquia\LiftClient\Entity\Capture |
||
850 | */ |
||
851 | public function setAuthor($author) |
||
860 | |||
861 | /** |
||
862 | * Sets the 'page_type' parameter. |
||
863 | * |
||
864 | * @param string $pageType Category of page the visitor viewed (examples include article page, tag page, and home page) |
||
865 | * |
||
866 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
867 | * |
||
868 | * @return \Acquia\LiftClient\Entity\Capture |
||
869 | */ |
||
870 | public function setPageType($pageType) |
||
879 | |||
880 | /** |
||
881 | * Sets the 'thumbnail_url' parameter. |
||
882 | * |
||
883 | * @param string $thumbnailUrl Thumbnail URL of an article |
||
884 | * |
||
885 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
886 | * |
||
887 | * @return \Acquia\LiftClient\Entity\Capture |
||
888 | */ |
||
889 | public function setThumbnailUrl($thumbnailUrl) |
||
898 | |||
899 | /** |
||
900 | * Sets the 'published_date' parameter. |
||
901 | * |
||
902 | * @param DateTime $publishedDate Publish date of an article |
||
903 | * |
||
904 | * @throws \Acquia\LiftClient\Exception\LiftSdkException |
||
905 | * |
||
906 | * @return \Acquia\LiftClient\Entity\Capture |
||
907 | */ |
||
908 | public function setPublishedDate(DateTime $publishedDate) |
||
917 | } |
||
918 |