Passed
Pull Request — master (#374)
by Brian
107:36 queued 10:01
created

GetPaid_Meta_Box_Item_Info::output()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 71
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 47
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 71
rs 9.1563

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
/**
4
 * Item Info
5
 *
6
 * Display the item data meta box.
7
 *
8
 */
9
10
if ( ! defined( 'ABSPATH' ) ) {
11
	exit; // Exit if accessed directly
12
}
13
14
/**
15
 * GetPaid_Meta_Box_Item_Info Class.
16
 */
17
class GetPaid_Meta_Box_Item_Info {
18
19
    /**
20
	 * Output the metabox.
21
	 *
22
	 * @param WP_Post $post
23
	 */
24
    public static function output( $post ) {
25
26
        // Prepare the item.
27
        $item = new WPInv_Item( $post );
28
29
        ?>
30
31
        <div class='bsui' style='padding-top: 10px;'>
32
            <?php do_action( 'wpinv_item_before_info_metabox', $item ); ?>
33
34
            <div class="wpinv_item_type form-group row">
35
                <label for="wpinv_item_type" class="col-sm-12 col-form-label">
36
                    <?php _e( 'Item Type', 'invoicing' );?>
37
                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( self::get_tooltip( $post ) ); ?>"></span>
38
                </label>
39
40
                <div class="col-sm-12">
41
42
                    <?php
43
                        echo aui()->select(
44
                            array(
45
                                'id'               => 'wpinv_item_type',
46
                                'name'             => 'wpinv_item_type',
47
                                'placeholder'      => __( 'Select item type', 'invoicing' ),
48
                                'value'            => $item->get_type( 'edit' ),
49
                                'select2'          => true,
50
                                'data-allow-clear' => 'false',
51
                                'no_wrap'          => true,
52
                                'options'          => wpinv_get_item_types(),
53
                            )
54
                        );
55
                    ?>
56
57
                </div>
58
            </div>
59
60
            <div class="wpinv_item_shortcode form-group row">
61
                <label for="wpinv_item_shortcode" class="col-sm-12 col-form-label">
62
                    <?php _e( 'Payment Form Shortcode', 'invoicing' );?>
63
                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Displays a payment form', 'invoicing' ); ?>"></span>
64
                </label>
65
66
                <div class="col-sm-12">
67
                    <input  onClick="this.select()" type="text" id="wpinv_item_shortcode" value="[getpaid item=<?php echo esc_attr( $item->get_id() ); ?>]" style="width: 100%;" />
68
                </div>
69
            </div>
70
71
            <div class="wpinv_item_buy_shortcode form-group row">
72
                <label for="wpinv_item_button_shortcode" class="col-sm-12 col-form-label">
73
                    <?php _e( 'Payment Button Shortcode', 'invoicing' );?>
74
                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Displays a buy now button', 'invoicing' ); ?>"></span>
75
                </label>
76
77
                <div class="col-sm-12">
78
                    <input onClick="this.select()" type="text" id="wpinv_item_button_shortcode" value="[getpaid item=<?php echo esc_attr( $item->get_id() ); ?> button='Buy Now']" style="width: 100%;" />
79
                </div>
80
            </div>
81
82
            <div class="wpinv_item_custom_id form-group">
83
                <?php _e( 'Custom ID', 'invoicing' );?> &mdash; <?php echo sanitize_text_field( $item->get_custom_id() ) ?>
84
            </div>
85
86
            <?php do_action( 'wpinv_meta_values_metabox_before', $post ); ?>
87
            <?php foreach ( apply_filters( 'wpinv_show_meta_values_for_keys', array() ) as $meta_key ) : ?>
88
                <div class="wpinv_item_custom_id form-group">
89
                    <?php sanitize_text_field( $meta_key );?> &mdash; <?php echo sanitize_text_field( get_post_meta( $item->get_id(), '_wpinv_' . $meta_key, true ) ); ?>
0 ignored issues
show
Bug introduced by
It seems like get_post_meta($item->get...nv_' . $meta_key, true) can also be of type false; however, parameter $str of sanitize_text_field() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

89
                    <?php sanitize_text_field( $meta_key );?> &mdash; <?php echo sanitize_text_field( /** @scrutinizer ignore-type */ get_post_meta( $item->get_id(), '_wpinv_' . $meta_key, true ) ); ?>
Loading history...
90
                </div>
91
            <?php endforeach; ?>
92
            <?php do_action( 'wpinv_meta_values_metabox_after', $post ); ?>
93
            <?php do_action( 'wpinv_item_info_metabox', $item ); ?>
94
        </div>
95
        <?php
96
97
    }
98
99
    /**
100
	 * Returns item type tolltip.
101
	 *
102
	 */
103
    public static function get_tooltip( $post ) {
104
105
        ob_start();
106
        ?>
107
108
        <?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br> <br>
109
        <?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc', 'invoicing' );?><br> <br>
110
111
        <?php
112
        do_action( 'wpinv_item_info_metabox_after', $post );
113
114
        return ob_get_clean();
115
116
    }
117
118
}
119