ImpressCMS/impresscms

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

Summary

Maintainability
A
3 hrs
Test Coverage

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

function editadsense($showmenu = FALSE, $adsenseid = 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

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

function editadsense($showmenu = FALSE, $adsenseid = 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

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

    } else {
        $adsenseObj->setVar('adsenseid', 0);
        $adsenseObj->setVar('tag', '');
        $sform = $adsenseObj->getForm(_CO_ICMS_ADSENSES_CREATE, 'addadsense');
        $sform->assign($icmsAdminTpl);

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 editadsense($showmenu = FALSE, $adsenseid = 0, $clone = FALSE) {

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 checkVarArray from undeclared class \icms_core_DataFilter
Open

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

Variable $icmsAdminTpl is undeclared
Open

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

Variable $icmsAdminTpl is undeclared
Open

        $icmsAdminTpl->assign('icms_adsense_title', _CO_ICMS_ADSENSES_DSC);

Call to method addQuickSearch from undeclared class \icms_ipf_view_Table
Open

        $objectTable->addQuickSearch(array('title', 'summary', 'description'));

Call to method __construct from undeclared class \icms_ipf_view_Column
Open

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

Call to method fetch from undeclared class \icms_ipf_view_Table
Open

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

Reference to static property module from undeclared class \icms
Open

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

Variable $icmsAdminTpl is undeclared
Open

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

Call to method __construct from undeclared class \icms_ipf_Controller
Open

        $controller = new icms_ipf_Controller($icms_adsense_handler);

Variable $icmsAdminTpl is undeclared
Open

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

Call to method storeFromDefaultForm from undeclared class \icms_ipf_Controller
Open

        $controller->storeFromDefaultForm(_CO_ICMS_ADSENSES_CREATED, _CO_ICMS_ADSENSES_MODIFIED);

Reference to static property user from undeclared class \icms
Open

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

Call to method __construct from undeclared class \icms_ipf_Controller
Open

        $controller = new icms_ipf_Controller($icms_adsense_handler);

Call to method handleObjectDeletion from undeclared class \icms_ipf_Controller
Open

        $controller->handleObjectDeletion();

Call to method addColumn from undeclared class \icms_ipf_view_Table
Open

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

Call to method __construct from undeclared class \icms_ipf_view_Table
Open

        $objectTable = new icms_ipf_view_Table($icms_adsense_handler);

Call to method __construct from undeclared class \icms_ipf_view_Column
Open

        $objectTable->addColumn(new icms_ipf_view_Column(_CO_ICMS_ADSENSE_TAG_CODE, 'center', 200, 'getXoopsCode'));

Call to method checkVarArray from undeclared class \icms_core_DataFilter
Open

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

Call to method addCustomAction from undeclared class \icms_ipf_view_Table
Open

        $objectTable->addCustomAction('getCloneLink');

Call to method addColumn from undeclared class \icms_ipf_view_Table
Open

        $objectTable->addColumn(new icms_ipf_view_Column(_CO_ICMS_ADSENSE_TAG_CODE, 'center', 200, 'getXoopsCode'));

Call to method addIntroButton from undeclared class \icms_ipf_view_Table
Open

        $objectTable->addIntroButton('addadsense', 'admin.php?fct=adsense&op=mod', _CO_ICMS_ADSENSES_CREATE);

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

    if (!$clone && !$adsenseObj->isNew()) {
        $sform = $adsenseObj->getForm(_CO_ICMS_ADSENSES_EDIT, 'addadsense');
        $sform->assign($icmsAdminTpl);
        $icmsAdminTpl->assign('icms_adsense_title', _CO_ICMS_ADSENSES_EDIT_INFO);
        $icmsAdminTpl->display('db:system_adm_adsense.html');
Severity: Major
Found in htdocs/modules/system/admin/adsense/main.php and 1 other location - About 3 hrs to fix
htdocs/modules/system/admin/customtag/main.php on lines 49..63

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

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

function editadsense($showmenu = FALSE, $adsenseid = 0, $clone = FALSE) {

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

        editadsense(TRUE, $adsenseid);

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

function editadsense($showmenu = FALSE, $adsenseid = 0, $clone = FALSE) {

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

        editadsense(TRUE, $adsenseid, TRUE);

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

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

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

        editadsense(TRUE, $adsenseid, TRUE);

Inline control structures are not allowed
Open

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

The variable $icms_adsense_handler is not named in camelCase.
Open

function editadsense($showmenu = FALSE, $adsenseid = 0, $clone = FALSE) {
    global $icms_adsense_handler, $icmsAdminTpl;

    icms_cp_header();
    $adsenseObj = $icms_adsense_handler->get($adsenseid);

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

function editadsense($showmenu = FALSE, $adsenseid = 0, $clone = FALSE) {
    global $icms_adsense_handler, $icmsAdminTpl;

    icms_cp_header();
    $adsenseObj = $icms_adsense_handler->get($adsenseid);

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