Completed
Push — 2.x ( ab0eb3...c52bbe )
by Scott Kingsley
05:27 queued 39s
created

PodsBuilderModuleForm::PodsBuilderModuleForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 10 and the first side effect is on line 6.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @package Pods\Components
4
 * @subpackage Builder
5
 */
6
if ( !class_exists( 'LayoutModule' ) )
7
    return;
8
9
if ( !class_exists( 'PodsBuilderModuleForm' ) ) {
10
    class PodsBuilderModuleForm extends LayoutModule {
11
12
        var $_name = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $_name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
13
        var $_var = 'pods-builder-form';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $_var.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
14
        var $_description = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $_description.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
15
        var $_editor_width = 500;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $_editor_width.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
16
        var $_can_remove_wrappers = true;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $_can_remove_wrappers.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
17
18
        /**
19
         * Register the Module
20
         */
21 View Code Duplication
        public function __construct () {
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...
22
            $this->_name = __( 'Pods - Form', 'pods' );
23
            $this->_description = __( 'Display a form for creating and editing Pod items', 'pods' );
24
            $this->module_path = dirname( __FILE__ );
25
26
            $this->LayoutModule();
27
        }
28
29
        /**
30
         * Set default variables
31
         *
32
         * @param $defaults
33
         *
34
         * @return mixed
35
         */
36
        function _get_defaults ( $defaults ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
            $new_defaults = array(
38
                'pod_type' => '',
39
                'slug' => '',
40
                'fields' => '',
41
                'label' => __( 'Submit', 'pods' ),
42
                'thank_you' => '',
43
                'sidebar' => 'none'
44
            );
45
46
            return ITUtility::merge_defaults( $new_defaults, $defaults );
47
        }
48
49
        /**
50
         * Output something before the table form
51
         *
52
         * @param object $form Form class
53
         * @param bool $results
54
         */
55
        function _before_table_edit ( $form, $results = true ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
56
?>
57
    <p><?php echo $this->_description; ?></p>
58
<?php
59
        }
60
61
        /**
62
         * Output something at the start of the table form
63
         *
64
         * @param object $form Form class
65
         * @param bool $results
66
         */
67
        function _start_table_edit ( $form, $results = true ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
68
            $api = pods_api();
69
            $all_pods = $api->load_pods( array( 'names' => true ) );
70
71
            $pod_types = array();
72
73
            foreach ( $all_pods as $pod_name => $pod_label ) {
0 ignored issues
show
Bug introduced by
The expression $all_pods of type array|object|integer|double|string|null|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
74
                $pod_types[ $pod_name ] = $pod_label . ' (' . $pod_name . ')';
75
            }
76
?>
77
    <tr>
78
        <td valign="top">
79
            <label for="pod_type"><?php _e( 'Pod', 'pods' ); ?></label>
80
        </td>
81
        <td>
82
            <?php
83 View Code Duplication
                if ( 0 < count( $all_pods ) )
84
                    $form->add_drop_down( 'pod_type', $pod_types );
85
                else
86
                    echo '<strong class="red">' . __( 'None Found', 'pods' ) . '</strong>';
87
            ?>
88
        </td>
89
    </tr>
90
    <tr>
91
        <td valign="top">
92
            <label for="slug"><?php _e( 'Slug or ID', 'pods' ); ?></label>
93
        </td>
94
        <td>
95
            <?php $form->add_text_box( 'slug' ); ?>
96
        </td>
97
    </tr>
98
    <tr>
99
        <td valign="top">
100
            <label for="fields"><?php _e( 'Fields (comma-separated)', 'pods' ); ?></label>
101
        </td>
102
        <td>
103
            <?php $form->add_text_box( 'fields' ); ?>
104
        </td>
105
    </tr>
106
    <tr>
107
        <td valign="top">
108
            <label for="label"><?php _e( 'Submit Label', 'pods' ); ?></label>
109
        </td>
110
        <td>
111
            <?php $form->add_text_box( 'label' ); ?>
112
        </td>
113
    </tr>
114
    <tr>
115
        <td valign="top">
116
            <label for="thank_you"><?php _e( 'Thank You URL upon submission', 'pods' ); ?></label>
117
        </td>
118
        <td>
119
            <?php $form->add_text_box( 'thank_you' ); ?>
120
        </td>
121
    </tr>
122
<?php
123
        }
124
125
        /**
126
         * Module Output
127
         */
128
        function _render ( $fields ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
129
            $args = array(
130
                'name' => trim( pods_var_raw( 'pod_type', $fields[ 'data' ], '' ) ),
131
                'slug' => trim( pods_var_raw( 'slug', $fields[ 'data' ], '' ) ),
132
                'fields' => trim( pods_var_raw( 'fields', $fields[ 'data' ], '' ) ),
133
                'label' => trim( pods_var_raw( 'label', $fields[ 'data' ], __( 'Submit', 'pods' ), null, true ) ),
134
                'thank_you' => trim( pods_var_raw( 'thank_you', $fields[ 'data' ], '' ) ),
135
                'form' => 1
136
            );
137
138
            if ( 0 < strlen( $args[ 'name' ] ) )
139
                echo pods_shortcode( $args, ( isset( $content ) ? $content : null ) );
0 ignored issues
show
Bug introduced by
The variable $content seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
140
        }
141
142
    }
143
}
144
145
new PodsBuilderModuleForm();