ImpressCMS/impresscms

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

Summary

Maintainability
A
25 mins
Test Coverage

Function editrating has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

function editrating($showmenu = FALSE, $ratingid = 0) {
    global $icms_rating_handler, $icmsAdminTpl, $op, $changedField;

    icms_cp_header();

Severity: Minor
Found in htdocs/modules/system/admin/rating/main.php - About 25 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

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

        $controller = new icms_ipf_Controller($icms_rating_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 editrating has a boolean flag argument $showmenu, which is a certain sign of a Single Responsibility Principle violation.
Open

function editrating($showmenu = FALSE, $ratingid = 0) {

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

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

    } else {
        $ratingObj->hideFieldFromForm(array('item', 'itemid', 'uid', 'date', 'rate'));

        $controller = new icms_ipf_Controller($icms_rating_handler);
        $controller->postDataToObject($ratingObj);

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

Avoid unused parameters such as '$showmenu'.
Open

function editrating($showmenu = FALSE, $ratingid = 0) {

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

Call to method __construct from undeclared class \icms_ipf_view_Column
Open

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

Call to method __construct from undeclared class \icms_ipf_Controller
Open

        $controller = new icms_ipf_Controller($icms_rating_handler);

Call to method __construct from undeclared class \icms_ipf_view_Column
Open

        $objectTable->addColumn(new icms_ipf_view_Column('item', _GLOBAL_LEFT, false, 'getItemValue'));

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 handleObjectDeletion from undeclared class \icms_ipf_Controller
Open

        $controller->handleObjectDeletion();

Call to method checkVarArray from undeclared class \icms_core_DataFilter
Open

    $clean_GET = icms_core_DataFilter::checkVarArray($_GET, $filter_get, FALSE);

Call to method addColumn from undeclared class \icms_ipf_view_Table
Open

        $objectTable->addColumn(new icms_ipf_view_Column('name', _GLOBAL_LEFT, false, 'getUnameValue'));

Call to method checkVarArray from undeclared class \icms_core_DataFilter
Open

    $clean_POST = icms_core_DataFilter::checkVarArray($_POST, $filter_post, FALSE);

Call to method __construct from undeclared class \icms_ipf_Controller
Open

        $controller = new icms_ipf_Controller($icms_rating_handler);

Call to method __construct from undeclared class \icms_ipf_view_Column
Open

        $objectTable->addColumn(new icms_ipf_view_Column('name', _GLOBAL_LEFT, false, 'getUnameValue'));

Call to method addColumn from undeclared class \icms_ipf_view_Table
Open

        $objectTable->addColumn(new icms_ipf_view_Column('rate', 'center', 60, 'getRateValue'));

Call to method postDataToObject from undeclared class \icms_ipf_Controller
Open

        $controller->postDataToObject($ratingObj);

Call to method __construct from undeclared class \icms_ipf_view_Table
Open

        $objectTable = new icms_ipf_view_Table($icms_rating_handler, false, array('delete'));

Variable $icmsModule is undeclared
Open

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

Call to method addColumn from undeclared class \icms_ipf_view_Table
Open

        $objectTable->addColumn(new icms_ipf_view_Column('dirname', _GLOBAL_LEFT));

Call to method addColumn from undeclared class \icms_ipf_view_Table
Open

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

Call to method __construct from undeclared class \icms_ipf_view_Column
Open

        $objectTable->addColumn(new icms_ipf_view_Column('rate', 'center', 60, 'getRateValue'));

Variable $icmsAdminTpl is undeclared
Open

        $icmsAdminTpl->assign('icms_rating_explain', TRUE);

Variable $icmsAdminTpl is undeclared
Open

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

Call to method __construct from undeclared class \icms_ipf_view_Column
Open

        $objectTable->addColumn(new icms_ipf_view_Column('dirname', _GLOBAL_LEFT));

Call to method addColumn from undeclared class \icms_ipf_view_Table
Open

        $objectTable->addColumn(new icms_ipf_view_Column('item', _GLOBAL_LEFT, false, 'getItemValue'));

Variable $icmsAdminTpl is undeclared
Open

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

Variable $icmsAdminTpl is undeclared
Open

        $icmsAdminTpl->assign('icms_rating_title', _CO_ICMS_RATINGS_DSC);

Call to method fetch from undeclared class \icms_ipf_view_Table
Open

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

Avoid variables with short names like $op. Configured minimum length is 3.
Open

    global $icms_rating_handler, $icmsAdminTpl, $op, $changedField;

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

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

    $clean_POST = icms_core_DataFilter::checkVarArray($_POST, $filter_post, FALSE);

Expected 1 blank line at end of file; 2 found
Open

icms_cp_footer();

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

function editrating($showmenu = FALSE, $ratingid = 0) {

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

        $icmsAdminTpl->assign('icms_rating_explain', TRUE);

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

    $clean_GET = icms_core_DataFilter::checkVarArray($_GET, $filter_get, FALSE);

Blank line found at start of control structure
Open

    if (!$ratingObj->isNew()) {

The DEFAULT body must start on the line following the statement
Open

    default:

Inline control structures are not allowed
Open

    if (isset($_GET['filter_post'])) unset($_GET['filter_post']);

The variable $icms_rating_handler is not named in camelCase.
Open

function editrating($showmenu = FALSE, $ratingid = 0) {
    global $icms_rating_handler, $icmsAdminTpl, $op, $changedField;

    icms_cp_header();

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_rating_handler is not named in camelCase.
Open

function editrating($showmenu = FALSE, $ratingid = 0) {
    global $icms_rating_handler, $icmsAdminTpl, $op, $changedField;

    icms_cp_header();

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_rating_handler is not named in camelCase.
Open

function editrating($showmenu = FALSE, $ratingid = 0) {
    global $icms_rating_handler, $icmsAdminTpl, $op, $changedField;

    icms_cp_header();

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