felixarntz/wp-site-identity

View on GitHub
src/admin-pages/settings-fields/class-wp-site-identity-settings-field-control-callbacks.php

Summary

Maintainability
B
5 hrs
Test Coverage

The class WP_Site_Identity_Settings_Field_Control_Callbacks has 12 public methods. Consider refactoring WP_Site_Identity_Settings_Field_Control_Callbacks to keep number of public methods under 10.
Open

final class WP_Site_Identity_Settings_Field_Control_Callbacks {

    /**
     * Renders a text control for a field.
     *

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

File class-wp-site-identity-settings-field-control-callbacks.php has 256 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * WP_Site_Identity_Settings_Field_Control_Callbacks class
 *
 * @package WPSiteIdentity

    Function render_number_control has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        public function render_number_control( $value, WP_Site_Identity_Settings_Field $field ) {
            $attrs = $this->make_base_attrs( $field, array(
                'check_description' => true,
            ) );
            $props = $this->make_base_props( $field );

    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 render_number_control has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function render_number_control( $value, WP_Site_Identity_Settings_Field $field ) {
            $attrs = $this->make_base_attrs( $field, array(
                'check_description' => true,
            ) );
            $props = $this->make_base_props( $field );

      Function attrs has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          private function attrs( array $attrs ) {
              foreach ( $attrs as $attr => $value ) {
                  if ( is_array( $value ) || is_object( $value ) ) {
                      $value = wp_json_encode( $value );
                  }

      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 class names like WP_Site_Identity_Settings_Field_Control_Callbacks. Keep class name length under 40.
      Open

      final class WP_Site_Identity_Settings_Field_Control_Callbacks {
      
          /**
           * Renders a text control for a field.
           *

      LongClassName

      Since: 2.9

      Detects when classes or interfaces are declared with excessively long names.

      Example

      class ATooLongClassNameThatHintsAtADesignProblem {
      
      }
      
      interface ATooLongInterfaceNameThatHintsAtADesignProblem {
      
      }

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

      There are no issues that match your filters.

      Category
      Status