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

PodsBuilderModuleView::_get_defaults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 9
rs 9.6666
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( 'PodsBuilderModuleView' ) ) {
10
    class PodsBuilderModuleView 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-view';
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 - View', 'pods' );
23
            $this->_description = __( "Include a file from a theme, with caching options", '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
                'view' => '',
39
                'expires' => 0,
40
                'cache_mode' => 'none'
41
            );
42
43
            return ITUtility::merge_defaults( $new_defaults, $defaults );
44
        }
45
46
        /**
47
         * Output something before the table form
48
         *
49
         * @param object $form Form class
50
         * @param bool $results
51
         */
52
        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...
53
?>
54
    <p><?php echo $this->_description; ?></p>
55
<?php
56
        }
57
58
        /**
59
         * Output something at the start of the table form
60
         *
61
         * @param object $form Form class
62
         * @param bool $results
63
         */
64
        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...
65
?>
66
    <tr>
67
        <td valign="top">
68
            <label for="view"><?php _e( 'File to include', 'pods' ); ?></label>
69
        </td>
70
        <td>
71
            <?php $form->add_text_box( 'view' ); ?>
72
        </td>
73
    </tr>
74
    <tr>
75
        <td valign="top">
76
            <label for="cache_mode"><?php _e( 'Cache Type', 'pods' ); ?></label>
77
        </td>
78
        <td>
79
            <?php
80
                $cache_modes = array(
81
                    'none' => __( 'Disable Caching', 'pods' ),
82
                    'cache' => __( 'Object Cache', 'pods' ),
83
                    'transient' => __( 'Transient', 'pods' ),
84
                    'site-transient' => __( 'Site Transient', 'pods' )
85
                );
86
87
                $form->add_drop_down( 'cache_mode', $cache_modes );
88
            ?>
89
        </td>
90
    </tr>
91
    <tr>
92
        <td valign="top">
93
            <label for="expires"><?php _e( 'Cache Expiration (in seconds)', 'pods' ); ?></label>
94
        </td>
95
        <td>
96
            <?php $form->add_text_box( 'expires' ); ?>
97
        </td>
98
    </tr>
99
<?php
100
        }
101
102
        /**
103
         * Module Output
104
         */
105
        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...
106
            $args = array(
107
                'view' => trim( pods_var_raw( 'view', $fields[ 'data' ], '' ) ),
108
                'expires' => (int) trim( pods_var_raw( 'expires', $fields[ 'data' ], ( 60 * 5 ) ) ),
109
                'cache_mode' => trim( pods_var_raw( 'cache_mode', $fields[ 'data' ], 'transient', null, true ) )
110
            );
111
112
            if ( 0 < strlen( $args[ 'view' ] ) && 'none' != $args[ 'cache_mode' ] )
113
                echo pods_shortcode( $args );
114
        }
115
116
    }
117
}
118
119
new PodsBuilderModuleView();