| Conditions | 18 |
| Paths | 37 |
| Total Lines | 62 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 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 |
||
| 93 | public function __construct( $name, $plugin, $requirements ) { |
||
| 94 | |||
| 95 | $this->name = htmlspecialchars( strip_tags( $name ) ); |
||
| 96 | $this->plugin = $plugin; |
||
| 97 | $this->requirements = $requirements; |
||
| 98 | |||
| 99 | if ( ! empty( $requirements ) && is_array( $requirements ) ) { |
||
| 100 | |||
| 101 | $failures = $extensions = array(); |
||
| 102 | |||
| 103 | $requirements = array_merge( |
||
| 104 | array( |
||
| 105 | 'WordPress' => '', |
||
| 106 | 'PHP' => '', |
||
| 107 | 'Extensions' => '', |
||
| 108 | ), $requirements |
||
| 109 | ); |
||
| 110 | |||
| 111 | // Check for WordPress version. |
||
| 112 | if ( $requirements['WordPress'] && is_string( $requirements['WordPress'] ) ) { |
||
| 113 | if ( function_exists( 'get_bloginfo' ) ) { |
||
| 114 | $wp_version = get_bloginfo( 'version' ); |
||
| 115 | if ( version_compare( $wp_version, $requirements['WordPress'] ) === - 1 ) { |
||
| 116 | $failures['WordPress'] = $wp_version; |
||
| 117 | $this->wp = false; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | // Check fo PHP version. |
||
| 123 | if ( $requirements['PHP'] && is_string( $requirements['PHP'] ) ) { |
||
| 124 | if ( version_compare( PHP_VERSION, $requirements['PHP'] ) === -1 ) { |
||
| 125 | $failures['PHP'] = PHP_VERSION; |
||
| 126 | $this->php = false; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | // Check fo PHP Extensions. |
||
| 131 | if ( $requirements['Extensions'] && is_array( $requirements['Extensions'] ) ) { |
||
| 132 | foreach ( $requirements['Extensions'] as $extension ) { |
||
| 133 | if ( $extension && is_string( $extension ) ) { |
||
| 134 | $extensions[ $extension ] = extension_loaded( $extension ); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | if ( in_array( false, $extensions ) ) { |
||
| 138 | foreach ( $extensions as $extension_name => $found ) { |
||
| 139 | if ( $found === false ) { |
||
|
|
|||
| 140 | $failures['Extensions'][ $extension_name ] = $extension_name; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | $this->extensions = false; |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | $this->failures = $failures; |
||
| 148 | |||
| 149 | } else { |
||
| 150 | |||
| 151 | trigger_error( 'WP Requirements: the requirements are invalid.', E_USER_ERROR ); |
||
| 152 | |||
| 153 | } |
||
| 154 | } |
||
| 155 | |||
| 272 |