| Conditions | 3 | 
| Paths | 4 | 
| Total Lines | 139 | 
| Code Lines | 103 | 
| 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 | ||
| 47 |       private function __construct() { | ||
| 48 | |||
| 49 | $plugin_data = get_file_data( ( dirname( __DIR__ ) . '/wp-amd.php' ), array( | ||
| 50 | 'Name' => 'Plugin Name', | ||
| 51 | 'Version' => 'Version', | ||
| 52 | 'TextDomain' => 'Text Domain', | ||
| 53 | ), 'plugin' ); | ||
| 54 | |||
| 55 | $this->version = trim( $plugin_data[ 'Version' ] ); | ||
|  | |||
| 56 | $this->domain = trim( $plugin_data[ 'TextDomain' ] ); | ||
| 57 | |||
| 58 | // Initialize Settings. | ||
| 59 | $this->settings = new Settings( array( | ||
| 60 | 'key' => 'wp_amd', | ||
| 61 | 'data' => array( | ||
| 62 | 'version' => $this->version, | ||
| 63 | 'domain' => $this->domain, | ||
| 64 | 'assets' => array( | ||
| 65 | 'script' => array( | ||
| 66 | 'type' => 'script', | ||
| 67 | 'disk_cache' => apply_filters( 'wp-amd:script:disk_cache', false, $this ), | ||
| 68 | 'extension' => 'js', | ||
| 69 | 'minify' => false, | ||
| 70 | 'admin_menu' => true, | ||
| 71 | 'load_in_head' => false, | ||
| 72 | 'permalink' => apply_filters( 'wp-amd:script:path', 'assets/wp-amd.js', $this ), | ||
| 73 | 'dependencies' => apply_filters( 'wp-amd:script:dependencies', array( | ||
| 74 | 'jquery' => array( | ||
| 75 | 'id' => 'jquery', | ||
| 76 | 'name' => 'jQuery', | ||
| 77 | 'infourl' => 'http://jquery.com', | ||
| 78 | 'version' => '2.1.0', | ||
| 79 | 'url' => '//ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.0.min.js', | ||
| 80 | ), | ||
| 81 | 'backbone' => array( | ||
| 82 | 'id' => 'backbone', | ||
| 83 | 'name' => 'Backbone.js', | ||
| 84 | 'infourl' => 'http://backbonejs.com', | ||
| 85 | 'url' => 'http://backbonejs.org/backbone-min.js', | ||
| 86 | ), | ||
| 87 | 'lodash' => array( | ||
| 88 | 'id' => 'lodash', | ||
| 89 | 'name' => 'Lodash', | ||
| 90 | 'infourl' => 'http://lodash.com', | ||
| 91 | 'version' => '2.4.1', | ||
| 92 | 'url' => 'http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js', | ||
| 93 | ), | ||
| 94 | 'knockout' => array( | ||
| 95 | 'id' => 'knockout', | ||
| 96 | 'name' => 'Knockout.js', | ||
| 97 | 'version' => '2.2.1', | ||
| 98 | 'infourl' => 'http://knockoutjs.com', | ||
| 99 | 'url' => 'http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js', | ||
| 100 | ), | ||
| 101 | 'udx-requires' => array( | ||
| 102 | 'id' => 'udx-requires', | ||
| 103 | 'name' => 'Requires.js (UDX)', | ||
| 104 | 'infourl' => 'http://cdn.udx.io', | ||
| 105 | 'version' => '4.0.0', | ||
| 106 | 'url' => '//cdn.udx.io/udx.requires.js', | ||
| 107 | ), | ||
| 108 | 'twitter-bootstrap' => array( | ||
| 109 | 'id' => 'twitter-bootstrap', | ||
| 110 | 'name' => 'Twitter Bootstrap', | ||
| 111 | 'infourl' => 'http://getbootstrap.com/', | ||
| 112 | 'version' => '3.1.1', | ||
| 113 | 'url' => '//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js' | ||
| 114 | ), | ||
| 115 | 'google-analytics' => array( | ||
| 116 | 'id' => 'google-analytics', | ||
| 117 | 'name' => 'Google Analytics', | ||
| 118 | 'infourl' => 'http://google-analytics.com/', | ||
| 119 | 'version' => '3.1.1', | ||
| 120 | 'url' => '//www.google-analytics.com/urchin.js' | ||
| 121 | ) | ||
| 122 | ), $this ), | ||
| 123 | ), | ||
| 124 | 'style' => array( | ||
| 125 | 'type' => 'style', | ||
| 126 | 'minify' => false, | ||
| 127 | 'disk_cache' => apply_filters( 'wp-amd:script:disk_cache', false, $this ), | ||
| 128 | 'permalink' => apply_filters( 'wp-amd:style:path', 'assets/wp-amd.css', $this ), | ||
| 129 | 'extension' => 'css', | ||
| 130 | 'admin_menu' => true, | ||
| 131 | 'load_in_head' => true, | ||
| 132 | 'dependencies' => apply_filters( 'wp-amd:style:dependencies', array( | ||
| 133 | 'twitter-bootstrap' => array( | ||
| 134 | 'id' => 'twitter-bootstrap', | ||
| 135 | 'name' => 'Twitter Bootstrap', | ||
| 136 | 'version' => '3.1.1', | ||
| 137 | 'infourl' => 'http://getbootstrap.com/', | ||
| 138 | 'url' => '//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css' | ||
| 139 | ), | ||
| 140 | 'normalize' => array( | ||
| 141 | 'id' => 'normalize', | ||
| 142 | 'name' => 'Normalize', | ||
| 143 | 'version' => '3.0.1', | ||
| 144 | 'infourl' => 'http://getbootstrap.com/', | ||
| 145 | 'url' => '//cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.min.css' | ||
| 146 | ), | ||
| 147 | 'fontawesome' => array( | ||
| 148 | 'id' => 'fontawesome', | ||
| 149 | 'name' => 'Font Awesome', | ||
| 150 | 'infourl' => 'http://fontawesome.io/', | ||
| 151 | 'url' => '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.min.css' | ||
| 152 | ), | ||
| 153 | ), $this ), | ||
| 154 | ) | ||
| 155 | ) | ||
| 156 | ) | ||
| 157 | )); | ||
| 158 | |||
| 159 |         if( !class_exists( 'ChromePhp' ) ) { | ||
| 160 | include (__DIR__ . '/class-chrome-php.php'); | ||
| 161 | } | ||
| 162 | |||
| 163 | // Set Dynamics. | ||
| 164 | $this->set( 'version', $this->version ); | ||
| 165 | $this->set( 'locale', $this->domain ); | ||
| 166 | |||
| 167 | // Initialize Style and Script classes. | ||
| 168 | $this->style = new Style( $this->get( 'assets.style' ), $this ); | ||
| 169 | $this->script = new Script( $this->get( 'assets.script' ), $this ); | ||
| 170 | |||
| 171 |         // ChromePhp::log('wp-amd: bootstrapping.'.$_SERVER['REQUEST_URI']); | ||
| 172 | // ChromePhp::log($_SERVER); | ||
| 173 | |||
| 174 |         if( file_exists( dirname( __DIR__ ) . '/lib/class-minit.php' ) ) { | ||
| 175 | require_once( dirname( __DIR__ ) . '/lib/class-minit.php' ); | ||
| 176 | } | ||
| 177 | |||
| 178 | // AJAX Update Handler. | ||
| 179 | add_action( 'wp_ajax_/amd/v1/asset', array( $this, 'ajax_handler' ) ); | ||
| 180 | |||
| 181 | // Handle dynamic URL identification for plugin assets. | ||
| 182 | add_filter( 'includes_url', array( $this, 'includes_url' ), 20, 2 ); | ||
| 183 | add_filter( 'plugins_url', array( $this, 'plugins_url' ), 20, 2 ); | ||
| 184 | |||
| 185 | } | ||
| 186 | |||
| 314 | 
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.