Function _get_items_array
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
public function _get_items_array($cat_name = '', $recursive_sort = true, $all = false)
{
if (empty($cat_name)) {
$cat_name = $this->_default_cats_block;
}
- 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
File yf_cats.class.php
has 361 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Category display handler.
*
Function _recursive_sort_items
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
public function _recursive_sort_items($items = [], $skip_item_id = 0, $parent_id = 0)
{
$children = [];
$cur_group = MAIN_TYPE_USER ? $_SESSION['user_group'] : $_SESSION['admin_group'];
foreach ((array) $items as $id => $info) {
- 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
Function _get_nav_by_item_id
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function _get_nav_by_item_id($item_id = 0, $cat_items = [], $STPL_NAME = '', $prepare_link_callback = null)
{
if (empty($STPL_NAME)) {
$STPL_NAME = __CLASS__ . '/nav_item';
}
- 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
Function _prepare_for_box
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function _prepare_for_box($cat_items = [], $with_all = true, $parent_item_id = 0, $all = false)
{
if ( ! empty($cat_items) && is_string($cat_items)) {
$cat_items = $this->_get_items_array($cat_items);
}
- 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_items_array
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function _get_items_array($cat_name = '', $recursive_sort = true, $all = false)
{
if (empty($cat_name)) {
$cat_name = $this->_default_cats_block;
}
Method _get_nav_by_item_id
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function _get_nav_by_item_id($item_id = 0, $cat_items = [], $STPL_NAME = '', $prepare_link_callback = null)
{
if (empty($STPL_NAME)) {
$STPL_NAME = __CLASS__ . '/nav_item';
}
Function _recursive_get_children_ids
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function _recursive_get_children_ids($cat_id = 0, $cat_items = [], $get_sub_children = true, $return_array = false)
{
$children_ids = [];
if (empty($cat_id)) {
return $children_ids;
- 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
Function _recursive_get_parents_ids
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function _recursive_get_parents_ids($cat_id = 0, $cat_items = [])
{
$parents_ids = [];
if (empty($cat_id)) {
return $parents_ids;
- 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 _prepare_for_box
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function _prepare_for_box($cat_items = [], $with_all = true, $parent_item_id = 0, $all = false)
{
if ( ! empty($cat_items) && is_string($cat_items)) {
$cat_items = $this->_get_items_array($cat_items);
}
Method _recursive_get_children_ids
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function _recursive_get_children_ids($cat_id = 0, $cat_items = [], $get_sub_children = true, $return_array = false)
{
$children_ids = [];
if (empty($cat_id)) {
return $children_ids;
Method _recursive_sort_items
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function _recursive_sort_items($items = [], $skip_item_id = 0, $parent_id = 0)
{
$children = [];
$cur_group = MAIN_TYPE_USER ? $_SESSION['user_group'] : $_SESSION['admin_group'];
foreach ((array) $items as $id => $info) {
Function _get_recursive_cat_ids
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function _get_recursive_cat_ids($cat_id = 0, $all_cats = false)
{
$cat_id = (int) $cat_id;
if (empty($all_cats)) {
$all_cats = conf('all_cats');
- 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
Function _count_levels
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function _count_levels($start_id = 0, &$children, $level = 0)
{
$ids = [];
foreach ((array) $children[$start_id] as $id => $_tmp) {
$ids[$id] = $level;
- 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
Function _get_cat_id_by_name
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function _get_cat_id_by_name($cat_name = '')
{
if (empty($cat_name)) {
$cat_name = $this->_default_cats_block;
}
- 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
Identical blocks of code found in 6 locations. Consider refactoring. Open
public function _count_levels($start_id = 0, &$children, $level = 0)
{
$ids = [];
foreach ((array) $children[$start_id] as $id => $_tmp) {
$ids[$id] = $level;
- 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 104.
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