Method sortValues
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function sortValues()
{
# TODO: sort by URI as last resort
# Note that getLabel() returns URIs in case of no label and may return a prefixed value which affects sorting
if (!empty($this->values)) {
Method __construct
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public function __construct($model, $prop, $label, $tooltip = null, $super = null, $sort_by_notation = false)
Avoid too many return
statements within this method. Open
return strcoll($a->getSortKey(), $b->getSortKey());
Avoid too many return
statements within this method. Open
return strnatcasecmp($anot, $bnot);
The method __construct has a boolean flag argument $sort_by_notation, which is a certain sign of a Single Responsibility Principle violation. Open
public function __construct($model, $prop, $label, $tooltip = null, $super = null, $sort_by_notation = 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 sortValues uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else { // natural
return strnatcasecmp($anot, $bnot);
}
- 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 sortValues uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// assume that notations are unique, choose strategy
if ($this->sort_by_notation == "lexical") {
return strcoll($anot, $bnot);
} else { // natural
- 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 sortValues uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
uasort($this->values, function ($a, $b) {
// assume that sort keys are unique
return strcoll($a->getSortKey(), $b->getSortKey());
});
- 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
TODO found Open
# TODO: sort by URI as last resort
- Exclude checks
The parameter $sort_by_notation is not named in camelCase. Open
public function __construct($model, $prop, $label, $tooltip = null, $super = null, $sort_by_notation = false)
{
$this->model = $model;
$this->prop = $prop;
$this->label = $label;
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
Avoid variables with short names like $b. Configured minimum length is 3. Open
uasort($this->values, function ($a, $b) {
- 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 $sort_by_notation is not named in camelCase. Open
class ConceptProperty
{
/** stores the Model object (used for translations) */
private $model;
/** stores the property type */
- 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 $a. Configured minimum length is 3. Open
uasort($this->values, function ($a, $b) {
- 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 $is_sorted is not named in camelCase. Open
class ConceptProperty
{
/** stores the Model object (used for translations) */
private $model;
/** stores the property type */
- 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 variable $sort_by_notation is not named in camelCase. Open
public function __construct($model, $prop, $label, $tooltip = null, $super = null, $sort_by_notation = false)
{
$this->model = $model;
$this->prop = $prop;
$this->label = $label;
- 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();
}
}