Passed
Pull Request — master (#375)
by Brian
87:27
created

WPInv_Meta_Box_Payment_Form::output()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 78
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 33
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 78
rs 9.392

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
// MUST have WordPress.
3
if ( !defined( 'WPINC' ) ) {
4
    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
5
}
6
7
class WPInv_Meta_Box_Payment_Form {
8
9
    /**
10
     * Output payment form details.
11
     *
12
     * @param WP_Post $post
13
     */
14
    public static function output_details( $post ) {
15
        $details = get_post_meta( $post->ID, 'payment_form_data', true );
16
17
        if ( ! is_array( $details ) ) {
18
            return;
19
        }
20
21
        echo '<div class="gdmbx2-wrap form-table"> <div class="gdmbx2-metabox gdmbx-field-list">';
22
23
        foreach ( $details as $key => $value ) {
24
            $key = sanitize_text_field( $key );
25
26
            if ( is_array( $value ) ) {
27
                $value = implode( ',', $value );
28
            }
29
30
            $value = esc_html( $value );
31
32
            echo "<div class='gdmbx-row gdmbx-type-select'>";
33
            echo "<div class='gdmbx-th'><label>$key:</label></div>";
34
            echo "<div class='gdmbx-td'>$value</div></div>";
35
        }
36
37
        echo "</div></div>";
38
39
    }
40
41
    /**
42
     * Output fields.
43
     *
44
     * @param WP_Post $post
45
     */
46
    public static function output_shortcode( $post ) {
47
48
        if ( ! is_numeric( $post ) ) {
0 ignored issues
show
introduced by
The condition is_numeric($post) is always false.
Loading history...
49
            $post = $post->ID;
50
        }
51
52
        if ( $post == wpinv_get_default_payment_form() ) {
53
            echo '&mdash;';
54
            return;
55
        }
56
57
        echo "<input type='text' style='min-width: 220px;' value='[getpaid form=$post]' disabled>";
58
59
    }
60
61
}
62
63