WP-API/WP-API

View on GitHub
lib/fields/class-wp-rest-meta-fields.php

Summary

Maintainability
C
1 day
Test Coverage

Function get_registered_fields has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    protected function get_registered_fields() {
        $registered = array();

        foreach ( get_registered_meta_keys( $this->get_meta_type() ) as $name => $args ) {
            if ( empty( $args['show_in_rest'] ) ) {
Severity: Minor
Found in lib/fields/class-wp-rest-meta-fields.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

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

    protected function update_multi_meta_value( $object_id, $name, $values ) {
        if ( ! current_user_can( 'edit_post_meta', $object_id, $name ) ) {
            return new WP_Error(
                'rest_cannot_update',
                sprintf( __( 'You do not have permission to edit the %s custom field.' ), $name ),
Severity: Minor
Found in lib/fields/class-wp-rest-meta-fields.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

Method update_multi_meta_value has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function update_multi_meta_value( $object_id, $name, $values ) {
        if ( ! current_user_can( 'edit_post_meta', $object_id, $name ) ) {
            return new WP_Error(
                'rest_cannot_update',
                sprintf( __( 'You do not have permission to edit the %s custom field.' ), $name ),
Severity: Minor
Found in lib/fields/class-wp-rest-meta-fields.php - About 1 hr to fix

    Method get_registered_fields has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function get_registered_fields() {
            $registered = array();
    
            foreach ( get_registered_meta_keys( $this->get_meta_type() ) as $name => $args ) {
                if ( empty( $args['show_in_rest'] ) ) {
    Severity: Minor
    Found in lib/fields/class-wp-rest-meta-fields.php - About 1 hr to fix

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

          public function get_value( $object_id, $request ) {
              $fields   = $this->get_registered_fields();
              $response = array();
      
              foreach ( $fields as $name => $args ) {
      Severity: Minor
      Found in lib/fields/class-wp-rest-meta-fields.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 update_value has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          public function update_value( $request, $object_id ) {
              $fields = $this->get_registered_fields();
      
              foreach ( $fields as $name => $args ) {
                  if ( ! array_key_exists( $name, $request ) ) {
      Severity: Minor
      Found in lib/fields/class-wp-rest-meta-fields.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 prepare_value has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function prepare_value( $value, $request, $args ) {
              $type = $args['schema']['type'];
      
              // For multi-value fields, check the item type instead.
              if ( 'array' === $type && ! empty( $args['schema']['items']['type'] ) ) {
      Severity: Minor
      Found in lib/fields/class-wp-rest-meta-fields.php - About 45 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