travi/php-framework

View on GitHub
php/thirdparty/browser_detection.php

Summary

Maintainability
F
1 wk
Test Coverage

Function browser_detection has a Cognitive Complexity of 137 (exceeds 5 allowed). Consider refactoring.
Open

function browser_detection( $which_test, $test_excludes='', $external_ua_string='' )
{
    /*
    uncomment the global variable declaration if you want the variables to be available on
    a global level throughout your php page, make sure that php is configured to support
Severity: Minor
Found in php/thirdparty/browser_detection.php - About 2 days 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 browser_detection has 399 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function browser_detection( $which_test, $test_excludes='', $external_ua_string='' )
{
    /*
    uncomment the global variable declaration if you want the variables to be available on
    a global level throughout your php page, make sure that php is configured to support
Severity: Major
Found in php/thirdparty/browser_detection.php - About 1 day to fix

    File browser_detection.php has 700 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /*
    Script Name: Full Featured PHP Browser/OS detection
    Author: Harald Hope, Website: http://techpatterns.com/
    Script Source URI: http://techpatterns.com/downloads/php_browser_detection.php
    Severity: Major
    Found in php/thirdparty/browser_detection.php - About 1 day to fix

      Function get_os_data has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring.
      Open

      function get_os_data ( $pv_browser_string, $pv_browser_name, $pv_version_number  )
      {
          // initialize variables
          $os_working_type = '';
          $os_working_number = '';
      Severity: Minor
      Found in php/thirdparty/browser_detection.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_os_data has 141 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function get_os_data ( $pv_browser_string, $pv_browser_name, $pv_version_number  )
      {
          // initialize variables
          $os_working_type = '';
          $os_working_number = '';
      Severity: Major
      Found in php/thirdparty/browser_detection.php - About 5 hrs to fix

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

        function get_mobile_data( $pv_browser_user_agent )
        {
            $mobile_browser = '';
            $mobile_browser_number = '';
            $mobile_device = '';
        Severity: Minor
        Found in php/thirdparty/browser_detection.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_mobile_data has 64 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function get_mobile_data( $pv_browser_user_agent )
        {
            $mobile_browser = '';
            $mobile_browser_number = '';
            $mobile_device = '';
        Severity: Major
        Found in php/thirdparty/browser_detection.php - About 2 hrs to fix

          Function get_item_version has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          function get_item_version( $pv_browser_user_agent, $pv_search_string, $pv_b_break_last='', $pv_extra_search='' )
          {
              // 12 is the longest that will be required, handles release dates: 20020323; 0.8.0+
              $substring_length = 15;
              $start_pos = 0; // set $start_pos to 0 for first iteration
          Severity: Minor
          Found in php/thirdparty/browser_detection.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 get_item_version has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function get_item_version( $pv_browser_user_agent, $pv_search_string, $pv_b_break_last='', $pv_extra_search='' )
          {
              // 12 is the longest that will be required, handles release dates: 20020323; 0.8.0+
              $substring_length = 15;
              $start_pos = 0; // set $start_pos to 0 for first iteration
          Severity: Minor
          Found in php/thirdparty/browser_detection.php - About 1 hr to fix

            Avoid deeply nested control flow statements.
            Open

                                    if ( !$moz_rv )
                                    {
                                        // you can use this if you are running php >= 4.2
                                        if ( function_exists( 'floatval' ) )
                                        {
            Severity: Major
            Found in php/thirdparty/browser_detection.php - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if ( $moz_type == 'rv' )
                                      {
                                          $moz_type = 'mozilla';
                                      }
              Severity: Major
              Found in php/thirdparty/browser_detection.php - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if ( strstr( $browser_number, '7.' ) && strstr( $browser_user_agent, 'trident/5' ) )
                                        {
                                            // note that 7.0 becomes 9 when adding 1, but if it's 7.1 it will be 9.1
                                            $true_ie_number = $browser_number + 2;
                                        }
                Severity: Major
                Found in php/thirdparty/browser_detection.php - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          if ( ( $moz_release_date < 20020400 ) || ( $moz_rv < 1 ) )
                                          {
                                              $b_safe_browser = false;
                                          }
                  Severity: Major
                  Found in php/thirdparty/browser_detection.php - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                            if ( $browser_number < 5 )// opera 4 wasn't very useable.
                                            {
                                                $b_safe_browser = false;
                                            }
                    Severity: Major
                    Found in php/thirdparty/browser_detection.php - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              for ( $j = 0; $j < $j_count; $j++ )
                                              {
                                                  if ( strstr( $browser_user_agent, $a_moz_types[$j] ) )
                                                  {
                                                      $moz_type = $a_moz_types[$j];
                      Severity: Major
                      Found in php/thirdparty/browser_detection.php - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                if ( strstr( $browser_number, '9.' ) && strstr( $browser_user_agent, 'version/' ) )
                                                {
                                                    get_set_count( 'set', 0 );
                                                    $browser_number = get_item_version( $browser_user_agent, 'version/' );
                                                }
                        Severity: Major
                        Found in php/thirdparty/browser_detection.php - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                                  for ( $j = 0; $j < $j_count; $j++ )
                                                  {
                                                      if ( strstr( $browser_user_agent, $a_webkit_types[$j] ) )
                                                      {
                                                          $webkit_type = $a_webkit_types[$j];
                          Severity: Major
                          Found in php/thirdparty/browser_detection.php - About 45 mins to fix

                            Consider simplifying this complex logical expression.
                            Open

                                                if ( strstr( $pv_browser_string, 'os x' ) )
                                                {
                                                    // if it doesn't have a version number, it is os x;
                                                    if ( strstr( $pv_browser_string, 'os x ' ) )
                                                    {
                            Severity: Major
                            Found in php/thirdparty/browser_detection.php - About 40 mins to fix

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

                                      elseif ( is_array( $os_working_data ) && ( $i == ( $i_count - 1 ) ) )
                                      {
                                          $j_count = count($os_working_data);
                                          for ($j = 0; $j < $j_count; $j++)
                                          {
                              Severity: Major
                              Found in php/thirdparty/browser_detection.php and 1 other location - About 1 hr to fix
                              php/thirdparty/browser_detection.php on lines 912..924

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

                              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 ( is_array( $os_working_data ) && ( $i == ( $i_count - 2 ) ) )
                                      {
                                          $j_count = count($os_working_data);
                                          for ($j = 0; $j < $j_count; $j++)
                                          {
                              Severity: Major
                              Found in php/thirdparty/browser_detection.php and 1 other location - About 1 hr to fix
                              php/thirdparty/browser_detection.php on lines 929..943

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

                              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