Completed
Pull Request — staging (#840)
by
unknown
18:46
created

OptinFormBase   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 76
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 76
loc 76
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get_form_defaults() 52 52 1
A update_form_field() 3 3 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
 * YIKES Inc. Easy Forms.
4
 *
5
 * @package   YIKES\EasyForms
6
 * @author    Freddie Mixell
7
 * @license   GPL2
8
 */
9
10
namespace YIKES\EasyForms\Model;
11
 
12 View Code Duplication
abstract class OptinFormBase implements OptinInterface {
0 ignored issues
show
Duplication introduced by
This class 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...
13
14
	/**
15
	 * Get the default values for a form.
16
	 *
17
	 * @author Jeremy Pry
18
	 * @return array Array of default form data.
19
	 */
20
	public function get_form_defaults() {
21
		return array(
22
			'id'                      => 0,
23
			'list_id'                 => '',
24
			'form_name'               => '',
25
			'form_description'        => '',
26
			'fields'                  => array(),
27
			'custom_styles'           => '',
28
			'custom_template'         => '',
29
			'redirect_user_on_submit' => 0,
30
			'redirect_page'           => '',
31
			'submission_settings'     => array(
32
				'ajax'                   => 1,
33
				'redirect_on_submission' => 0,
34
				'redirect_page'          => 1,
35
				'hide_form_post_signup'  => 0,
36
			),
37
			'optin_settings'          => array(
38
				'optin'                => 1,
39
				'update_existing_user' => 1,
40
				'send_update_email'    => 1,
41
			),
42
			'form_settings'           => array(
43
				'yikes-easy-mc-form-class-names'                 => '',
44
				'yikes-easy-mc-inline-form'                      => 0,
45
				'yikes-easy-mc-submit-button-type'               => 'text',
46
				'yikes-easy-mc-submit-button-text'               => __( 'Submit', 'yikes-inc-easy-mailchimp-extender' ),
47
				'yikes-easy-mc-submit-button-image'              => '',
48
				'yikes-easy-mc-submit-button-classes'            => '',
49
				'yikes-easy-mc-form-schedule'                    => 0,
50
				'yikes-easy-mc-form-restriction-start'           => 0,
51
				'yikes-easy-mc-form-restriction-end'             => 0,
52
				'yikes-easy-mc-form-restriction-pending-message' => sprintf( __( 'Signup is not yet open, and will be available on %s. Please come back then to signup.', 'yikes-inc-easy-mailchimp-extender' ), current_time( str_replace( '-', '/', get_option( 'date_format' ) ) ) . ' ' . __( 'at', 'yikes-inc-easy-mailchimp-extender' ) . ' ' . current_time( 'g:iA' ) ),
53
				'yikes-easy-mc-form-restriction-expired-message' => sprintf( __( 'This signup for this form ended on %s.', 'yikes-inc-easy-mailchimp-extender' ), date( str_replace( '-', '/', get_option( 'date_format' ) ), strtotime( current_time( str_replace( '-', '/', get_option( 'date_format' ) ) ) ) + ( 3600 * 24 ) ) . ' ' . __( 'at', 'yikes-inc-easy-mailchimp-extender' ) . ' ' . date( 'g:iA', strtotime( current_time( 'g:iA' ) ) + ( 3600 * 24 ) ) ),
54
				'yikes-easy-mc-form-login-required'              => 0,
55
				'yikes-easy-mc-form-restriction-login-message'   => __( 'You need to be logged in to sign up for this mailing list.', 'yikes-inc-easy-mailchimp-extender' ),
56
			),
57
			'error_messages'			=> array(
58
				'success'				=> '',
59
				'success-single-optin'	=> '',
60
				'success-resubscribed'	=> '',
61
				'general-error'			=> '',
62
				'already-subscribed'	=> '',
63
				'update-link'			=> '',
64
				'email-subject'			=> '',
65
			),
66
			'custom_notifications'    => '',
67
			'impressions'             => 0,
68
			'submissions'             => 0,
69
			'custom_fields'           => array(),
70
		);
71
	}
72
73
	/**
74
	 * Update a given field for a form.
75
	 *
76
	 * @author Jeremy Pry
77
	 *
78
	 * @param int    $form_id The form ID to update.
79
	 * @param string $field   The form field to update.
80
	 * @param mixed  $data    The form data.
81
	 *
82
	 * @return bool Whether the form field was successfully updated.
83
	 */
84
	public function update_form_field( $form_id, $field, $data ) {
85
		return $this->update_form( $form_id, array( $field => $data ) );
86
	}
87
}
88