assemblee-virtuelle/wp-ldp

View on GitHub
class-api.php

Summary

Maintainability
D
2 days
Test Coverage

Function get_resource has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring.
Open

        public function get_resource( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
            $params = $request->get_params();
            $ldp_container = $params['ldp_container'];
            $ldp_resource_slug = $params['ldp_resource'];

Severity: Minor
Found in class-api.php - About 1 day 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_resource has 95 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        public function get_resource( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
            $params = $request->get_params();
            $ldp_container = $params['ldp_container'];
            $ldp_resource_slug = $params['ldp_resource'];

Severity: Major
Found in class-api.php - About 3 hrs to fix

    Function get_api_definition has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

            public function get_api_definition( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
                header( 'Content-Type: application/ld+json' );
                header( 'Access-Control-Allow-Origin: *' );
    
                $query = new \WP_Query(
    Severity: Minor
    Found in class-api.php - About 3 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_api_definition has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            public function get_api_definition( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
                header( 'Content-Type: application/ld+json' );
                header( 'Access-Control-Allow-Origin: *' );
    
                $query = new \WP_Query(
    Severity: Minor
    Found in class-api.php - About 1 hr to fix

      Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space
      Open

                                  $current_post_entry = array();
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
      Open

                                  $current_post_entry['@id'] = get_permalink( $post->ID );
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 2 space(s) between "'methods'" and double arrow, but found 1.
      Open

                          'methods' => \WP_REST_Server::READABLE,
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 3 space(s) between "'@id'" and double arrow, but found 1.
      Open

                              '@id' => rtrim( get_rest_url(), '/' ) . $request->get_route() . '/',
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 27 spaces but found 1 space
      Open

                      $current_container_entry['@type'] = 'http://www.w3.org/ns/ldp#BasicContainer';
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
      Open

                  $terms = wp_get_post_terms( $post->ID, 'ldp_container' );
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Missing wp_unslash() before sanitization.
      Open

                  $referer = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : null;
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Must use "self::" for local static member reference
      Open

                      $current_container_entry['@id'] = site_url( '/' ) . \WpLdp\Api::LDP_API_URL . $value['id'] . '/';
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 9 space(s) between "'author'" and double arrow, but found 1.
      Open

                              'author' => $user->data->ID,
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
      Open

                          $rdf_type = isset( $term_meta['ldp_rdf_type'] ) ? $term_meta['ldp_rdf_type'] : null;
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 36 spaces but found 1 space
      Open

                      $current_container_entry = array();
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
      Open

                      $term_id = $terms[0]->term_id;
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 6 space(s) between "'post_type'" and double arrow, but found 1.
      Open

                              'post_type' => 'post',
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 6 space(s) between "'post_type'" and double arrow, but found 1.
      Open

                          'post_type' => 'ldp_resource',
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 29 spaces but found 1 space
      Open

                      $current_container_entry['@id'] = site_url( '/' ) . \WpLdp\Api::LDP_API_URL . $value['id'] . '/';
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 1 space(s) between "'@id'" and double arrow, but found 2.
      Open

                                          '@id'  => ! empty( $value ) ? $value : null,
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 4 space(s) between "'post_status'" and double arrow, but found 1.
      Open

                              'post_status' => 'any',
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 2 space(s) between "'methods'" and double arrow, but found 1.
      Open

                          'methods' => \WP_REST_Server::READABLE,
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 26 spaces but found 1 space
      Open

                      $current_container_entry['@count'] = $value['value'];
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 12 spaces but found 1 space
      Open

                  $params = $request->get_params();
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
      Open

                  $ldp_container = $params['ldp_container'];
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 6 space(s) between "'name'" and double arrow, but found 1.
      Open

                          'name' => $ldp_resource_slug,
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Each array item in a multi-line array declaration must end in a comma
      Open

                      )
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
      Open

                      $rdf_type = isset( $term_meta['ldp_rdf_type'] ) ? $term_meta['ldp_rdf_type'] : null;
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 24 spaces but found 1 space
      Open

                              $field_value = get_post_custom_values( $field_name, $post->ID )[0];
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 8 space(s) between "'orderby'" and double arrow, but found 1.
      Open

                              'orderby' => 'menu_order',
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
      Open

                                  $array[ $rdf_type ]['id'] = strtolower( explode( ':', $rdf_type )[1] );
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Equals sign not aligned with surrounding assignments; expected 23 spaces but found 1 space
      Open

                              $field_values = get_post_custom_values( $field_name, $post->ID )[0];
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      Detected usage of a non-sanitized input variable: $_SERVER
      Open

                  $referer = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : null;
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      unserialize() found. Serialized data has known vulnerability problems with Object Injection. JSON is generally a better approach for serializing data. See https://www.owasp.org/index.php/PHP_Object_Injection
      Open

                                  $field_values = unserialize( $field_values );
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      No space found after comma in function call
      Open

                              if ( array_key_exists( $rdf_type,$array ) ) {
      Severity: Minor
      Found in class-api.php by phpcodesniffer

      There are no issues that match your filters.

      Category
      Status