Completed
Pull Request — staging (#840)
by
unknown
19:58
created

OptinFormBase::get_form_defaults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52

Duplication

Lines 52
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 52
loc 52
rs 9.0472
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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