pfefferle/wordpress-semantic-linkbacks

View on GitHub

Showing 39 of 42 total issues

Function generate_commentdata has a Cognitive Complexity of 84 (exceeds 5 allowed). Consider refactoring.
Open

    public static function generate_commentdata( $commentdata ) {
        // Use new webmention source meta key.
        if ( array_key_exists( 'webmention_source_url', $commentdata['comment_meta'] ) ) {
            $source = $commentdata['comment_meta']['webmention_source_url'];
        } else { // Fallback to comment author url.
Severity: Minor
Found in includes/class-linkbacks-mf2-handler.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

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

    $type_labels = array(
        'reacji'          => __( 'Reacjis', 'semantic-linkbacks' ),
        'like'            => __( 'Likes', 'semantic-linkbacks' ),
        'favorite'        => __( 'Favourites', 'semantic-linkbacks' ),
        'bookmark'        => __( 'Bookmarks', 'semantic-linkbacks' ),
Severity: Major
Found in includes/functions.php and 1 other location - About 1 day to fix
includes/class-linkbacks-handler.php on lines 273..307

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

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

        $strings = array(
            // translators: Name verb on domain
            'mention'         => __( '%1$s mentioned %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
            // translators: Name verb on domain
            'reply'           => __( '%1$s replied to %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
Severity: Major
Found in includes/class-linkbacks-handler.php and 1 other location - About 1 day to fix
includes/functions.php on lines 184..201

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

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

File class-linkbacks-mf2-handler.php has 440 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
use Mf2\Parser;

/**
 * provides a microformats handler for the semantic linkbacks
Severity: Minor
Found in includes/class-linkbacks-mf2-handler.php - About 6 hrs to fix

    Method generate_commentdata has 161 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function generate_commentdata( $commentdata ) {
            // Use new webmention source meta key.
            if ( array_key_exists( 'webmention_source_url', $commentdata['comment_meta'] ) ) {
                $source = $commentdata['comment_meta']['webmention_source_url'];
            } else { // Fallback to comment author url.
    Severity: Major
    Found in includes/class-linkbacks-mf2-handler.php - About 6 hrs to fix

      Function get_representative_entry has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function get_representative_entry( $entries, $target ) {
              // iterate array
              foreach ( $entries as $entry ) {
                  // check properties
                  if ( isset( $entry['properties'] ) ) {
      Severity: Minor
      Found in includes/class-linkbacks-mf2-handler.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

      Function get_entry_type has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function get_entry_type( $target, $entry, $mf_array = array() ) {
              $classes = self::get_class_mapper();
      
              // check properties for target-url
              foreach ( $entry['properties'] as $key => $values ) {
      Severity: Minor
      Found in includes/class-linkbacks-mf2-handler.php - About 5 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

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

          if ( $type ) { // use type if set
              if ( 'mention' === $type ) {
                  $args['type__not_in'] = 'comment';
                  $args['meta_query']   = array(
                      'relation' => 'OR',
      Severity: Major
      Found in includes/functions.php and 1 other location - About 4 hrs to fix
      includes/functions.php on lines 90..131

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

      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

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

          if ( $type ) { // use type if set
              if ( 'mention' === $type ) {
                  $args['type__not_in'] = 'comment';
                  $args['meta_query']   = array(
                      'relation' => 'OR',
      Severity: Major
      Found in includes/functions.php and 1 other location - About 4 hrs to fix
      includes/functions.php on lines 20..61

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

      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

      File class-linkbacks-handler.php has 369 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      
      // Mentions with content less than this length will be rendered inline.
      define( 'MAX_INLINE_MENTION_LENGTH', 300 );
      
      
      Severity: Minor
      Found in includes/class-linkbacks-handler.php - About 4 hrs to fix

        Function get_representative_author has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function get_representative_author( $mf_array, $source ) {
                foreach ( $mf_array['items'] as $mf ) {
                    if ( isset( $mf['type'] ) ) {
                        if ( in_array( 'h-card', $mf['type'], true ) ) {
                            // check domain
        Severity: Minor
        Found in includes/class-linkbacks-mf2-handler.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

        Method list_linkbacks has 97 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function list_linkbacks( $args, $comments ) {
            $defaults = array(
                'avatar_size' => 64,
                'style'       => 'ul', // What HTML type to wrap it in. Accepts 'ul', 'ol'.
                'style-class' => 'mention-list', // What class to assign to the wrapper
        Severity: Major
        Found in includes/functions.php - About 3 hrs to fix

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

          class Linkbacks_Handler {
              /**
               * Initialize the plugin, registering WordPress hooks.
               */
              public static function init() {
          Severity: Minor
          Found in includes/class-linkbacks-handler.php - About 3 hrs to fix

            Function flatten_microformats has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
            Open

                public static function flatten_microformats( $item ) {
                    $flat = array();
                    if ( 1 === count( $item ) ) {
                        $item = $item[0];
                    }
            Severity: Minor
            Found in includes/class-linkbacks-mf2-handler.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_linkbacks_number has 56 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function get_linkbacks_number( $type = null, $post_id = null ) {
                if ( null === $post_id ) {
                    $post_id = get_the_ID();
                }
                $args = array(
            Severity: Major
            Found in includes/functions.php - About 2 hrs to fix

              Method get_linkbacks has 51 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function get_linkbacks( $type = null, $post_id = null, $order = 'DESC' ) {
                  if ( null === $post_id ) {
                      $post_id = get_the_ID();
                  }
                  $args = array(
              Severity: Major
              Found in includes/functions.php - About 2 hrs to fix

                Function list_linkbacks has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                function list_linkbacks( $args, $comments ) {
                    $defaults = array(
                        'avatar_size' => 64,
                        'style'       => 'ul', // What HTML type to wrap it in. Accepts 'ul', 'ol'.
                        'style-class' => 'mention-list', // What class to assign to the wrapper
                Severity: Minor
                Found in includes/functions.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 flatten_microformats has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static function flatten_microformats( $item ) {
                        $flat = array();
                        if ( 1 === count( $item ) ) {
                            $item = $item[0];
                        }
                Severity: Minor
                Found in includes/class-linkbacks-mf2-handler.php - About 1 hr to fix

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

                      public static function pre_get_avatar_data( $args, $id_or_email ) {
                          if ( ! $id_or_email instanceof WP_Comment ||
                          ! isset( $id_or_email->comment_type ) ||
                          $id_or_email->user_id ) {
                              return $args;
                  Severity: Minor
                  Found in includes/class-linkbacks-avatar-handler.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 anonymous_avatar_data has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public static function anonymous_avatar_data( $args, $id_or_email ) {
                          $local = apply_filters( 'semantic_linkbacks_local_avatars', array( 'mm', 'mystery', 'mysteryman' ) );
                          if ( ! in_array( $args['default'], $local, true ) ) {
                              return $args;
                          }
                  Severity: Minor
                  Found in includes/class-linkbacks-avatar-handler.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

                  Severity
                  Category
                  Status
                  Source
                  Language