wp-plugins/all-in-one-seo-pack

View on GitHub
aioseop_robots.php

Summary

Maintainability
F
1 wk
Test Coverage

Function filter_options has a Cognitive Complexity of 79 (exceeds 5 allowed). Consider refactoring.
Open

        function filter_options( $options, $location ) {
            if ( $location ) $prefix = $this->get_prefix( $location ) . $location . '_';
            if ( $location === 'generator' ) {
                    $optimize = false;
                    $robotgen = '';
Severity: Minor
Found in aioseop_robots.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

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

        function parse_annotated_robots( $robots ) {
                $state = 0;
                $rules = Array();
                $opts = Array( 'sitemap', 'crawl-delay', 'user-agent', 'allow', 'disallow', 'comment' );
                $rule = Array();
Severity: Minor
Found in aioseop_robots.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

File aioseop_robots.php has 367 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @package All-in-One-SEO-Pack 
 */
/**
Severity: Minor
Found in aioseop_robots.php - About 4 hrs to fix

    Function annotate_robots_html has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

            function annotate_robots_html( $file, $show_help = false, $title = '' ) {
                $robots = $this->annotate_robots( $file );
                if( !empty( $robots ) ){
                    $buf = '<table class="widefat" ><thead>';
                    if ( !empty( $title ) ) {
    Severity: Minor
    Found in aioseop_robots.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

    Function annotate_robots has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

            function annotate_robots( $robots ) {
                    $state = 0;
                    $rules = Array();
                    foreach ($robots as $l) {
                        $l = trim($l);
    Severity: Minor
    Found in aioseop_robots.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

    Function output_robots has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

            function output_robots($rules) {
                $robots = '';
                foreach ($rules as $r) {
                    foreach ( $r['comment']     as $c) $robots .= "$c\n";
                    foreach ( $r['user-agent']  as $u) if ( $u != '' ) $robots .= "User-agent: $u\n";
    Severity: Minor
    Found in aioseop_robots.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

    Function get_robot_user_agents has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

            function get_robot_user_agents($rules) {
                $opts = Array( 'sitemap', 'crawl-delay', 'user-agent', 'allow', 'disallow', 'comment' );
                $user_agents = Array();
                foreach ($rules as $r) {
                    if ( !empty( $r['sitemap'] ) && empty( $r['user-agent'] ) ) $r['user-agent'] = Array( null );
    Severity: Minor
    Found in aioseop_robots.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

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

            function opt_robot_rule($dis) {
                if ( is_array($dis) ) { // unique rules only
                    $dis = array_unique( $dis, SORT_STRING );
                    $pd = null;
                    foreach( $dis as $k => $d ) { 
    Severity: Minor
    Found in aioseop_robots.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 __construct has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            function __construct( ) {
                $this->name = __('Robots.txt', 'all-in-one-seo-pack');    // Human-readable name of the plugin
                $this->prefix = 'aiosp_robots_';                        // option prefix
                $this->file = __FILE__;                                    // the current file
                parent::__construct();
    Severity: Major
    Found in aioseop_robots.php - About 2 hrs to fix

      Method filter_options has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              function filter_options( $options, $location ) {
                  if ( $location ) $prefix = $this->get_prefix( $location ) . $location . '_';
                  if ( $location === 'generator' ) {
                          $optimize = false;
                          $robotgen = '';
      Severity: Major
      Found in aioseop_robots.php - About 2 hrs to fix

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

                function parse_annotated_robots( $robots ) {
                        $state = 0;
                        $rules = Array();
                        $opts = Array( 'sitemap', 'crawl-delay', 'user-agent', 'allow', 'disallow', 'comment' );
                        $rule = Array();
        Severity: Major
        Found in aioseop_robots.php - About 2 hrs to fix

          Method annotate_robots_html has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  function annotate_robots_html( $file, $show_help = false, $title = '' ) {
                      $robots = $this->annotate_robots( $file );
                      if( !empty( $robots ) ){
                          $buf = '<table class="widefat" ><thead>';
                          if ( !empty( $title ) ) {
          Severity: Minor
          Found in aioseop_robots.php - About 1 hr to fix

            Method annotate_robots has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    function annotate_robots( $robots ) {
                            $state = 0;
                            $rules = Array();
                            foreach ($robots as $l) {
                                $l = trim($l);
            Severity: Minor
            Found in aioseop_robots.php - About 1 hr to fix

              Function do_robots has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                      function do_robots( $options, $location ) {
                          if ( $location ) $prefix = $this->get_prefix( $location ) . $location . '_';
                          if ( $location === 'generator' ) {
                              if ( isset( $_POST['Submit_Update'] ) || isset( $_POST['Submit_Opt_Update'] ) ) {
                                  $this->save_files( Array( 'robotgen' => 'robots.txt' ), $prefix );
              Severity: Minor
              Found in aioseop_robots.php - About 55 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

              Function filter_settings has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                      function filter_settings( $settings, $location ) {
                          if ( $location == 'generator' ) {
                              $prefix = $this->get_prefix( $location ) . $location . '_';
                              if ( isset( $_POST['Submit_Optimize'] ) ) {
                                  if ( isset( $settings[ $prefix . 'robotgen' ] ) ) {
              Severity: Minor
              Found in aioseop_robots.php - About 55 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

              Avoid deeply nested control flow statements.
              Open

                                          if ( empty( $options[$prefix . 'robotgen'] ) ) 
                                              $options = $this->load_files( $options, Array( 'robotgen' => 'robots.txt' ), $prefix );                            
              Severity: Major
              Found in aioseop_robots.php - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                            if ( $optimize ) $options[$prefix . 'robotgen'] = $robotgen;
                Severity: Major
                Found in aioseop_robots.php - About 45 mins to fix

                  Function __construct has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                          function __construct( ) {
                              $this->name = __('Robots.txt', 'all-in-one-seo-pack');    // Human-readable name of the plugin
                              $this->prefix = 'aiosp_robots_';                        // option prefix
                              $this->file = __FILE__;                                    // the current file
                              parent::__construct();
                  Severity: Minor
                  Found in aioseop_robots.php - About 35 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

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

                                      } elseif ( stripos($l, 'allow') === 0) {
                                          if ($state < 3) {
                                              $rules[] = Array( 'state' => $state, 'type' => 'allow', 'content' => $l, 'valid' => false, 'strict' => false );
                                              continue;
                                          }
                  Severity: Major
                  Found in aioseop_robots.php and 1 other location - About 1 hr to fix
                  aioseop_robots.php on lines 256..263

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

                  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

                                      } elseif ( stripos($l, 'disallow') === 0) {
                                          if ($state < 3) {
                                              $rules[] = Array( 'state' => $state, 'type' => 'disallow', 'content' => $l, 'valid' => false, 'strict' => false );
                                              continue;
                                          }
                  Severity: Major
                  Found in aioseop_robots.php and 1 other location - About 1 hr to fix
                  aioseop_robots.php on lines 263..270

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

                  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

                  There are no issues that match your filters.

                  Category
                  Status