WP-API/WP-API

View on GitHub
lib/endpoints/class-wp-rest-controller.php

Summary

Maintainability
D
1 day
Test Coverage

Function filter_response_by_context has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

    public function filter_response_by_context( $data, $context ) {

        $schema = $this->get_item_schema();
        foreach ( $data as $key => $value ) {
            if ( empty( $schema['properties'][ $key ] ) || empty( $schema['properties'][ $key ]['context'] ) ) {
Severity: Minor
Found in lib/endpoints/class-wp-rest-controller.php - About 4 hrs 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

WP_REST_Controller has 27 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class WP_REST_Controller {

    /**
     * The namespace of this controller's route.
     *
Severity: Minor
Found in lib/endpoints/class-wp-rest-controller.php - About 3 hrs to fix

    Function get_endpoint_args_for_item_schema has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) {
    
            $schema                = $this->get_item_schema();
            $schema_properties     = ! empty( $schema['properties'] ) ? $schema['properties'] : array();
            $endpoint_args = array();
    Severity: Minor
    Found in lib/endpoints/class-wp-rest-controller.php - About 2 hrs 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

    Method get_endpoint_args_for_item_schema has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) {
    
            $schema                = $this->get_item_schema();
            $schema_properties     = ! empty( $schema['properties'] ) ? $schema['properties'] : array();
            $endpoint_args = array();
    Severity: Minor
    Found in lib/endpoints/class-wp-rest-controller.php - About 1 hr to fix

      Method get_collection_params has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function get_collection_params() {
              return array(
                  'context'                => $this->get_context_param(),
                  'page'                   => array(
                      'description'        => __( 'Current page of the collection.' ),
      Severity: Minor
      Found in lib/endpoints/class-wp-rest-controller.php - About 1 hr to fix

        Function update_additional_fields_for_object has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function update_additional_fields_for_object( $object, $request ) {
                $additional_fields = $this->get_additional_fields();
        
                foreach ( $additional_fields as $field_name => $field_options ) {
                    if ( ! $field_options['update_callback'] ) {
        Severity: Minor
        Found in lib/endpoints/class-wp-rest-controller.php - About 55 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

        There are no issues that match your filters.

        Category
        Status