| Conditions | 6 |
| Paths | 32 |
| Total Lines | 61 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 65 | function start_el( &$sOutput, $oTerm, $iDepth=0, $aArgs=array(), $iCurrentObjectID=0 ) { |
||
|
|
|||
| 66 | |||
| 67 | $aArgs = $aArgs + array( |
||
| 68 | '_name_prefix' => null, |
||
| 69 | '_input_id_prefix' => null, |
||
| 70 | '_attributes' => array(), |
||
| 71 | '_selected_items' => array(), |
||
| 72 | 'taxonomy' => null, // parsed by the core function to perform the database query. |
||
| 73 | 'disabled' => null, // not sure what this was for |
||
| 74 | '_save_unchecked' => true, // 3.8.8+ |
||
| 75 | ); |
||
| 76 | |||
| 77 | // Local variables |
||
| 78 | $_iID = $oTerm->term_id; |
||
| 79 | $_sTaxonomySlug = empty( $aArgs[ 'taxonomy' ] ) |
||
| 80 | ? 'category' |
||
| 81 | : $aArgs[ 'taxonomy' ]; |
||
| 82 | $_sID = "{$aArgs[ '_input_id_prefix' ]}_{$_sTaxonomySlug}_{$_iID}"; |
||
| 83 | |||
| 84 | // Post count |
||
| 85 | $_sPostCount = $aArgs[ 'show_post_count' ] |
||
| 86 | ? " <span class='font-lighter'>(" . $oTerm->count . ")</span>" |
||
| 87 | : ''; |
||
| 88 | |||
| 89 | // Attributes |
||
| 90 | $_aInputAttributes = isset( $_aInputAttributes[ $_iID ] ) |
||
| 91 | ? $_aInputAttributes[ $_iID ] + $aArgs[ '_attributes' ] |
||
| 92 | : $aArgs[ '_attributes' ]; |
||
| 93 | $_aInputAttributes = array( |
||
| 94 | 'id' => $_sID, |
||
| 95 | 'value' => 1, // must be 1 because the index of zero exists so the index value cannot be assigned here. |
||
| 96 | 'type' => 'checkbox', |
||
| 97 | 'name' => "{$aArgs[ '_name_prefix' ]}[{$_iID}]", |
||
| 98 | 'checked' => in_array( $_iID, ( array ) $aArgs[ '_selected_items' ] ) |
||
| 99 | ? 'checked' |
||
| 100 | : null, |
||
| 101 | ) + $_aInputAttributes |
||
| 102 | + array( |
||
| 103 | 'class' => null, |
||
| 104 | ); |
||
| 105 | $_aInputAttributes['class'] .= ' apf_checkbox'; |
||
| 106 | |||
| 107 | $_aLiTagAttributes = array( |
||
| 108 | 'id' => "list-{$_sID}", |
||
| 109 | 'class' => 'category-list', |
||
| 110 | 'title' => $oTerm->description, |
||
| 111 | ); |
||
| 112 | |||
| 113 | $_sHiddenInputForUnchecked = $aArgs[ '_save_unchecked' ] |
||
| 114 | ? "<input value='0' type='hidden' name='" . $_aInputAttributes[ 'name' ] . "' class='apf_checkbox' />" |
||
| 115 | : ''; |
||
| 116 | |||
| 117 | // Output - the variable is by reference so the modification takes effect |
||
| 118 | $sOutput .= "\n" |
||
| 119 | . "<li " . AdminPageFramework_WPUtility::getAttributes( $_aLiTagAttributes ) . ">" |
||
| 120 | . "<label for='{$_sID}' class='taxonomy-checklist-label'>" |
||
| 121 | . $_sHiddenInputForUnchecked // 3.8.8+ |
||
| 122 | . "<input " . AdminPageFramework_WPUtility::getAttributes( $_aInputAttributes ) . " />" |
||
| 123 | . esc_html( apply_filters( 'the_category', $oTerm->name ) ) |
||
| 124 | . $_sPostCount |
||
| 125 | . "</label>"; |
||
| 126 | /* no need to close the </li> tag since it is dealt in the end_el() method. */ |
||
| 130 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.