Completed
Pull Request — staging (#840)
by
unknown
16:43
created

FormHelper::form_title()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 3
nop 3
dl 0
loc 16
rs 9.4222
c 0
b 0
f 0
1
<?php
2
3
namespace YIKES\EasyForms\Form;
4
5
trait FormHelper {
6
    public function form_title( $title, $custom_title, $form_name ) {
7
        $form_title = '';
0 ignored issues
show
Unused Code introduced by
$form_title is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
8
        switch( true ) {
9
            case ! empty( $custom_title ) && isset( $custom_title ):
10
                $form_title = $custom_title;
11
            break;
12
            case ! empty( $title ) && isset( $title ):
13
                $form_title = $title;
14
            break;
15
            default:
16
                $form_title = $form_name;
17
            break;
18
        }
19
20
        return apply_filters( 'yikes-mailchimp-form-title', apply_filters( 'the_title', $form_title ), $this->form_id );
0 ignored issues
show
Bug introduced by
The property form_id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
21
    }
22
23
    public function form_description( $description, $custom_description ) {
24
        if ( $description ) {
25
			if ( ! empty( $custom_description ) ) {
26
				/**
27
				 * Filter the description that is displayed through the shortcode.
28
				 *
29
				 * @param string $title   The title to display.
30
				 * @param int    $form_id The form ID.
31
				 */
32
				return apply_filters( 'yikes-mailchimp-form-description', $custom_description, $this->form_id );
33
			} else {
34
				return apply_filters( 'yikes-mailchimp-form-description', $this->form_data['form_description'], $this->form_id );
0 ignored issues
show
Bug introduced by
The property form_data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
			}
36
		} else {
37
            return false;
38
        }
39
    }
40
41
    protected function reduce_field_count() {
42
		$this->field_count = $this->field_count --;
0 ignored issues
show
Bug introduced by
The property field_count does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
	}
44
45
	protected function set_field_count() {
46
		return isset( $this->form_data['fields'] ) ? count( $this->form_data['fields'] ) : 0;
47
	}
48
49
	public function form_classes( bool $is_submitted ) {
50
        $form_classes = 'yikes-easy-mc-form yikes-easy-mc-form-' . $this->form_id;
51
        if ( isset( $this->form_inline ) && $this->form_inline != 0 ) {
0 ignored issues
show
Bug introduced by
The property form_inline does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
52
            $form_classes .= ' yikes-mailchimp-form-inline';
53
        }
54
55
        if ( $is_submitted && $this->form_data['submission_settings']['hide_form_post_signup'] == 1 ) {
56
            $form_classes .=  ' yikes-easy-mc-display-none';
57
        }
58
59
        $form_classes .= $this->form_data['form_settings']['yikes-easy-mc-form-class-names'];
60
        return apply_filters( 'yikes-mailchimp-form-class', $form_classes, $this->form_id );
61
	}
62
63
	public function inline_form_override() {
64
		return isset( $this->has_recaptcha ) || ( function_exists( 'is_plugin_active' ) && is_plugin_active( 'eu-opt-in-compliance-for-mailchimp/yikes-inc-easy-mailchimp-eu-law-compliance-extension.php' ) );
65
	}
66
    
67
    public function edit_form_link() {
68
		if( current_user_can( apply_filters( 'yikes-mailchimp-user-role-access' , 'manage_options' ) ) ) {
69
			$edit_form_link = '<span class="edit-link">';
70
			$edit_form_link .= '<a class="post-edit-link" href="' . esc_url( admin_url( 'admin.php?page=yikes-mailchimp-edit-form&id=' . $this->form_id ) ) . '" title="' . __( 'Edit' , 'yikes-inc-easy-mailchimp-extender' ) . ' ' . ucwords( $this->form_data['form_name'] ) . '">' . __( 'Edit Form' , 'yikes-inc-easy-mailchimp-extender' ) . '</a>';
71
			$edit_form_link .= '</span>';
72
			$edit_form_link = apply_filters( 'yikes-mailchimp-front-end-form-action-links', $edit_form_link, $this->form_id, ucwords( $this->form_data['form_name'] ) );
73
		} else {
74
			$edit_form_link = '';
75
		}
76
		return $edit_form_link;
77
    }
78
}
79