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();
- 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
Missing class import via use statement (line '34', column '21'). Open
$controller = new icms_ipf_Controller($icms_rating_handler);
- Read upRead up
- Exclude checks
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) {
- 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 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);
- 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 editrating($showmenu = FALSE, $ratingid = 0) {
- 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 __construct
from undeclared class \icms_ipf_view_Column
Open
$objectTable->addColumn(new icms_ipf_view_Column('date', 'center', 150));
- Exclude checks
Call to method __construct
from undeclared class \icms_ipf_Controller
Open
$controller = new icms_ipf_Controller($icms_rating_handler);
- Exclude checks
Call to method __construct
from undeclared class \icms_ipf_view_Column
Open
$objectTable->addColumn(new icms_ipf_view_Column('item', _GLOBAL_LEFT, false, 'getItemValue'));
- Exclude checks
Reference to static property user
from undeclared class \icms
Open
if (!is_object(icms::$user) || !is_object($icmsModule) || !icms::$user->isAdmin($icmsModule->getVar('mid'))) {
- Exclude checks
Call to method handleObjectDeletion
from undeclared class \icms_ipf_Controller
Open
$controller->handleObjectDeletion();
- 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 addColumn
from undeclared class \icms_ipf_view_Table
Open
$objectTable->addColumn(new icms_ipf_view_Column('name', _GLOBAL_LEFT, false, 'getUnameValue'));
- Exclude checks
Call to method checkVarArray
from undeclared class \icms_core_DataFilter
Open
$clean_POST = icms_core_DataFilter::checkVarArray($_POST, $filter_post, FALSE);
- Exclude checks
Call to method __construct
from undeclared class \icms_ipf_Controller
Open
$controller = new icms_ipf_Controller($icms_rating_handler);
- Exclude checks
Call to method __construct
from undeclared class \icms_ipf_view_Column
Open
$objectTable->addColumn(new icms_ipf_view_Column('name', _GLOBAL_LEFT, false, 'getUnameValue'));
- Exclude checks
Call to method addColumn
from undeclared class \icms_ipf_view_Table
Open
$objectTable->addColumn(new icms_ipf_view_Column('rate', 'center', 60, 'getRateValue'));
- Exclude checks
Call to method postDataToObject
from undeclared class \icms_ipf_Controller
Open
$controller->postDataToObject($ratingObj);
- Exclude checks
Call to method __construct
from undeclared class \icms_ipf_view_Table
Open
$objectTable = new icms_ipf_view_Table($icms_rating_handler, false, array('delete'));
- Exclude checks
Variable $icmsModule
is undeclared Open
if (!is_object(icms::$user) || !is_object($icmsModule) || !icms::$user->isAdmin($icmsModule->getVar('mid'))) {
- Exclude checks
Call to method addColumn
from undeclared class \icms_ipf_view_Table
Open
$objectTable->addColumn(new icms_ipf_view_Column('dirname', _GLOBAL_LEFT));
- Exclude checks
Call to method addColumn
from undeclared class \icms_ipf_view_Table
Open
$objectTable->addColumn(new icms_ipf_view_Column('date', 'center', 150));
- Exclude checks
Call to method __construct
from undeclared class \icms_ipf_view_Column
Open
$objectTable->addColumn(new icms_ipf_view_Column('rate', 'center', 60, 'getRateValue'));
- Exclude checks
Variable $icmsAdminTpl
is undeclared Open
$icmsAdminTpl->assign('icms_rating_explain', TRUE);
- Exclude checks
Variable $icmsAdminTpl
is undeclared Open
$icmsAdminTpl->display('db:system_adm_rating.html');
- Exclude checks
Call to method __construct
from undeclared class \icms_ipf_view_Column
Open
$objectTable->addColumn(new icms_ipf_view_Column('dirname', _GLOBAL_LEFT));
- Exclude checks
Call to method addColumn
from undeclared class \icms_ipf_view_Table
Open
$objectTable->addColumn(new icms_ipf_view_Column('item', _GLOBAL_LEFT, false, 'getItemValue'));
- Exclude checks
Variable $icmsAdminTpl
is undeclared Open
$icmsAdminTpl->assign('icms_rating_table', $objectTable->fetch());
- Exclude checks
Variable $icmsAdminTpl
is undeclared Open
$icmsAdminTpl->assign('icms_rating_title', _CO_ICMS_RATINGS_DSC);
- Exclude checks
Call to method fetch
from undeclared class \icms_ipf_view_Table
Open
$icmsAdminTpl->assign('icms_rating_table', $objectTable->fetch());
- Exclude checks
Avoid variables with short names like $op. Configured minimum length is 3. Open
global $icms_rating_handler, $icmsAdminTpl, $op, $changedField;
- Read upRead up
- Exclude checks
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);
- Exclude checks
Expected 1 blank line at end of file; 2 found Open
icms_cp_footer();
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE" Open
function editrating($showmenu = FALSE, $ratingid = 0) {
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE" Open
$icmsAdminTpl->assign('icms_rating_explain', TRUE);
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE" Open
$clean_GET = icms_core_DataFilter::checkVarArray($_GET, $filter_get, FALSE);
- Exclude checks
Blank line found at start of control structure Open
if (!$ratingObj->isNew()) {
- Exclude checks
The DEFAULT body must start on the line following the statement Open
default:
- Exclude checks
Inline control structures are not allowed Open
if (isset($_GET['filter_post'])) unset($_GET['filter_post']);
- Exclude checks
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();
- 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_rating_handler is not named in camelCase. Open
function editrating($showmenu = FALSE, $ratingid = 0) {
global $icms_rating_handler, $icmsAdminTpl, $op, $changedField;
icms_cp_header();
- 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_rating_handler is not named in camelCase. Open
function editrating($showmenu = FALSE, $ratingid = 0) {
global $icms_rating_handler, $icmsAdminTpl, $op, $changedField;
icms_cp_header();
- 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();
}
}