File permissions.php
has 319 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php declare(strict_types=1);
/*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
Function _renderOptionTree
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function _renderOptionTree(&$tree, $option, $prefix, $parentIds = []): void
{
if ($option['id'] > 0) :
$tree .= $prefix . '<input type="checkbox" name="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" onclick="';
foreach ($parentIds as $pid) {
- 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
Method render
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function render(): string
{
// load all child ids for javascript codes
foreach (array_keys($this->_itemTree) as $item_id) {
$this->_itemTree[$item_id]['allchild'] = [];
Method _renderOptionTree
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function _renderOptionTree(&$tree, $option, $prefix, $parentIds = []): void
{
if ($option['id'] > 0) :
$tree .= $prefix . '<input type="checkbox" name="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" onclick="';
foreach ($parentIds as $pid) {
Function render
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function render(): string
{
// load all child ids for javascript codes
foreach (array_keys($this->_itemTree) as $item_id) {
$this->_itemTree[$item_id]['allchild'] = [];
- 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
Method __construct
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function __construct($title, $modid, $permname, $permdesc, $url = '')
Function render
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function render(): string
{
$ret = '<table class="outer"><tr><td class="odd"><table><tr>';
$cols = 1;
foreach ($this->_optionTree[0]['children'] as $topitem) {
- 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
Avoid using undefined variables such as '$option_ids' which will lead to PHP notices. Open
$option_ids_str = implode(', ', $option_ids);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$option_ids' which will lead to PHP notices. Open
$option_ids[] = "'" . $this->getName() . '[groups][' . $this->_groupId . '][' . $id . ']' . "'";
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Missing class import via use statement (line '72', column '21'). Open
$tray = new \XoopsFormElementTray('');
- 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
Missing class import via use statement (line '74', column '31'). Open
$tray->addElement(new \XoopsFormButton('', 'reset', _CANCEL, 'reset'));
- 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
Missing class import via use statement (line '67', column '29'). Open
$ele = new forum_XoopsGroupFormCheckBox($glist[$i], 'perms[' . $this->_permName . ']', $i, $selected);
- 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
Missing class import via use statement (line '73', column '31'). Open
$tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
- 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 _renderOptionTree uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
else :
$tree .= $prefix . $option['name'] . '<input type="hidden" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . "]\"><br>\n";
endif;
- 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
The method render uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$ret .= "<tr valign='top' align='left'><td class='head'>" . $elements[$i]->getCaption();
if ('' != $elements[$i]->getDescription()) {
$ret .= '<br><br><span style="font-weight: normal;">' . $elements[$i]->getDescription() . '</span>';
}
- 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
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class forum_XoopsGroupFormCheckBox extends \XoopsGroupFormCheckBox
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class forum_XoopsGroupPermForm extends \XoopsGroupPermForm
- Exclude checks
The class forum_XoopsGroupPermForm is not named in CamelCase. Open
class forum_XoopsGroupPermForm extends \XoopsGroupPermForm
{
/**
* forum_XoopsGroupPermForm constructor.
* @param $title
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
The class forum_XoopsGroupFormCheckBox is not named in CamelCase. Open
class forum_XoopsGroupFormCheckBox extends \XoopsGroupFormCheckBox
{
/**
* forum_XoopsGroupFormCheckBox constructor.
* @param $caption
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 34 and the first side effect is on line 21. Open
<?php declare(strict_types=1);
- Exclude checks
Each class must be in a file by itself Open
class forum_XoopsGroupFormCheckBox extends \XoopsGroupFormCheckBox
- Exclude checks
Method name "_renderOptionTree" should not be prefixed with an underscore to indicate visibility Open
public function _renderOptionTree(&$tree, $option, $prefix, $parentIds = []): void
- Exclude checks
Line exceeds 120 characters; contains 152 characters Open
$fm_options = ['category' => ['title' => _AM_SONGLIST_CAT_ACCESS, 'item' => 'category_access', 'desc' => '', 'anonymous' => true]];
- Exclude checks
Line exceeds 120 characters; contains 134 characters Open
$tree .= "var ele = xoopsGetElementById('" . $child_ele . "'); if(this.checked !== true) {ele.checked = false;}";
- Exclude checks
Line exceeds 120 characters; contains 228 characters Open
$ret_ele .= _ALL . ' <input id="checkall[' . $i . ']" type="checkbox" value="" onclick="var optionids = new Array(' . implode(', ', $option_ids) . '); xoopsCheckAllElements(optionids, \'checkall[' . $i . ']\')">';
- Exclude checks
Line exceeds 120 characters; contains 132 characters Open
$op = isset($_GET['op']) ? \mb_strtolower($_GET['op']) : (isset($_COOKIE['op']) ? \mb_strtolower($_COOKIE['op']) : '');
- Exclude checks
Line exceeds 120 characters; contains 223 characters Open
$ret .= _ALL . ' <input id="' . $checkallbtn_id . '" type="checkbox" value="" onclick="var optionids = new Array(' . $option_ids_str . "); xoopsCheckAllElements(optionids, '" . $checkallbtn_id . "');\">";
- Exclude checks
Line exceeds 120 characters; contains 138 characters Open
$op_select->addOptionArray(['no' => _SELECT, 'template' => _AM_SONGLIST_PERM_TEMPLATE, 'apply' => _AM_SONGLIST_PERM_TEMPLATEAPP]);
- Exclude checks
Line exceeds 120 characters; contains 163 characters Open
$fm_options[$perm] = ['title' => constant('_AM_SONGLIST_CAN_' . \mb_strtoupper($perm)), 'item' => 'forum_' . $perm, 'desc' => '', 'anonymous' => true];
- Exclude checks
Line exceeds 120 characters; contains 240 characters Open
$tree .= $prefix . '<input type="checkbox" name="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" onclick="';
- Exclude checks
Line exceeds 120 characters; contains 256 characters Open
$ret .= "<form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "'" . $this->getExtra() . ">\n<table width='100%' class='outer' cellspacing='1' valign='top'>\n";
- Exclude checks
Line exceeds 120 characters; contains 179 characters Open
* Note: this is a __patchy__ solution. We should have a more extensible and flexible group permission management: not only for data architecture but also for management interface
- Exclude checks
Line exceeds 120 characters; contains 166 characters Open
$tree .= $prefix . $option['name'] . '<input type="hidden" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . "]\"><br>\n";
- Exclude checks
Line exceeds 120 characters; contains 245 characters Open
$ret_ele .= '<td><input name="perms[' . $i . '][' . 'forum_' . $perm . ']" id="' . $option_id . '" onclick="" value="1" type="checkbox"' . $checked . '>' . constant('_AM_SONGLIST_CAN_' . \mb_strtoupper($perm)) . '<br></td>';
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
$ret .= "<form name='template' id='template' method='post'>\n<table width='100%' class='outer' cellspacing='1'>\n";
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
require_once XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['songlistModule']->getVar('dirname') . '/class/xoopsformloader.php';
- Exclude checks
Line exceeds 120 characters; contains 192 characters Open
$form = new forum_XoopsGroupPermForm($fm_options[$op]['title'], $module_id, $fm_options[$op]['item'], $fm_options[$op]['desc'], 'admin/permissions.php', $fm_options[$op]['anonymous']);
- Exclude checks
Line exceeds 120 characters; contains 142 characters Open
$tree .= "var ele = xoopsGetElementById('" . $parent_ele . "'); if(ele.checked !== true) {ele.checked = this.checked;}";
- Exclude checks
Line exceeds 120 characters; contains 286 characters Open
$tree .= '>' . $option['name'] . '<input type="hidden" name="' . $this->getName() . '[parents][' . $option['id'] . ']" value="' . implode(':', $parentIds) . '"><input type="hidden" name="' . $this->getName() . '[itemname][' . $option['id'] . ']" value="' . htmlspecialchars(
- Exclude checks
Class name "forum_XoopsGroupPermForm" is not in camel caps format Open
class forum_XoopsGroupPermForm extends \XoopsGroupPermForm
- Exclude checks
Multi-line function call not indented correctly; expected 16 spaces but found 20 Open
$option['name'],
- Exclude checks
Multi-line function call not indented correctly; expected 16 spaces but found 20 Open
ENT_QUOTES | ENT_HTML5
- Exclude checks
Class name "forum_XoopsGroupFormCheckBox" is not in camel caps format Open
class forum_XoopsGroupFormCheckBox extends \XoopsGroupFormCheckBox
- Exclude checks
Multi-line function call not indented correctly; expected 12 spaces but found 16 Open
) . "\"><br>\n";
- Exclude checks
The variable $item_id is not named in camelCase. Open
public function render(): string
{
// load all child ids for javascript codes
foreach (array_keys($this->_itemTree) as $item_id) {
$this->_itemTree[$item_id]['allchild'] = [];
- 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 $item_id is not named in camelCase. Open
public function render(): string
{
// load all child ids for javascript codes
foreach (array_keys($this->_itemTree) as $item_id) {
$this->_itemTree[$item_id]['allchild'] = [];
- 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 $checkallbtn_id is not named in camelCase. Open
public function render(): string
{
$ret = '<table class="outer"><tr><td class="odd"><table><tr>';
$cols = 1;
foreach ($this->_optionTree[0]['children'] as $topitem) {
- 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 $child_ele is not named in camelCase. Open
public function _renderOptionTree(&$tree, $option, $prefix, $parentIds = []): void
{
if ($option['id'] > 0) :
$tree .= $prefix . '<input type="checkbox" name="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" onclick="';
foreach ($parentIds as $pid) {
- 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 $checkallbtn_id is not named in camelCase. Open
public function render(): string
{
$ret = '<table class="outer"><tr><td class="odd"><table><tr>';
$cols = 1;
foreach ($this->_optionTree[0]['children'] as $topitem) {
- 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 $item_id is not named in camelCase. Open
public function render(): string
{
// load all child ids for javascript codes
foreach (array_keys($this->_itemTree) as $item_id) {
$this->_itemTree[$item_id]['allchild'] = [];
- 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 $item_id is not named in camelCase. Open
public function render(): string
{
// load all child ids for javascript codes
foreach (array_keys($this->_itemTree) as $item_id) {
$this->_itemTree[$item_id]['allchild'] = [];
- 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 $checkallbtn_id is not named in camelCase. Open
public function render(): string
{
$ret = '<table class="outer"><tr><td class="odd"><table><tr>';
$cols = 1;
foreach ($this->_optionTree[0]['children'] as $topitem) {
- 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 $option_ids_str is not named in camelCase. Open
public function render(): string
{
$ret = '<table class="outer"><tr><td class="odd"><table><tr>';
$cols = 1;
foreach ($this->_optionTree[0]['children'] as $topitem) {
- 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 $child_ele is not named in camelCase. Open
public function _renderOptionTree(&$tree, $option, $prefix, $parentIds = []): void
{
if ($option['id'] > 0) :
$tree .= $prefix . '<input type="checkbox" name="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" onclick="';
foreach ($parentIds as $pid) {
- 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 $parent_ele is not named in camelCase. Open
public function _renderOptionTree(&$tree, $option, $prefix, $parentIds = []): void
{
if ($option['id'] > 0) :
$tree .= $prefix . '<input type="checkbox" name="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" onclick="';
foreach ($parentIds as $pid) {
- 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 $option_ids is not named in camelCase. Open
public function render(): string
{
$ret = '<table class="outer"><tr><td class="odd"><table><tr>';
$cols = 1;
foreach ($this->_optionTree[0]['children'] as $topitem) {
- 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 $option_ids_str is not named in camelCase. Open
public function render(): string
{
$ret = '<table class="outer"><tr><td class="odd"><table><tr>';
$cols = 1;
foreach ($this->_optionTree[0]['children'] as $topitem) {
- 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 $parent_ele is not named in camelCase. Open
public function _renderOptionTree(&$tree, $option, $prefix, $parentIds = []): void
{
if ($option['id'] > 0) :
$tree .= $prefix . '<input type="checkbox" name="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" onclick="';
foreach ($parentIds as $pid) {
- 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 $option_ids is not named in camelCase. Open
public function render(): string
{
$ret = '<table class="outer"><tr><td class="odd"><table><tr>';
$cols = 1;
foreach ($this->_optionTree[0]['children'] as $topitem) {
- 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 method _renderOptionTree is not named in camelCase. Open
public function _renderOptionTree(&$tree, $option, $prefix, $parentIds = []): void
{
if ($option['id'] > 0) :
$tree .= $prefix . '<input type="checkbox" name="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" id="' . $this->getName() . '[groups][' . $this->_groupId . '][' . $option['id'] . ']" onclick="';
foreach ($parentIds as $pid) {
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}