ImpressCMS/impresscms

View on GitHub
htdocs/modules/system/admin/blocksadmin/main.php

Summary

Maintainability
C
1 day
Test Coverage

editblock accesses the super-global variable $_POST.
Open

function editblock($bid = 0, $clone = FALSE) {
    global $icms_block_handler, $icmsAdminTpl;

    $blockObj = $icms_block_handler->get($bid);

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

editblock accesses the super-global variable $_POST.
Open

function editblock($bid = 0, $clone = FALSE) {
    global $icms_block_handler, $icmsAdminTpl;

    $blockObj = $icms_block_handler->get($bid);

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

editblock accesses the super-global variable $_POST.
Open

function editblock($bid = 0, $clone = FALSE) {
    global $icms_block_handler, $icmsAdminTpl;

    $blockObj = $icms_block_handler->get($bid);

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Function editblock has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

function editblock($bid = 0, $clone = FALSE) {
    global $icms_block_handler, $icmsAdminTpl;

    $blockObj = $icms_block_handler->get($bid);

Severity: Minor
Found in htdocs/modules/system/admin/blocksadmin/main.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 editblock has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function editblock($bid = 0, $clone = FALSE) {
    global $icms_block_handler, $icmsAdminTpl;

    $blockObj = $icms_block_handler->get($bid);

Severity: Minor
Found in htdocs/modules/system/admin/blocksadmin/main.php - About 1 hr to fix

    The function editblock() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
    Open

    function editblock($bid = 0, $clone = FALSE) {
        global $icms_block_handler, $icmsAdminTpl;
    
        $blockObj = $icms_block_handler->get($bid);
    
    

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

    Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

    The method editblock has a boolean flag argument $clone, which is a certain sign of a Single Responsibility Principle violation.
    Open

    function editblock($bid = 0, $clone = FALSE) {

    BooleanArgumentFlag

    Since: 1.4.0

    A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

    Example

    class Foo {
        public function bar($flag = true) {
        }
    }

    Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

    Missing class import via use statement (line '60', column '21').
    Open

            $controller = new icms_ipf_Controller($icms_block_handler);

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    The method editblock uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

        } else {
            if ($clone) {
                if ($blockObj->getVar('block_type') != 'C') {
                    $blockObj->setVar('block_type', 'K');
                    $blockObj->hideFieldFromForm('content');

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

    The method editblock uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

        } else {
            $blockObj->setControl("content", "dhtmltextarea");
        }

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

    The method editblock uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $blockObj->setVar('block_type', 'C');
            }

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

    Reference to static property user from undeclared class \icms
    Open

    if (!is_object(icms::$user) || !is_object($icmsModule) || !icms::$user->isAdmin($icmsModule->getVar('mid'))) {

    Call to method __construct from undeclared class \icms_ipf_view_Table
    Open

                $objectTable = new icms_ipf_view_Table($icms_block_handler);

    Call to method __construct from undeclared class \icms_ipf_view_Column
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('name'));

    Call to method addColumn from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('name'));

    Call to method __construct from undeclared class \icms_ipf_view_Column
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('title', _GLOBAL_LEFT, FALSE, 'getAdminViewItemLink'));

    Call to method __construct from undeclared class \icms_ipf_Controller
    Open

            $controller = new icms_ipf_Controller($icms_block_handler);

    Suspicious array access to nullable ?array
    Open

                        $obj->setVar('weight', (int) $_POST['block_weight'][$k]);

    Reference to undeclared constant \_SUBMIT
    Open

                $objectTable->addActionButton('change_blocks', FALSE, _SUBMIT);

    Suspicious array access to nullable ?array
    Open

                foreach ($_POST['SystemBlocksadmin_objects'] as $k => $v) {

    Variable $icmsModule is undeclared
    Open

    if (!is_object(icms::$user) || !is_object($icmsModule) || !icms::$user->isAdmin($icmsModule->getVar('mid'))) {

    Suspicious array access to nullable ?array
    Open

                    if ($obj->getVar('weight', 'e') != $_POST['block_weight'][$k]) {

    Call to method __construct from undeclared class \icms_ipf_view_Column
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('visible', 'center'));

    Call to method __construct from undeclared class \icms_ipf_view_Column
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('mid'));

    Call to method addCustomAction from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addCustomAction('getDownActionLink');

    Call to method addCustomAction from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addCustomAction('getCloneActionLink');

    Call to method storeFromDefaultForm from undeclared class \icms_ipf_Controller
    Open

                $controller->storeFromDefaultForm(_AM_SYSTEM_BLOCKSADMIN_CREATED, _AM_SYSTEM_BLOCKSADMIN_MODIFIED);

    Call to method __construct from undeclared class \icms_ipf_Controller
    Open

                $controller = new icms_ipf_Controller($icms_block_handler);

    Call to method addQuickSearch from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addQuickSearch(array(

    Call to method fetch from undeclared class \icms_ipf_view_Table
    Open

                $icmsAdminTpl->assign('icms_block_table', $objectTable->fetch());

    Call to method postDataToObject from undeclared class \icms_ipf_Controller
    Open

            $controller->postDataToObject($blockObj);

    Call to method addColumn from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('visible', 'center'));

    Call to method __construct from undeclared class \icms_ipf_view_Column
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('side', 'center', FALSE, 'getSideControl'));

    Call to method addIntroButton from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addIntroButton('addpost', 'admin.php?fct=blocksadmin&amp;op=mod', _AM_SYSTEM_BLOCKSADMIN_CREATE);

    Call to method addColumn from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('title', _GLOBAL_LEFT, FALSE, 'getAdminViewItemLink'));

    Call to method addColumn from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('side', 'center', FALSE, 'getSideControl'));

    Suspicious array access to nullable ?array
    Open

                    if ($obj->getVar('side', 'e') != $_POST['block_side'][$k]) {

    Call to method addColumn from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('mid'));

    Call to method addFilter from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addFilter('side', 'getBlockPositionArray');

    Call to method addColumn from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('weight', 'center', FALSE, 'getWeightControl'));

    Call to method addCustomAction from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addCustomAction('getUpActionLink');

    Call to method addActionButton from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addActionButton('change_blocks', FALSE, _SUBMIT);

    Variable $icmsAdminTpl is undeclared
    Open

                $icmsAdminTpl->assign('icms_block_table', $objectTable->fetch());

    Variable $icmsAdminTpl is undeclared
    Open

                $icmsAdminTpl->display('db:system_adm_blocksadmin.html');

    Call to method __construct from undeclared class \icms_ipf_Controller
    Open

                $controller = new icms_ipf_Controller($icms_block_handler);

    Call to method handleObjectDeletion from undeclared class \icms_ipf_Controller
    Open

                $controller->handleObjectDeletion();

    Call to method addFilter from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addFilter('mid', 'getModulesArray');

    Call to method addCustomAction from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addCustomAction('getBlankLink');

    Suspicious array access to nullable ?array
    Open

                        $obj->setVar('side', (int) $_POST['block_side'][$k]);

    Call to method __construct from undeclared class \icms_ipf_view_Column
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('weight', 'center', FALSE, 'getWeightControl'));

    Call to method addFilter from undeclared class \icms_ipf_view_Table
    Open

                $objectTable->addFilter('visible', 'getVisibleStatusArray');

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

            case "down" :
                $icms_block_handler->downWeight($clean_bid);
                $rtn = '/modules/system/admin.php?fct=blocksadmin';
                if (isset($_GET['sortsel'])) {
                    $rtn .= '&amp;sortsel=' . $sortsel . '&amp;ordersel=' . $ordersel . '&amp;limitsel=' . $limitsel . '&amp;startbid=' . $startbid;
    Severity: Major
    Found in htdocs/modules/system/admin/blocksadmin/main.php and 2 other locations - About 2 hrs to fix
    htdocs/modules/system/admin/blocksadmin/main.php on lines 138..149
    htdocs/modules/system/admin/blocksadmin/main.php on lines 151..162

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

    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 3 locations. Consider refactoring.
    Open

            case "up" :
                $icms_block_handler->upWeight($clean_bid);
                $rtn = '/modules/system/admin.php?fct=blocksadmin';
                if (isset($_GET['sortsel'])) {
                    $rtn .= '&amp;sortsel=' . $sortsel . '&amp;ordersel=' . $ordersel . '&amp;limitsel=' . $limitsel . '&amp;startbid=' . $startbid;
    Severity: Major
    Found in htdocs/modules/system/admin/blocksadmin/main.php and 2 other locations - About 2 hrs to fix
    htdocs/modules/system/admin/blocksadmin/main.php on lines 138..149
    htdocs/modules/system/admin/blocksadmin/main.php on lines 164..175

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

    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 3 locations. Consider refactoring.
    Open

            case 'visible' :
                $icms_block_handler->changeVisible($clean_bid);
                $rtn = '/modules/system/admin.php?fct=blocksadmin';
                if (isset($_GET['sortsel'])) {
                    $rtn .= '&amp;sortsel=' . $sortsel . '&amp;ordersel=' . $ordersel . '&amp;limitsel=' . $limitsel . '&amp;startbid=' . $startbid;
    Severity: Major
    Found in htdocs/modules/system/admin/blocksadmin/main.php and 2 other locations - About 2 hrs to fix
    htdocs/modules/system/admin/blocksadmin/main.php on lines 151..162
    htdocs/modules/system/admin/blocksadmin/main.php on lines 164..175

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

    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

    TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE"
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('title', _GLOBAL_LEFT, FALSE, 'getAdminViewItemLink'));

    TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE"
    Open

    function editblock($bid = 0, $clone = FALSE) {

    TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
    Open

    if (in_array($clean_op, $valid_op, TRUE)) {

    There must be no space before the colon in a CASE statement
    Open

            case "up" :

    TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
    Open

                        $changed = TRUE;

    There must be no space before the colon in a DEFAULT statement
    Open

            default :

    There must be no space before the colon in a CASE statement
    Open

            case "down" :

    There must be no space before the colon in a CASE statement
    Open

            case "addblock" :

    TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE"
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('weight', 'center', FALSE, 'getWeightControl'));

    TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE"
    Open

                $objectTable->addColumn(new icms_ipf_view_Column('side', 'center', FALSE, 'getSideControl'));

    There must be no space before the colon in a CASE statement
    Open

            case "clone" :

    There must be no space before the colon in a CASE statement
    Open

            case "mod" :

    There must be no space before the colon in a CASE statement
    Open

            case "del" :

    TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE"
    Open

                $objectTable->addActionButton('change_blocks', FALSE, _SUBMIT);

    TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE"
    Open

                    $changed = FALSE;

    TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
    Open

                        $changed = TRUE;

    There must be no space before the colon in a CASE statement
    Open

            case 'visible' :

    TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
    Open

                editblock($clean_bid, TRUE);

    There must be no space before the colon in a CASE statement
    Open

            case "changedField" :

    There must be no space before the colon in a CASE statement
    Open

            case "change_blocks" :

    Inline control structures are not allowed
    Open

    if (isset($_GET['op']))

    Inline control structures are not allowed
    Open

    if (isset($_POST['op']))

    Inline control structures are not allowed
    Open

        if (!$blockObj->isNew() && $blockObj->getVar('edit_func') != '') $blockObj->showFieldOnForm('options');

    Expected 1 space after SWITCH keyword; 0 found
    Open

        switch($clean_op) {

    The variable $icms_block_handler is not named in camelCase.
    Open

    function editblock($bid = 0, $clone = FALSE) {
        global $icms_block_handler, $icmsAdminTpl;
    
        $blockObj = $icms_block_handler->get($bid);
    
    

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $icms_block_handler is not named in camelCase.
    Open

    function editblock($bid = 0, $clone = FALSE) {
        global $icms_block_handler, $icmsAdminTpl;
    
        $blockObj = $icms_block_handler->get($bid);
    
    

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $icms_block_handler is not named in camelCase.
    Open

    function editblock($bid = 0, $clone = FALSE) {
        global $icms_block_handler, $icmsAdminTpl;
    
        $blockObj = $icms_block_handler->get($bid);
    
    

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    There are no issues that match your filters.

    Category
    Status