felixarntz/global-admin

View on GitHub
wp-global-admin/wp-admin/global/user-edit.php

Summary

Maintainability
A
1 hr
Test Coverage

Function _ga_maybe_modify_global_administrator_setting has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

function _ga_maybe_modify_global_administrator_setting( $user_id ) {
    if ( is_multinetwork() && is_global_admin() && ! IS_PROFILE_PAGE && current_user_can( 'manage_global_options' ) ) {
        $global_administrators = get_global_option( 'global_administrators', array() );
        $user                  = get_userdata( $user_id );

Severity: Minor
Found in wp-global-admin/wp-admin/global/user-edit.php - About 1 hr to fix

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 _ga_maybe_display_global_administrator_checkbox has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

function _ga_maybe_display_global_administrator_checkbox( $user ) {
    if ( is_multinetwork() && is_global_admin() && ! IS_PROFILE_PAGE && current_user_can( 'manage_global_options' ) ) {
        ?>
        </table>

Severity: Minor
Found in wp-global-admin/wp-admin/global/user-edit.php - About 25 mins to fix

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 excessively long variable names like $global_administrators. Keep variable name length under 20.
Open

        $global_administrators = get_global_option( 'global_administrators', array() );

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

All output should be run through an escaping function (like esc_html_e() or esc_attr_e()), found '_e'.
Open

                        <p><?php _e( 'Global administrator privileges cannot be removed because this user has the global admin email.', 'wp-global-admin' ); ?></p>

All output should be run through an escaping function (like esc_html_e() or esc_attr_e()), found '_e'.
Open

                        <p><label><input type="checkbox" id="global_administrator" name="global_administrator"<?php checked( is_global_administrator( $user->ID ) ); ?> /> <?php _e( 'Grant this user global administrator privileges.', 'wp-global-admin' ); ?></label></p>

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'.
Open

    wp_die( __( 'Multinetwork support is not enabled.', 'wp-global-admin' ) );

Use Yoda Condition checks, you must.
Open

                    <?php if ( $user->user_email != get_global_option( 'admin_email' ) || ! is_global_administrator( $user->ID ) ) : ?>

All output should be run through an escaping function (like esc_html_e() or esc_attr_e()), found '_e'.
Open

                    <?php _e( 'Global Administrator', 'wp-global-admin' ); ?>

All output should be run through an escaping function (like esc_html_e() or esc_attr_e()), found '_e'.
Open

        <h2><?php _e( 'Permissions', 'wp-global-admin' ); ?></h2>

Processing form data without nonce verification.
Open

        if ( ! empty( $_POST['global_administrator'] ) ) {

There are no issues that match your filters.

Category
Status