assemblee-virtuelle/wp-ldp

View on GitHub
class-site-taxonomy.php

Summary

Maintainability
D
2 days
Test Coverage

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

        public function get_sites_list( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
            header( 'Content-Type: application/ld+json' );
            header( 'Access-Control-Allow-Origin: *' );

            $terms = get_terms(
Severity: Minor
Found in class-site-taxonomy.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_sites_list has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        public function get_sites_list( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
            header( 'Content-Type: application/ld+json' );
            header( 'Access-Control-Allow-Origin: *' );

            $terms = get_terms(
Severity: Minor
Found in class-site-taxonomy.php - About 1 hr to fix

    Method register_site_taxonomy has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            public function register_site_taxonomy() {
                $labels = array(
                    'name'                       => __( 'Sites', 'wpldp' ),
                    'singular_name'              => __( 'Site', 'wpldp' ),
                    'menu_name'                  => __( 'Sites', 'wpldp' ),
    Severity: Minor
    Found in class-site-taxonomy.php - About 1 hr to fix

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

                  $labels = array(
                      'name'                       => __( 'Sites', 'wpldp' ),
                      'singular_name'              => __( 'Site', 'wpldp' ),
                      'menu_name'                  => __( 'Sites', 'wpldp' ),
                      'all_items'                  => __( 'All Items', 'wpldp' ),
      Severity: Major
      Found in class-site-taxonomy.php and 1 other location - About 1 day to fix
      class-container-taxonomy.php on lines 70..88

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 263.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

              public function __construct() {
                  register_activation_hook( __FILE__, array( $this, 'wpldp_rewrite_flush' ) );
                  add_action( 'init', array( $this, 'register_site_taxonomy' ), 0 );
      
                  add_action( 'ldp_site_add_form_fields', array( $this, 'add_custom_tax_fields_oncreate_site' ) );
      Severity: Major
      Found in class-site-taxonomy.php and 1 other location - About 6 hrs to fix
      class-container-taxonomy.php on lines 31..51

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 218.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

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

                      'with_front'                 => true,
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                      $ch = curl_init();
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                          'taxonomy' => 'ldp_site',
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                  $term_id = $term->term_id;
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Concat operator must be surrounded by a single space
      Open

                  echo "<p class='description'>" . __( 'WordPress site that you know and that the WP-LDP plugin is installed', 'wpldp' ). '</p>';
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Concat operator must be surrounded by a single space
      Open

                  echo "<th scope='row'><label for='ldp_site_url'>" . __( 'web site', 'wpldp' ). '</label></th>';
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Visibility must be declared on method "save_custom_tax_field_site"
      Open

              function save_custom_tax_field_site( $term_id ) {
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Using cURL functions is highly discouraged. Use wp_remote_get() instead.
      Open

                      curl_setopt( $ch, CURLOPT_URL, $build_url );
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                          'taxonomy' => 'ldp_site',
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Using cURL functions is highly discouraged. Use wp_remote_get() instead.
      Open

                      curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/ld+json', 'Accept: application/ld+json' ) );
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                          '@id'      => get_site_url() . '/api/ldp/v1/sites/',
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Using cURL functions is highly discouraged. Use wp_remote_get() instead.
      Open

                      $outputs[ $ldp_site_url  . '/schema/' ]['code'] = curl_getinfo( $ch )['http_code'];
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      No space after opening parenthesis is prohibited
      Open

                  foreach ($outputs as $site_url => $output ) {
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Concat operator must be surrounded by a single space
      Open

                  echo "<p class='description'>" . __( 'WordPress site that you know and on which the WP-LDP plugin is installed', 'wpldp' ). '</p></td>';
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Detected usage of meta_query, possible slow query.
      Open

                          'meta_query' => array(
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                      'show_admin_column'          => true,
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Using cURL functions is highly discouraged. Use wp_remote_get() instead.
      Open

                      curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Concat operator must be surrounded by a single space
      Open

                      $outputs[ $ldp_site_url  . '/schema/' ]['data'] = curl_exec( $ch );
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Expected type hint "{\WP_REST_Request}"; found "\WP_REST_Request" for $request
      Open

              public function add_new_site( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
      Severity: Minor
      Found in class-site-taxonomy.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-site-taxonomy.php by phpcodesniffer

      Visibility must be declared on method "add_custom_tax_fields_onedit_site"
      Open

              function add_custom_tax_fields_onedit_site( $term ) {
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Processing form data without nonce verification.
      Open

                  if ( isset( $_POST['ldp_site_url'] ) ) {
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                      $term_meta = $_POST['ldp_site_url'];
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Missing wp_unslash() before sanitization.
      Open

                      $term_meta = $_POST['ldp_site_url'];
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                              'value' => $source_site_url,
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 12 space(s) between "'public'" and double arrow, but found 21.
      Open

                      'public'                     => true,
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                  echo "<p class='description'>" . __( 'WordPress site that you know and on which the WP-LDP plugin is installed', 'wpldp' ). '</p></td>';
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Expected type hint "{\WP_REST_Response}"; found "\WP_REST_Response" for $response
      Open

              public function add_new_site( \WP_REST_Request $request, \WP_REST_Response $response = null ) {
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                      'slug'                       => 'site',
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 11 space(s) between "'show_ui'" and double arrow, but found 20.
      Open

                      'show_ui'                    => true,
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 11 space(s) between "'rewrite'" and double arrow, but found 20.
      Open

                      'rewrite'                    => $rewrite,
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Using cURL functions is highly discouraged. Use wp_remote_get() instead.
      Open

                      $ch = curl_init();
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Using cURL functions is highly discouraged. Use wp_remote_get() instead.
      Open

                      $outputs[ $ldp_site_url  . '/schema/' ]['data'] = curl_exec( $ch );
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Using cURL functions is highly discouraged. Use wp_remote_get() instead.
      Open

                      curl_setopt( $ch, CURLOPT_HTTPGET, true );
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                      'hierarchical'               => true,
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                          '@type'    => 'http://www.w3.org/ns/ldp#BasicContainer',
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                  echo "<label for='ldp_site'>" . __( 'web site', 'wpldp' ). '</label>';
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                  echo "<p class='description'>" . __( 'WordPress site that you know and that the WP-LDP plugin is installed', 'wpldp' ). '</p>';
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

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

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

                      'hierarchical'               => false,
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                      'show_in_nav_menus'          => true,
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                  $term_meta = get_term_meta( $term_id,'ldp_site_url', true );
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Processing form data without nonce verification.
      Open

                      $term_meta = $_POST['ldp_site_url'];
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Concat operator must be surrounded by a single space
      Open

                      $outputs[ $ldp_site_url  . '/schema/' ]['code'] = curl_getinfo( $ch )['http_code'];
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                              $current_site = $response->{'@graph'}[0];
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Class file names should be based on the class name with "class-" prepended. Expected class-sitetaxonomy.php, but found class-site-taxonomy.php.
      Open

      <?php
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Expected 2 spaces after parameter type; 1 found
      Open

               * @param  {\WP_REST_Request} $request The current HTTP request object.
      Severity: Minor
      Found in class-site-taxonomy.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::CREATABLE,
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 5 space(s) between "'show_tagcloud'" and double arrow, but found 14.
      Open

                      'show_tagcloud'              => true,
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                              'key' => 'ldp_site_url',
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Array double arrow not aligned correctly; expected 12 space(s) between "'labels'" and double arrow, but found 21.
      Open

                      'labels'                     => $labels,
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Visibility must be declared on method "add_custom_tax_fields_oncreate_site"
      Open

              function add_custom_tax_fields_oncreate_site() {
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                  echo "<th scope='row'><label for='ldp_site_url'>" . __( 'web site', 'wpldp' ). '</label></th>';
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Concat operator must be surrounded by a single space
      Open

                  echo "<label for='ldp_site'>" . __( 'web site', 'wpldp' ). '</label>';
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      Expected 2 spaces after parameter type; 1 found
      Open

               * @param  \WP_REST_Request $request The current HTTP request object.
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '"<td> <input type="url" placeholder="http://" name="ldp_site_url" id="ldp_site_url" value="$ldp_site_url">"'.</td>
      Open

                  echo "<td><input type='url' placeholder='http://' name='ldp_site_url' id='ldp_site_url' value='$ldp_site_url' />";
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

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

                  $term = null;
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      No space found after comma in function call
      Open

                  $term_meta = get_term_meta( $term_id,'ldp_site_url', true );
      Severity: Minor
      Found in class-site-taxonomy.php by phpcodesniffer

      There are no issues that match your filters.

      Category
      Status