Complex classes like AdminPageFramework_Resource_admin_page often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AdminPageFramework_Resource_admin_page, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class AdminPageFramework_Resource_admin_page extends AdminPageFramework_Resource_Base { |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Applies page and tab specific filters to inline CSS rules. |
||
| 28 | * |
||
| 29 | * @since 3.5.0 |
||
| 30 | * @return void |
||
| 31 | */ |
||
| 32 | protected function _printClassSpecificStyles( $sIDPrefix ) { |
||
| 68 | /** |
||
| 69 | * Returns the currently loaded page slug to apply resource filters. |
||
| 70 | * |
||
| 71 | * If the page has not been added, an empty value will be returned. |
||
| 72 | * |
||
| 73 | * @since 3.5.3 |
||
| 74 | * @return string The page slug if the page has been added. |
||
| 75 | */ |
||
| 76 | private function _getCurrentPageSlugForFilter() { |
||
| 82 | /** |
||
| 83 | * Returns the currently loaded tab slug to apply resource filters. |
||
| 84 | * |
||
| 85 | * If the tab has not been added, an empty value will be returned. |
||
| 86 | * |
||
| 87 | * @since 3.5.3 |
||
| 88 | * @return string The tab slug if the tab has been added. |
||
| 89 | */ |
||
| 90 | private function _getCurrentTabSlugForFilter( $sPageSlug ) { |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Applies page and tab specific filters to inline JaveScript scirpts. |
||
| 99 | * |
||
| 100 | * @since 3.5.0 |
||
| 101 | * @return void |
||
| 102 | */ |
||
| 103 | protected function _printClassSpecificScripts( $sIDPrefix ) { |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Enqueues styles by page slug and tab slug. |
||
| 142 | * |
||
| 143 | * @since 2.1.5 |
||
| 144 | * @internal |
||
| 145 | */ |
||
| 146 | public function _enqueueStyles( $aSRCs, $sPageSlug='', $sTabSlug='', $aCustomArgs=array() ) { |
||
| 155 | /** |
||
| 156 | * Enqueues a style by page slug and tab slug. |
||
| 157 | * |
||
| 158 | * <h4>Custom Argument Array for the Fourth Parameter</h4> |
||
| 159 | * <ul> |
||
| 160 | * <li><strong>handle_id</strong> - ( optional, string ) The handle ID of the stylesheet.</li> |
||
| 161 | * <li><strong>dependencies</strong> - ( optional, array ) The dependency array. For more information, see <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_style">codex</a>.</li> |
||
| 162 | * <li><strong>version</strong> - ( optional, string ) The stylesheet version number.</li> |
||
| 163 | * <li><strong>media</strong> - ( optional, string ) the description of the field which is inserted into the after the input field tag.</li> |
||
| 164 | * </ul> |
||
| 165 | * |
||
| 166 | * @since 2.1.2 |
||
| 167 | * @since 2.1.5 Moved from the main class. |
||
| 168 | * @see http://codex.wordpress.org/Function_Reference/wp_enqueue_style |
||
| 169 | * @param string $sSRC The URL of the stylesheet to enqueue, the absolute file path, or the relative path to the root directory of WordPress. Example: '/css/mystyle.css'. |
||
| 170 | * @param string $sPageSlug (optional) The page slug that the stylesheet should be added to. If not set, it applies to all the pages created by the framework. |
||
| 171 | * @param string $sTabSlug (optional) The tab slug that the stylesheet should be added to. If not set, it applies to all the in-page tabs in the page. |
||
| 172 | * @param array $aCustomArgs (optional) The argument array for more advanced parameters. |
||
| 173 | * @return string The script handle ID. If the passed url is not a valid url string, an empty string will be returned. |
||
| 174 | * @internal |
||
| 175 | */ |
||
| 176 | public function _enqueueStyle( $sSRC, $sPageSlug='', $sTabSlug='', $aCustomArgs=array() ) { |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Enqueues scripts by page slug and tab slug. |
||
| 182 | * |
||
| 183 | * @since 2.1.5 |
||
| 184 | */ |
||
| 185 | public function _enqueueScripts( $aSRCs, $sPageSlug='', $sTabSlug='', $aCustomArgs=array() ) { |
||
| 194 | /** |
||
| 195 | * Enqueues a script by page slug and tab slug. |
||
| 196 | * |
||
| 197 | * <h4>Custom Argument Array for the Fourth Parameter</h4> |
||
| 198 | * <ul> |
||
| 199 | * <li><strong>handle_id</strong> - ( optional, string ) The handle ID of the script.</li> |
||
| 200 | * <li><strong>dependencies</strong> - ( optional, array ) The dependency array. For more information, see <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script">codex</a>.</li> |
||
| 201 | * <li><strong>version</strong> - ( optional, string ) The stylesheet version number.</li> |
||
| 202 | * <li><strong>translation</strong> - ( optional, array ) The translation array. The handle ID will be used for the object name.</li> |
||
| 203 | * <li><strong>in_footer</strong> - ( optional, boolean ) Whether to enqueue the script before < / head > or before < / body > Default: <code>false</code>.</li> |
||
| 204 | * </ul> |
||
| 205 | * |
||
| 206 | * @since 2.1.2 |
||
| 207 | * @since 2.1.5 Moved from the main class. |
||
| 208 | * @see http://codex.wordpress.org/Function_Reference/wp_enqueue_script |
||
| 209 | * @param string $sSRC The URL of the stylesheet to enqueue, the absolute file path, or the relative path to the root directory of WordPress. Example: '/js/myscript.js'. |
||
| 210 | * @param string $sPageSlug (optional) The page slug that the script should be added to. If not set, it applies to all the pages created by the framework. |
||
| 211 | * @param string $sTabSlug (optional) The tab slug that the script should be added to. If not set, it applies to all the in-page tabs in the page. |
||
| 212 | * @param array $aCustomArgs (optional) The argument array for more advanced parameters. |
||
| 213 | * @return string The script handle ID. If the passed url is not a valid url string, an empty string will be returned. |
||
| 214 | * @internal |
||
| 215 | */ |
||
| 216 | public function _enqueueScript( $sSRC, $sPageSlug='', $sTabSlug='', $aCustomArgs=array() ) { |
||
| 219 | /** |
||
| 220 | * Enqueues a resouce. |
||
| 221 | * |
||
| 222 | * @since 3.5.3 |
||
| 223 | * @param string $sSRC The source path or url. |
||
| 224 | * @param string $sPageSlug The page slug that the item gets enqueued. |
||
| 225 | * @param string $sTabSlug The page slug that the item gets enqueued. |
||
| 226 | * @param array $aCustomArgs A custom argument array. |
||
| 227 | * @param string $sType Accepts 'style' or 'script' |
||
| 228 | */ |
||
| 229 | private function _enqueueResourceByType( $sSRC, $sPageSlug='', $sTabSlug='', $aCustomArgs=array(), $sType='style' ) { |
||
| 264 | /** |
||
| 265 | * Returns the property name that contains the information of resources by type. |
||
| 266 | * @since 3.5.3 |
||
| 267 | * @return string the property name that contains the information of resources by type. |
||
| 268 | */ |
||
| 269 | private function _getContainerPropertyNameByType( $sType ) { |
||
| 278 | /** |
||
| 279 | * Returns the property name that contains the added count of resources by type. |
||
| 280 | * @since 3.5.3 |
||
| 281 | * @return string the property name that contains the added count of resources by type. |
||
| 282 | */ |
||
| 283 | private function _getEnqueuedIndexPropertyNameByType( $sType ) { |
||
| 292 | /** |
||
| 293 | * Enqueues a style source without conditions. |
||
| 294 | * |
||
| 295 | * @remark Used for inserting the input field head tag elements. |
||
| 296 | * @since 3.0.0 |
||
| 297 | * @internal |
||
| 298 | */ |
||
| 299 | public function _forceToEnqueueStyle( $sSRC, $aCustomArgs=array() ) { |
||
| 302 | /** |
||
| 303 | * Enqueues a script source without conditions. |
||
| 304 | * |
||
| 305 | * @remark Used for inserting the input field head tag elements. |
||
| 306 | * @since 3.0.0 |
||
| 307 | * @internal |
||
| 308 | */ |
||
| 309 | public function _forceToEnqueueScript( $sSRC, $aCustomArgs=array() ) { |
||
| 312 | |||
| 313 | |||
| 314 | /** |
||
| 315 | * A helper function for the _replyToEnqueueScripts() and _replyToEnqueueStyle() methods. |
||
| 316 | * |
||
| 317 | * @since 2.1.2 |
||
| 318 | * @since 2.1.5 Moved from the main class. Changed the name from enqueueSRCByPageConditoin. |
||
| 319 | * @since 3.7.0 Fixed a typo in the method name. |
||
| 320 | * @internal |
||
| 321 | */ |
||
| 322 | protected function _enqueueSRCByCondition( $aEnqueueItem ) { |
||
| 352 | } |
||
| 353 |