| Conditions | 6 |
| Paths | 6 |
| Total Lines | 148 |
| Code Lines | 99 |
| 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 |
||
| 30 | function perform_gallery_settings_upgrade( $foogallery ) { |
||
| 31 | |||
| 32 | $mappings = array( |
||
| 33 | array( |
||
| 34 | 'id' => 'border-style', |
||
| 35 | 'value' => 'border-style-square-white', |
||
| 36 | 'new' => array( |
||
| 37 | array ( 'id' => 'theme', 'value' => 'fg-light' ), |
||
| 38 | array ( 'id' => 'border-size', 'value' => 'fg-border-thin' ), |
||
| 39 | array ( 'id' => 'drop-shadow', 'value' => 'fg-shadow-small' ) |
||
| 40 | ) |
||
| 41 | ), |
||
| 42 | array( |
||
| 43 | 'id' => 'border-style', |
||
| 44 | 'value' => 'border-style-circle-white', |
||
| 45 | 'new' => array( |
||
| 46 | array ( 'id' => 'theme', 'value' => 'fg-light' ), |
||
| 47 | array ( 'id' => 'border-size', 'value' => 'fg-border-thin' ), |
||
| 48 | array ( 'id' => 'drop-shadow', 'value' => 'fg-shadow-small' ), |
||
| 49 | array ( 'id' => 'rounded-corners', 'value' => 'fg-round-full' ) |
||
| 50 | ) |
||
| 51 | ), |
||
| 52 | array( |
||
| 53 | 'id' => 'border-style', |
||
| 54 | 'value' => 'border-style-square-black', |
||
| 55 | 'new' => array( |
||
| 56 | array ( 'id' => 'theme', 'value' => 'fg-dark' ), |
||
| 57 | array ( 'id' => 'border-size', 'value' => 'fg-border-thin' ), |
||
| 58 | array ( 'id' => 'drop-shadow', 'value' => 'fg-shadow-small' ) |
||
| 59 | ) |
||
| 60 | ), |
||
| 61 | array( |
||
| 62 | 'id' => 'border-style', |
||
| 63 | 'value' => 'border-style-circle-black', |
||
| 64 | 'new' => array( |
||
| 65 | array ( 'id' => 'theme', 'value' => 'fg-dark' ), |
||
| 66 | array ( 'id' => 'border-size', 'value' => 'fg-border-thin' ), |
||
| 67 | array ( 'id' => 'drop-shadow', 'value' => 'fg-shadow-small' ), |
||
| 68 | array ( 'id' => 'rounded-corners', 'value' => 'fg-round-full' ) |
||
| 69 | ) |
||
| 70 | ), |
||
| 71 | array( |
||
| 72 | 'id' => 'border-style', |
||
| 73 | 'value' => 'border-style-inset', |
||
| 74 | 'new' => array( |
||
| 75 | array ( 'id' => 'theme', 'value' => 'fg-light' ), |
||
| 76 | array ( 'id' => 'inset-shadow', 'value' => 'fg-shadow-inset-large' ) |
||
| 77 | ) |
||
| 78 | ), |
||
| 79 | array( |
||
| 80 | 'id' => 'border-style', |
||
| 81 | 'value' => 'border-style-rounded', |
||
| 82 | 'new' => array( |
||
| 83 | array ( 'id' => 'theme', 'value' => 'fg-light' ), |
||
| 84 | array ( 'id' => 'rounded-corners', 'value' => 'fg-round-small' ) |
||
| 85 | ) |
||
| 86 | ), |
||
| 87 | array( |
||
| 88 | 'id' => 'spacing', |
||
| 89 | 'value' => 'spacing-width-0', |
||
| 90 | 'new' => array( |
||
| 91 | array ( 'id' => 'spacing', 'value' => 'fg-gutter-0' ) |
||
| 92 | ) |
||
| 93 | ), |
||
| 94 | array( |
||
| 95 | 'id' => 'spacing', |
||
| 96 | 'value' => 'spacing-width-5', |
||
| 97 | 'new' => array( |
||
| 98 | array ( 'id' => 'spacing', 'value' => 'fg-gutter-5' ) |
||
| 99 | ) |
||
| 100 | ), |
||
| 101 | array( |
||
| 102 | 'id' => 'spacing', |
||
| 103 | 'value' => 'spacing-width-10', |
||
| 104 | 'new' => array( |
||
| 105 | array ( 'id' => 'spacing', 'value' => 'fg-gutter-10' ) |
||
| 106 | ) |
||
| 107 | ), |
||
| 108 | array( |
||
| 109 | 'id' => 'spacing', |
||
| 110 | 'value' => 'spacing-width-15', |
||
| 111 | 'new' => array( |
||
| 112 | array ( 'id' => 'spacing', 'value' => 'fg-gutter-15' ) |
||
| 113 | ) |
||
| 114 | ), |
||
| 115 | array( |
||
| 116 | 'id' => 'spacing', |
||
| 117 | 'value' => 'spacing-width-20', |
||
| 118 | 'new' => array( |
||
| 119 | array ( 'id' => 'spacing', 'value' => 'fg-gutter-20' ) |
||
| 120 | ) |
||
| 121 | ), |
||
| 122 | array( |
||
| 123 | 'id' => 'spacing', |
||
| 124 | 'value' => 'spacing-width-25', |
||
| 125 | 'new' => array( |
||
| 126 | array ( 'id' => 'spacing', 'value' => 'fg-gutter-25' ) |
||
| 127 | ) |
||
| 128 | ), |
||
| 129 | |||
| 130 | array( |
||
| 131 | 'id' => 'alignment', |
||
| 132 | 'value' => 'alignment-left', |
||
| 133 | 'new' => array( |
||
| 134 | array ( 'id' => 'alignment', 'value' => 'fg-left' ) |
||
| 135 | ) |
||
| 136 | ), |
||
| 137 | array( |
||
| 138 | 'id' => 'alignment', |
||
| 139 | 'value' => 'alignment-center', |
||
| 140 | 'new' => array( |
||
| 141 | array ( 'id' => 'alignment', 'value' => 'fg-center' ) |
||
| 142 | ) |
||
| 143 | ), |
||
| 144 | array( |
||
| 145 | 'id' => 'alignment', |
||
| 146 | 'value' => 'alignment-right', |
||
| 147 | 'new' => array( |
||
| 148 | array ( 'id' => 'alignment', 'value' => 'fg-right' ) |
||
| 149 | ) |
||
| 150 | ), |
||
| 151 | ); |
||
| 152 | |||
| 153 | //upgrade all template settings |
||
| 154 | foreach ( foogallery_gallery_templates() as $template ) { |
||
| 155 | |||
| 156 | foreach ( $mappings as $mapping ) { |
||
| 157 | |||
| 158 | $settings_key = "{$template['slug']}_{$mapping['id']}"; |
||
| 159 | |||
| 160 | //check if the settings exists |
||
| 161 | if ( array_key_exists( $settings_key, $foogallery->settings ) ) { |
||
| 162 | |||
| 163 | $old_settings_value = $foogallery->settings[$settings_key]; |
||
| 164 | |||
| 165 | if ( $mapping['value'] === $old_settings_value ) { |
||
| 166 | //we have found a match! |
||
| 167 | |||
| 168 | foreach ( $mapping['new'] as $setting_to_create ) { |
||
| 169 | $new_setting_key = "{$template['slug']}_{$setting_to_create['id']}"; |
||
| 170 | $new_setting_value = $setting_to_create['value']; |
||
| 171 | $foogallery->settings[$new_setting_key] = $new_setting_value; |
||
| 172 | } |
||
| 173 | } |
||
| 174 | } |
||
| 175 | } |
||
| 176 | } |
||
| 177 | } |
||
| 178 | } |
||
| 179 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.