Missing class import via use statement (line '33', column '23'). Open
throw new Ajde_Exception(sprintf('JavaScript library %s not
- 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 getUrl uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
throw new Ajde_Exception(sprintf('JavaScript library %s not
available', $name), 90013);
}
- 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 assigning values to variables in if clauses and the like (line '28', column '37'). Open
public static function getUrl($name, $version)
{
if (array_key_exists($name, $libraries = self::$libraries)) {
$url = self::$base.$name.'/'.$version.'/'.$libraries[$name];
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The class Ajde_Resource_JsLibrary is not named in CamelCase. Open
class Ajde_Resource_JsLibrary extends Ajde_Object_Static
{
public static $base = '//ajax.googleapis.com/ajax/libs/';
/*
- 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 {
}