soderlind/read-offline

View on GitHub
inc/class-read-offline-parser.php

Summary

Maintainability
C
1 day
Test Coverage

Function parse_request has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

    function parse_request( $wp_query ) {
        global $post;
        $create_new = true;
        if ( '1' == parent::$options['misc']['cache'] ) {
            $create_new = false;
Severity: Minor
Found in inc/class-read-offline-parser.php - About 6 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 parse_request has 59 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    function parse_request( $wp_query ) {
        global $post;
        $create_new = true;
        if ( '1' == parent::$options['misc']['cache'] ) {
            $create_new = false;
Severity: Major
Found in inc/class-read-offline-parser.php - About 2 hrs to fix

    Avoid deeply nested control flow statements.
    Open

                                if ( filesize( $attached_file ) > 0 ) {
                                    parent::read_offline_download( $attached_file,$mime_type,wp_create_nonce( 'read-offline-download' ) );
                                    exit();
                                }
    Severity: Major
    Found in inc/class-read-offline-parser.php - About 45 mins to fix

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

                          $attachments = new WP_Query( array(
                              'post_type'      => 'attachment',
                              'post_status'    => 'any',
                              'posts_per_page' => 500,
                              'post_parent'    => $post_id,
      Severity: Minor
      Found in inc/class-read-offline-parser.php and 1 other location - About 30 mins to fix
      inc/class-read-offline.php on lines 157..163

      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 40.

      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

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

                          $mime_type = parent::$mime_types[ $docformat ];

      Expected 1 space after comma in function call; 10 found
      Open

              add_action( 'parse_request',          array( $this, 'parse_request' ) );

      Equals sign not aligned correctly; expected 1 space but found 2 spaces
      Open

                          $code  = $_REQUEST['read-offline-code'];

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

                  $post = get_page( $post_id );

      Array item not aligned correctly; expected 12 spaces but found 9
      Open

               'read-offline/([^/]+)/([^\.]+).(pdf|epub|mobi|docx|print)$' => sprintf( 'index.php?read_offline_id=%s&read_offline_name=%s&&read_offline_format=%s',$wp_rewrite->preg_index( 1 ),$wp_rewrite->preg_index( 2 ),$wp_rewrite->preg_index( 3 ) ),

      Found precision alignment of 1 spaces.
      Open

               'read-offline/([^/]+)/([^\.]+).(pdf|epub|mobi|docx|print)$' => sprintf( 'index.php?read_offline_id=%s&read_offline_name=%s&&read_offline_format=%s',$wp_rewrite->preg_index( 1 ),$wp_rewrite->preg_index( 2 ),$wp_rewrite->preg_index( 3 ) ),

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

                  $filename = sprintf( '%s.%s',$wp_query->query_vars['read_offline_name'],$wp_query->query_vars['read_offline_format'] );

      Expected 1 space after comma in function call; 13 found
      Open

              add_filter( 'query_vars',             array( $this, 'query_vars' ) );

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

                  $post_id = $wp_query->query_vars['read_offline_id'];

      Expected 1 space after comma in function call; 13 found
      Open

              add_filter( 'admin_init',             array( $this, 'flush_rewrite_rules' ) );

      No space found after comma in function call
      Open

                  $filename = sprintf( '%s.%s',$wp_query->query_vars['read_offline_name'],$wp_query->query_vars['read_offline_format'] );

      No space found after comma in function call
      Open

               'read-offline/([^/]+)/([^\.]+).(pdf|epub|mobi|docx|print)$' => sprintf( 'index.php?read_offline_id=%s&read_offline_name=%s&&read_offline_format=%s',$wp_rewrite->preg_index( 1 ),$wp_rewrite->preg_index( 2 ),$wp_rewrite->preg_index( 3 ) ),

      No space found after comma in function call
      Open

                                      parent::read_offline_download( $attached_file,$mime_type,wp_create_nonce( 'read-offline-download' ) );

      No space found after comma in function call
      Open

               'read-offline/([^/]+)/([^\.]+).(pdf|epub|mobi|docx|print)$' => sprintf( 'index.php?read_offline_id=%s&read_offline_name=%s&&read_offline_format=%s',$wp_rewrite->preg_index( 1 ),$wp_rewrite->preg_index( 2 ),$wp_rewrite->preg_index( 3 ) ),

      No space found after comma in function call
      Open

                  $filename = sprintf( '%s.%s',$wp_query->query_vars['read_offline_name'],$wp_query->query_vars['read_offline_format'] );

      No space found after comma in function call
      Open

               'read-offline/([^/]+)/([^\.]+).(pdf|epub|mobi|docx|print)$' => sprintf( 'index.php?read_offline_id=%s&read_offline_name=%s&&read_offline_format=%s',$wp_rewrite->preg_index( 1 ),$wp_rewrite->preg_index( 2 ),$wp_rewrite->preg_index( 3 ) ),

      No space found after comma in function call
      Open

                                      parent::read_offline_download( $attached_file,$mime_type,wp_create_nonce( 'read-offline-download' ) );

      There are no issues that match your filters.

      Category
      Status