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) {
- Read upRead up
- Exclude checks
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) {
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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) {
- Read upRead up
- Exclude checks
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);
- Exclude checks
Variable $icmsAdminTpl
is undeclared Open
$icmsAdminTpl->assign('icms_adsense_explain', TRUE);
- Exclude checks
Variable $icmsAdminTpl
is undeclared Open
$icmsAdminTpl->assign('icms_adsense_title', _CO_ICMS_ADSENSES_DSC);
- Exclude checks
Call to method addQuickSearch
from undeclared class \icms_ipf_view_Table
Open
$objectTable->addQuickSearch(array('title', 'summary', 'description'));
- Exclude checks
Call to method __construct
from undeclared class \icms_ipf_view_Column
Open
$objectTable->addColumn(new icms_ipf_view_Column('description', _GLOBAL_LEFT));
- Exclude checks
Call to method fetch
from undeclared class \icms_ipf_view_Table
Open
$icmsAdminTpl->assign('icms_adsense_table', $objectTable->fetch());
- Exclude checks
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'))) {
- Exclude checks
Variable $icmsAdminTpl
is undeclared Open
$icmsAdminTpl->assign('icms_adsense_table', $objectTable->fetch());
- Exclude checks
Call to method __construct
from undeclared class \icms_ipf_Controller
Open
$controller = new icms_ipf_Controller($icms_adsense_handler);
- Exclude checks
Variable $icmsAdminTpl
is undeclared Open
$icmsAdminTpl->display('db:system_adm_adsense.html');
- Exclude checks
Call to method storeFromDefaultForm
from undeclared class \icms_ipf_Controller
Open
$controller->storeFromDefaultForm(_CO_ICMS_ADSENSES_CREATED, _CO_ICMS_ADSENSES_MODIFIED);
- Exclude checks
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'))) {
- Exclude checks
Call to method __construct
from undeclared class \icms_ipf_Controller
Open
$controller = new icms_ipf_Controller($icms_adsense_handler);
- Exclude checks
Call to method handleObjectDeletion
from undeclared class \icms_ipf_Controller
Open
$controller->handleObjectDeletion();
- Exclude checks
Call to method addColumn
from undeclared class \icms_ipf_view_Table
Open
$objectTable->addColumn(new icms_ipf_view_Column('description', _GLOBAL_LEFT));
- Exclude checks
Call to method __construct
from undeclared class \icms_ipf_view_Table
Open
$objectTable = new icms_ipf_view_Table($icms_adsense_handler);
- Exclude checks
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'));
- Exclude checks
Call to method checkVarArray
from undeclared class \icms_core_DataFilter
Open
$clean_GET = icms_core_DataFilter::checkVarArray($_GET, $filter_get, false);
- Exclude checks
Call to method addCustomAction
from undeclared class \icms_ipf_view_Table
Open
$objectTable->addCustomAction('getCloneLink');
- Exclude checks
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'));
- Exclude checks
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);
- Exclude checks
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');
- 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 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
- 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
TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE" Open
function editadsense($showmenu = FALSE, $adsenseid = 0, $clone = FALSE) {
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE" Open
editadsense(TRUE, $adsenseid);
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE" Open
function editadsense($showmenu = FALSE, $adsenseid = 0, $clone = FALSE) {
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE" Open
editadsense(TRUE, $adsenseid, TRUE);
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE" Open
$icmsAdminTpl->assign('icms_adsense_explain', TRUE);
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE" Open
editadsense(TRUE, $adsenseid, TRUE);
- Exclude checks
Inline control structures are not allowed Open
if (isset($_GET['filter_post'])) unset($_GET['filter_post']);
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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();
}
}