Completed
Push — master ( c1c65b...4856cf )
by Stephanie
03:24
created

FrmTipsHelper   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 191
Duplicated Lines 10.47 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 13
lcom 1
cbo 1
dl 20
loc 191
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
B pro_tip() 0 24 5
B get_builder_tip() 0 42 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() 0 16 1
A get_import_tip() 10 10 1
A get_banner_tip() 0 23 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
		$tips = self::$callback();
11
		$tip = self::get_random_tip( $tips );
12
13
		if ( $html == 'p' ) {
14
			echo '<p>';
15
		}
16
		?>
17
		<a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url( $tip['link'] ) ) ?>" target="_blank" class="frm_pro_tip">
18
			<span><i class="frm_icon_font frm_check1_icon"></i>  Pro Tip:</span>
19
			<?php echo $tip['tip'] ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$tip'
Loading history...
20
			<?php if ( isset( $tip['call'] ) ) { ?>
21
				<span><?php echo $tip['call'] ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$tip'
Loading history...
22
			<?php } ?>
23
		</a>
24
		<?php
25
		if ( $html == 'p' ) {
26
			echo '</p>';
27
		}
28
	}
29
30
	public static function get_builder_tip() {
31
		$tips = array(
32
			array(
33
				'link' => 'https://formidablepro.com/section-tip',
34
				'tip'  => __( 'Long forms can still be beautiful with sections.', 'formidable' ),
35
				'call' => __( 'Upgrade to Pro.', 'formidable' ),
36
			),
37
			array(
38
				'link' => 'https://formidablepro.com/conditional-logic-tip',
39
				'tip'  => __( 'Use conditional logic to shorten your forms and increase conversions.', 'formidable' ),
40
				'call' => __( 'Upgrade to Pro.', 'formidable' ),
41
			),
42
			array(
43
				'link' => 'https://formidablepro.com/page-break-tip',
44
				'tip'  => __( 'Stop intimidating users with long forms.', 'formidable' ),
45
				'call' => __( 'Use page breaks.', 'formidable' ),
46
			),
47
			array(
48
				'link' => 'https://formidablepro.com/file-upload-tip',
49
				'tip'  => __( 'Cut down on back-and-forth with clients.', 'formidable' ),
50
				'call' => __( 'Allow file uploads in your form.', 'formidable' ),
51
			),
52
			array(
53
				'link' => 'https://formidablepro.com/calculations-total-tip',
54
				'tip'  => __( 'Need to calculate a total?', 'formidable' ),
55
				'call' => __( 'Upgrade to Pro.', 'formidable' ),
56
			),
57
			array(
58
				'link' => 'https://formidablepro.com/create-posts-tip',
59
				'tip'  => __( 'Use this form for front-end posting.', 'formidable' ),
60
				'call' => __( 'Upgrade to Pro.', 'formidable' ),
61
			),
62
			array(
63
				'link' => 'https://formidablepro.com/downloads/mailchimp/',
64
				'tip'  => __( 'Grow your business with automated email follow-up.', 'formidable' ),
65
				'call' => __( 'Send leads straight to MailChimp.', 'formidable' ),
66
			),
67
		);
68
		$tips = array_merge( $tips, self::get_form_settings_tip(), self::get_form_action_tip(), self::get_entries_tip() );
69
70
		return $tips;
71
	}
72
73
	public static function get_form_settings_tip() {
74
		$tips = array(
75
			array(
76
				'link' => 'https://formidablepro.com/front-end-editing-tip',
77
				'tip'  => __( 'A site with dynamic, maintainable, user-generated content is within reach.', 'formidable' ),
78
				'call' => __( 'Add front-end editing.', 'formidable' ),
79
			),
80
			array(
81
				'link' => 'https://formidablepro.com/save-drafts-tip',
82
				'tip'  => __( 'Have a long form that takes time to complete?', 'formidable' ),
83
				'call' => __( 'Let logged-in users save a draft and return later.', 'formidable' ),
84
			),
85
		);
86
		return $tips;
87
	}
88
89
	public static function get_form_action_tip() {
90
		$tips = array(
91
			array(
92
				'link' => 'https://formidablepro.com/email-routing-tip',
93
				'tip'  => __( 'Save time by sending the email to the right person automatically.', 'formidable' ),
94
				'call' => __( 'Add email routing.', 'formidable' ),
95
			),
96
			array(
97
				'link' => 'https://formidablepro.com/create-posts-tip',
98
				'tip'  => __( 'Allow anyone to create blog posts using your form.', 'formidable' ),
99
				'call' => __( 'Upgrade to Pro.', 'formidable' ),
100
			),
101
			array(
102
				'link' => 'https://formidablepro.com/downloads/mailchimp/',
103
				'tip'  => __( 'Grow your business with automated email follow-up.', 'formidable' ),
104
				'call' => __( 'Send leads straight to MailChimp.', 'formidable' ),
105
			),
106
			array(
107
				'link' => 'https://formidablepro.com/downloads/paypal-standard/',
108
				'tip'  => __( 'Save hours and increase revenue by collecting payments with every submission.', 'formidable' ),
109
				'call' => __( 'Use PayPal with this form.', 'formidable' ),
110
			),
111
			array(
112
				'link' => 'https://formidablepro.com/downloads/registration-lite/',
113
				'tip'  => __( 'Start building up your site membership.', 'formidable' ),
114
				'call' => __( 'Automatically create user accounts.', 'formidable' ),
115
			),
116
			array(
117
				'link' => 'https://formidablepro.com/downloads/twilio/',
118
				'tip'  => __( 'Want a text when this form is submitted or when a payment is received?', 'formidable' ),
119
				'call' => __( 'Use Twilio with this form.', 'formidable' ),
120
			),
121
		);
122
123
		return $tips;
124
	}
125
126 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...
127
		$tips = array(
128
			array(
129
				'link' => 'https://formidablepro.com/visual-styling-tip',
130
				'tip'  => __( 'Want your sidebar or footer form to look different from the rest?', 'formidable' ),
131
				'call' => __( 'Use multiple stylesheets.', 'formidable' ),
132
			),
133
		);
134
		return $tips;
135
	}
136
137
	public static function get_entries_tip() {
138
		$tips = array(
139
			array(
140
				'link' => 'https://formidablepro.com/manage-entries-tip',
141
				'tip'  => __( 'Do you want to edit or delete form submissions?', 'formidable' ),
142
				'call' => __( 'Add entry management.', 'formidable' ),
143
			),
144
			array(
145
				'link' => 'https://formidablepro.com/search-entries-tip',
146
				'tip'  => __( 'Want to search submitted entries?', 'formidable' ),
147
				'call' => __( 'Upgrade to Pro.', 'formidable' ),
148
			),
149
		);
150
		$tips = array_merge( $tips, self::get_import_tip() );
151
		return $tips;
152
	}
153
154 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...
155
		$tips = array(
156
			array(
157
				'link' => 'https://formidablepro.com/import-entries-tip/',
158
				'tip'  => __( 'Want to import entries into your forms?', 'formidable' ),
159
				'call' => __( 'Upgrade to Pro.', 'formidable' ),
160
			),
161
		);
162
		return $tips;
163
	}
164
165
	public static function get_banner_tip() {
166
		$tips = array(
167
			array(
168
				'link' => 'https://formidablepro.com/',
169
				'tip'  => __( 'Looking for more options to get professional results?', 'formidable' ),
170
				'call' => __( 'Take your forms to the next level.', 'formidable' ),
171
			),
172
			array(
173
				'link' => 'https://formidablepro.com/',
174
				'tip'  => __( 'Increase conversions in your long forms.', 'formidable' ),
175
				'call' => __( 'Add conditional logic, page breaks, and section headings.', 'formidable' ),
176
			),
177
			array(
178
				'link' => 'https://formidablepro.com/',
179
				'tip'  => __( 'Automate your business and increase revenue.', 'formidable' ),
180
				'call' => __( 'Collect instant payments, and send leads to MailChimp.', 'formidable' ),
181
			),
182
		);
183
		$random = rand( 0, count( $tips ) - 1 );
184
		$tip = $tips[ $random ];
185
		$tip['num'] = $random;
186
		return $tip;
187
	}
188
189
	public static function get_random_tip( $tips ) {
190
		$random = rand( 0, count( $tips ) - 1 );
191
		return $tips[ $random ];
192
	}
193
}
194