File class-wp-rest-plugins-controller.php
has 618 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* REST API: WP_REST_Plugins_Controller class
*
* @package WordPress
Method create_item
has 103 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function create_item( $request ) {
global $wp_filesystem;
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/plugin.php';
Method get_item_schema
has 96 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function get_item_schema() {
if ( $this->schema ) {
return $this->add_additional_fields_schema( $this->schema );
}
WP_REST_Plugins_Controller
has 26 functions (exceeds 20 allowed). Consider refactoring. Open
class WP_REST_Plugins_Controller extends WP_REST_Controller {
const PATTERN = '[^.\/]+(?:\/[^.\/]+)?';
/**
Function create_item
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
public function create_item( $request ) {
global $wp_filesystem;
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/plugin.php';
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method register_routes
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function register_routes() {
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
array(
Function does_plugin_match_request
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
protected function does_plugin_match_request( $request, $item ) {
$search = $request['search'];
if ( $search ) {
$matched_search = false;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method delete_item
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function delete_item( $request ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$data = $this->get_plugin_data( $request['plugin'] );
Method prepare_item_for_response
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function prepare_item_for_response( $item, $request ) {
$fields = $this->get_fields_for_response( $request );
$item = _get_plugin_data_markup_translate( $item['_file'], $item, false );
$marked = _get_plugin_data_markup_translate( $item['_file'], $item, true );
Function plugin_status_permission_check
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function plugin_status_permission_check( $plugin, $new_status, $current_status ) {
if ( is_multisite() && ( 'network-active' === $current_status || 'network-active' === $new_status ) && ! current_user_can( 'manage_network_plugins' ) ) {
return new WP_Error(
'rest_cannot_manage_network_plugins',
__( 'Sorry, you are not allowed to manage network plugins.' ),
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function get_items
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function get_items( $request ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$plugins = array();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return in_array( $pack->language, $installed_locales, true );
Avoid too many return
statements within this method. Open
return $can_change_status;
Avoid too many return
statements within this method. Open
return $response;
Avoid too many return
statements within this method. Open
return new WP_REST_Response(
array(
'deleted' => true,
'previous' => $prepared->get_data(),
)
Avoid too many return
statements within this method. Open
return $error;
Avoid too many return
statements within this method. Open
return new WP_Error(
'unable_to_connect_to_filesystem',
$wp_filesystem->errors->get_error_message(),
array( 'status' => 500 )
);
Avoid too many return
statements within this method. Open
return (object) $item;
Avoid too many return
statements within this method. Open
return new WP_Error(
'unable_to_connect_to_filesystem',
__( 'Unable to connect to the filesystem. Please confirm your credentials.' ),
array( 'status' => 500 )
);
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return new WP_Error(
'unable_to_determine_installed_plugin',
__( 'Unable to determine what plugin was installed.' ),
array( 'status' => 500 )
);
Avoid too many return
statements within this method. Open
return $changed_status;
Function update_item_permissions_check
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function update_item_permissions_check( $request ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( ! current_user_can( 'activate_plugins' ) ) {
return new WP_Error(
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"