Conditions | 2 |
Paths | 2 |
Total Lines | 57 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
51 | public function init_form_fields() { |
||
52 | $shipping_methods = array(); |
||
53 | |||
54 | foreach ( WC()->shipping()->load_shipping_methods() as $method ) { |
||
|
|||
55 | $shipping_methods[ $method->id ] = $method->get_method_title(); |
||
56 | } |
||
57 | |||
58 | $this->form_fields = array( |
||
59 | 'enabled' => array( |
||
60 | 'title' => __( 'Enable COD', 'woocommerce' ), |
||
61 | 'label' => __( 'Enable Cash on Delivery', 'woocommerce' ), |
||
62 | 'type' => 'checkbox', |
||
63 | 'description' => '', |
||
64 | 'default' => 'no', |
||
65 | ), |
||
66 | 'title' => array( |
||
67 | 'title' => __( 'Title', 'woocommerce' ), |
||
68 | 'type' => 'text', |
||
69 | 'description' => __( 'Payment method description that the customer will see on your checkout.', 'woocommerce' ), |
||
70 | 'default' => __( 'Cash on Delivery', 'woocommerce' ), |
||
71 | 'desc_tip' => true, |
||
72 | ), |
||
73 | 'description' => array( |
||
74 | 'title' => __( 'Description', 'woocommerce' ), |
||
75 | 'type' => 'textarea', |
||
76 | 'description' => __( 'Payment method description that the customer will see on your website.', 'woocommerce' ), |
||
77 | 'default' => __( 'Pay with cash upon delivery.', 'woocommerce' ), |
||
78 | 'desc_tip' => true, |
||
79 | ), |
||
80 | 'instructions' => array( |
||
81 | 'title' => __( 'Instructions', 'woocommerce' ), |
||
82 | 'type' => 'textarea', |
||
83 | 'description' => __( 'Instructions that will be added to the thank you page.', 'woocommerce' ), |
||
84 | 'default' => __( 'Pay with cash upon delivery.', 'woocommerce' ), |
||
85 | 'desc_tip' => true, |
||
86 | ), |
||
87 | 'enable_for_methods' => array( |
||
88 | 'title' => __( 'Enable for shipping methods', 'woocommerce' ), |
||
89 | 'type' => 'multiselect', |
||
90 | 'class' => 'wc-enhanced-select', |
||
91 | 'css' => 'width: 450px;', |
||
92 | 'default' => '', |
||
93 | 'description' => __( 'If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.', 'woocommerce' ), |
||
94 | 'options' => $shipping_methods, |
||
95 | 'desc_tip' => true, |
||
96 | 'custom_attributes' => array( |
||
97 | 'data-placeholder' => __( 'Select shipping methods', 'woocommerce' ), |
||
98 | ), |
||
99 | ), |
||
100 | 'enable_for_virtual' => array( |
||
101 | 'title' => __( 'Accept for virtual orders', 'woocommerce' ), |
||
102 | 'label' => __( 'Accept COD if the order is virtual', 'woocommerce' ), |
||
103 | 'type' => 'checkbox', |
||
104 | 'default' => 'yes', |
||
105 | ), |
||
106 | ); |
||
107 | } |
||
108 | |||
238 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
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:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.