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
- Read upRead up
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
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
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 = '';
- Read upRead up
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 = '';
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 = '';
- Read upRead up
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 = '';
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
- Read upRead up
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
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' ) )
{
Avoid deeply nested control flow statements. Open
if ( $moz_type == 'rv' )
{
$moz_type = 'mozilla';
}
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;
}
Avoid deeply nested control flow statements. Open
if ( ( $moz_release_date < 20020400 ) || ( $moz_rv < 1 ) )
{
$b_safe_browser = false;
}
Avoid deeply nested control flow statements. Open
if ( $browser_number < 5 )// opera 4 wasn't very useable.
{
$b_safe_browser = false;
}
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];
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/' );
}
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];
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 ' ) )
{
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++)
{
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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++)
{
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76