| Conditions | 13 |
| Paths | 61 |
| Total Lines | 67 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 68 | public function load_titan_framework() { |
||
| 69 | |||
| 70 | // Don't do anything when we're activating a plugin to prevent errors |
||
| 71 | // on redeclaring Titan classes |
||
| 72 | if ( ! empty( $_GET['action'] ) && ! empty( $_GET['plugin'] ) ) { |
||
| 73 | if ( $_GET['action'] == 'activate' ) { |
||
| 74 | return; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | // Check if the framework plugin is activated |
||
| 79 | $useEmbeddedFramework = true; |
||
| 80 | $activePlugins = get_option('active_plugins'); |
||
| 81 | if ( is_array( $activePlugins ) ) { |
||
| 82 | foreach ( $activePlugins as $plugin ) { |
||
| 83 | if ( is_string( $plugin ) ) { |
||
| 84 | if ( stripos( $plugin, '/titan-framework.php' ) !== false ) { |
||
| 85 | $useEmbeddedFramework = false; |
||
| 86 | break; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | // Use the embedded Titan Framework |
||
| 92 | if ( $useEmbeddedFramework && ! class_exists( 'TitanFramework' ) ) { |
||
| 93 | // require_once( WPBO_PATH . 'vendor/gambitph/titan-framework/titan-framework.php' ); |
||
|
|
|||
| 94 | require_once( ABSPATH . 'wp-content/Titan-Framework/titan-framework.php' ); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * wpbo_before_load_titan hook |
||
| 99 | */ |
||
| 100 | do_action( 'wpbo_before_load_titan' ); |
||
| 101 | |||
| 102 | $this->titan = TitanFramework::getInstance( 'wpbo' ); |
||
| 103 | $this->settings = $this->titan->createAdminPage( array( |
||
| 104 | 'name' => __( 'Settings', 'betteroptin' ), |
||
| 105 | 'title' => __( 'BetterOptin Settings', 'betteroptin' ), |
||
| 106 | 'parent' => 'edit.php?post_type=wpbo-popup', |
||
| 107 | 'position' => 999, |
||
| 108 | 'id' => 'wpbo-settings' |
||
| 109 | ) ); |
||
| 110 | |||
| 111 | /* Get all options */ |
||
| 112 | $options = $this->get_options(); |
||
| 113 | |||
| 114 | /* Iterate */ |
||
| 115 | foreach( $options as $tab => $content ) { |
||
| 116 | |||
| 117 | /* Add a new tab */ |
||
| 118 | $tab = $this->settings->createTab( array( |
||
| 119 | 'name' => $content['name'], |
||
| 120 | 'title' => isset( $content['title'] ) ? $content['title'] : $content['name'], |
||
| 121 | 'id' => $tab |
||
| 122 | ) |
||
| 123 | ); |
||
| 124 | |||
| 125 | /* Add all options to current tab */ |
||
| 126 | foreach( $content['options'] as $option ) { |
||
| 127 | $tab->createOption( $option ); |
||
| 128 | } |
||
| 129 | |||
| 130 | $tab->createOption( array( 'type' => 'save', ) ); |
||
| 131 | |||
| 132 | } |
||
| 133 | |||
| 134 | } |
||
| 135 | |||
| 140 | } |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.