Function __construct
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
{
global $_form_object_options;
\xoops_loadLanguage('modinfo', 'songlist');
- 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 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
{
global $_form_object_options;
\xoops_loadLanguage('modinfo', 'songlist');
Method __construct
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
Function render
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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
The method getOptions has a boolean flag argument $encode, which is a certain sign of a Single Responsibility Principle violation. Open
public function getOptions($encode = false): array
- 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
Missing class import via use statement (line '105', column '37'). Open
$criteria = new \Criteria('');
- 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 getValue has a boolean flag argument $encode, which is a certain sign of a Single Responsibility Principle violation. Open
public function getValue($encode = false): array
- 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
Missing class import via use statement (line '114', column '37'). Open
$criteria = new \Criteria('`' . $field . '`', $id);
- 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 __construct has a boolean flag argument $multiple, which is a certain sign of a Single Responsibility Principle violation. Open
public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
- 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 addOption uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->_options[$value] = $value;
}
- 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 .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
}
- 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 property $_options is not named in camelCase. Open
class SelectSongForm extends \XoopsFormElement
{
/**
* Options
*
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_multiple is not named in camelCase. Open
class SelectSongForm extends \XoopsFormElement
{
/**
* Options
*
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
Avoid variables with short names like $id. Configured minimum length is 3. Open
public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
- 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
The property $_size is not named in camelCase. Open
class SelectSongForm extends \XoopsFormElement
{
/**
* Options
*
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_value is not named in camelCase. Open
class SelectSongForm extends \XoopsFormElement
{
/**
* Options
*
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_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 51 and the first side effect is on line 41. Open
<?php declare(strict_types=1);
- Exclude checks
Property name "$_options" should not be prefixed with an underscore to indicate visibility Open
public $_options = [];
- Exclude checks
Property name "$_multiple" should not be prefixed with an underscore to indicate visibility Open
public $_multiple = false;
- Exclude checks
Property name "$_size" should not be prefixed with an underscore to indicate visibility Open
public $_size;
- Exclude checks
Property name "$_value" should not be prefixed with an underscore to indicate visibility Open
public $_value = [];
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
* Note: both name and value should be sanitized. However, for backward compatibility, only value is sanitized for now.
- Exclude checks
Line exceeds 120 characters; contains 129 characters Open
* @param bool|int $encode To sanitizer the text? potential values: 0 - skip; 1 - only for value; 2 - for both value and name
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
$ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title . '" multiple="multiple">';
- Exclude checks
Line exceeds 120 characters; contains 138 characters Open
$value[$encode ? \htmlspecialchars($val, \ENT_QUOTES) : $val] = ($encode > 1) ? \htmlspecialchars($name, \ENT_QUOTES) : $name;
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
. 'for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected === true) { hasSelected = true; break; } }'
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 16 Open
}
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 16 Open
foreach ($songsHandler->getObjects($criteria) as $id => $obj) {
- Exclude checks
The variable $ele_title is not named in camelCase. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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 $_form_object_options is not named in camelCase. Open
public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
{
global $_form_object_options;
\xoops_loadLanguage('modinfo', 'songlist');
- 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 $ele_name is not named in camelCase. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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 $_form_object_options is not named in camelCase. Open
public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
{
global $_form_object_options;
\xoops_loadLanguage('modinfo', 'songlist');
- 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 $_form_object_options is not named in camelCase. Open
public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
{
global $_form_object_options;
\xoops_loadLanguage('modinfo', 'songlist');
- 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 $ele_options is not named in camelCase. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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 $ele_value is not named in camelCase. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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 $ele_title is not named in camelCase. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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 $_form_object_options is not named in camelCase. Open
public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
{
global $_form_object_options;
\xoops_loadLanguage('modinfo', 'songlist');
- 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 $ele_title is not named in camelCase. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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 $ele_name is not named in camelCase. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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 $_form_object_options is not named in camelCase. Open
public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
{
global $_form_object_options;
\xoops_loadLanguage('modinfo', 'songlist');
- 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 $ele_name is not named in camelCase. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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 $ele_name is not named in camelCase. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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 $_form_object_options is not named in camelCase. Open
public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
{
global $_form_object_options;
\xoops_loadLanguage('modinfo', 'songlist');
- 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 $ele_name is not named in camelCase. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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 $ele_value is not named in camelCase. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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 $ele_value is not named in camelCase. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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 $_form_object_options is not named in camelCase. Open
public function __construct($caption, $name, $value = null, $size = 1, $multiple = false, $id = -1, $field = 'cid')
{
global $_form_object_options;
\xoops_loadLanguage('modinfo', 'songlist');
- 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 $ele_options is not named in camelCase. Open
public function render(): string
{
$ele_name = $this->getName();
$ele_title = $this->getTitle();
$ele_value = $this->getValue();
- 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();
}
}