Completed
Push — master ( 49ca71...4cc6b6 )
by Stephanie
12:25
created

FrmTipsHelper   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 143
Duplicated Lines 20.98 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 12
lcom 1
cbo 1
dl 30
loc 143
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
B pro_tip() 0 22 5
B get_builder_tip() 0 26 1
A get_form_settings_tip() 0 15 1
B get_form_action_tip() 0 36 1
A get_styling_tip() 10 10 1
A get_entries_tip() 10 10 1
A get_import_tip() 10 10 1
A get_random_tip() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

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:

1
<?php
2
3
class FrmTipsHelper {
4
5
	public static function pro_tip( $callback, $html = '' ) {
6
		if ( FrmAppHelper::pro_is_installed() ) {
7
			return;
8
		}
9
10
		$tip = self::$callback();
11
		if ( $html == 'p' ) {
12
			echo '<p>';
13
		}
14
		?>
15
		<a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url( $tip['link'] ) ) ?>" target="_blank" class="frm_pro_tip">
16
			<span><i class="frm_icon_font frm_check1_icon"></i>  Pro Tip:</span>
17
			<?php echo $tip['tip'] ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$tip'
Loading history...
18
			<?php if ( isset( $tip['call'] ) ) { ?>
19
				<span><?php echo $tip['call'] ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$tip'
Loading history...
20
			<?php } ?>
21
		</a>
22
		<?php
23
		if ( $html == 'p' ) {
24
			echo '</p>';
25
		}
26
	}
27
28
	public static function get_builder_tip() {
29
		$tips = array(
30
			array(
31
				'link' => 'https://formidablepro.com/section-tip',
32
				'tip'  => __( 'Long forms can still be beautiful and manageable with sections.', 'formidable' ),
33
				'call' => __( 'Upgrade to Pro.', 'formidable' ),
34
			),
35
			array(
36
				'link' => 'https://formidablepro.com/conditional-logic-tip',
37
				'tip'  => __( 'Use conditional logic to shorten your forms and increase conversions.', 'formidable' ),
38
				'call' => __( 'Upgrade to Pro.', 'formidable' ),
39
			),
40
			array(
41
				'link' => 'https://formidablepro.com/page-break-tip',
42
				'tip'  => __( 'Increase conversions by showing fewer fields at a time with page breaks.', 'formidable' ),
43
				'call' => __( 'Upgrade to Pro.', 'formidable' ),
44
			),
45
			array(
46
				'link' => 'https://formidablepro.com/file-upload-tip',
47
				'tip'  => __( 'Cut down on back-and-forth with clients.', 'formidable' ),
48
				'call' => __( 'Allow file uploads in your form.', 'formidable' ),
49
			),
50
		);
51
52
		return self::get_random_tip( $tips );
53
	}
54
55
	public static function get_form_settings_tip() {
56
		$tips = array(
57
			array(
58
				'link' => 'https://formidablepro.com/front-end-editing-tip',
59
				'tip'  => __( 'A site with dynamic, maintainable, user-generated content is within reach.', 'formidable' ),
60
				'call' => __( 'Add front-end editing.', 'formidable' ),
61
			),
62
			array(
63
				'link' => 'https://formidablepro.com/save-drafts-tip',
64
				'tip'  => __( 'Have a long form that takes time to complete?', 'formidable' ),
65
				'call' => __( 'Let logged-in users save a draft and return later.', 'formidable' ),
66
			),
67
		);
68
		return self::get_random_tip( $tips );
69
	}
70
71
	public static function get_form_action_tip() {
72
		$tips = array(
73
			array(
74
				'link' => 'https://formidablepro.com/email-routing-tip',
75
				'tip'  => __( 'Save time by sending the email to the right person automatically.', 'formidable' ),
76
				'call' => __( 'Add email routing.', 'formidable' ),
77
			),
78
			array(
79
				'link' => 'https://formidablepro.com/create-posts-tip',
80
				'tip'  => __( 'Allow anyone to create a blog post right from your form.', 'formidable' ),
81
				'call' => __( 'Upgrade to Pro.', 'formidable' ),
82
			),
83
			array(
84
				'link' => 'https://formidablepro.com/downloads/mailchimp/',
85
				'tip'  => __( 'Grow your business with automated email follow-up.', 'formidable' ),
86
				'call' => __( 'Send leads straight to MailChimp.', 'formidable' ),
87
			),
88
			array(
89
				'link' => 'https://formidablepro.com/downloads/paypal-standard/',
90
				'tip'  => __( 'Save hours and increase revenue by collecting payments with every submission.', 'formidable' ),
91
				'call' => __( 'Use PayPal with this form.', 'formidable' ),
92
			),
93
			array(
94
				'link' => 'https://formidablepro.com/downloads/registration-lite/',
95
				'tip'  => __( 'Start building up your site membership.', 'formidable' ),
96
				'call' => __( 'Automatically create user accounts.', 'formidable' ),
97
			),
98
			array(
99
				'link' => 'https://formidablepro.com/downloads/twilio/',
100
				'tip'  => __( 'Want a text when this form is submitted or when a payment is received?', 'formidable' ),
101
				'call' => __( 'Use Twilio with this form.', 'formidable' ),
102
			),
103
		);
104
105
		return self::get_random_tip( $tips );
106
	}
107
108 View Code Duplication
	public static function get_styling_tip() {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
109
		$tips = array(
110
			array(
111
				'link' => 'https://formidablepro.com/visual-styling-tip',
112
				'tip'  => __( 'Want your sidebar or footer form to look different from the rest?', 'formidable' ),
113
				'call' => __( 'Use multiple stylesheets.', 'formidable' ),
114
			),
115
		);
116
		return $tips[0];
117
	}
118
119 View Code Duplication
	public static function get_entries_tip() {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
120
		$tips = array(
121
			array(
122
				'link' => 'https://formidablepro.com/manage-entries-tip',
123
				'tip'  => __( 'Are you looking for a specific entry? Do you want to delete or edit your submissions?', 'formidable' ),
124
				'call' => __( 'Add entry management.', 'formidable' ),
125
			),
126
		);
127
		return $tips[0];
128
	}
129
130 View Code Duplication
	public static function get_import_tip() {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
131
		$tips = array(
132
			array(
133
				'link' => 'https://formidablepro.com/import-entries-tip/',
134
				'tip'  => __( 'Want to import entries into your forms?', 'formidable' ),
135
				'call' => __( 'Upgrade to Pro.', 'formidable' ),
136
			),
137
		);
138
		return $tips[0];
139
	}
140
141
	public static function get_random_tip( $tips ) {
142
		$random = rand( 0, count( $tips ) - 1 );
143
		return $tips[ $random ];
144
	}
145
}
146