Missing class import via use statement (line '15', column '20'). Open
return new Pluf_HTTP_Response_Json($object->getList());
- 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 '22', column '23'). Open
throw new Exception(
- 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
Remove the unused function parameter "$request". Open
public static function listAll($request, $match, $p){
- Read upRead up
- Exclude checks
Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.
Noncompliant Code Example
function doSomething($a, $b) { // "$a" is unused return compute($b); }
Compliant Solution
function doSomething($b) { return compute($b); }
Exceptions
Functions in classes that override a class or implement interfaces are ignored.
class C extends B { function doSomething($a, $b) { // no issue reported on $b compute($a); } }
See
- MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
- MISRA C:2012, 2.7 - There should be no unused parameters in functions
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- CERT, MSC12-CPP. - Detect and remove code that has no effect
Remove the unused function parameter "$match". Open
public static function listAll($request, $match, $p){
- Read upRead up
- Exclude checks
Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.
Noncompliant Code Example
function doSomething($a, $b) { // "$a" is unused return compute($b); }
Compliant Solution
function doSomething($b) { return compute($b); }
Exceptions
Functions in classes that override a class or implement interfaces are ignored.
class C extends B { function doSomething($a, $b) { // no issue reported on $b compute($a); } }
See
- MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
- MISRA C:2012, 2.7 - There should be no unused parameters in functions
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- CERT, MSC12-CPP. - Detect and remove code that has no effect
Define and throw a dedicated exception instead of using a generic one. Open
throw new Exception(
- Read upRead up
- Exclude checks
If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.
Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.
Noncompliant Code Example
throw new Exception(); // Noncompliant
Compliant Solution
throw new InvalidArgumentException(); // or throw new UnexpectedValueException();
See
- MITRE, CWE-397 - Declaration of Throws for Generic Exception
- CERT, ERR07-J. - Do not throw RuntimeException, Exception, or Throwable
Avoid unused parameters such as '$request'. Open
public static function listAll($request, $match, $p){
- 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
Avoid unused parameters such as '$match'. Open
public static function listAll($request, $match, $p){
- 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
Return type of listAll()
is undeclared type \Pluf_HTTP_Response_Json
Open
public static function listAll($request, $match, $p){
- Exclude checks
Call to method __construct
from undeclared class \Pluf_HTTP_Response_Json
Open
return new Pluf_HTTP_Response_Json($object->getList());
- Exclude checks
Parameter $request
has undeclared type \Pluf_HTTP_Request
Open
public static function listAll($request, $match, $p){
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class ELearn_Views{
- Exclude checks
Avoid variables with short names like $p. Configured minimum length is 3. Open
private static function getModel ($p)
- 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 class ELearn_Views is not named in CamelCase. Open
class ELearn_Views{
/**
* Return list of all instance of the data model defined in $p
* @param Pluf_HTTP_Request $request
- 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
Avoid variables with short names like $p. Configured minimum length is 3. Open
public static function listAll($request, $match, $p){
- 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
Expected "function abc(...)"; found "function abc (...)" Open
private static function getModel ($p)
- Exclude checks
Expected 0 spaces before opening parenthesis; 1 found Open
private static function getModel ($p)
- Exclude checks
Opening brace of a class must be on the line after the definition Open
class ELearn_Views{
- Exclude checks
The closing brace for the class must go on the next line after the body Open
}
- Exclude checks
Whitespace found at end of line Open
* Return list of all instance of the data model defined in $p
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
'The model class was not provided in the parameters.');
- Exclude checks
Class name "ELearn_Views" is not in camel caps format Open
class ELearn_Views{
- Exclude checks
Expected 1 newline at end of file; 0 found Open
}
- Exclude checks
Opening brace should be on a new line Open
public static function listAll($request, $match, $p){
- Exclude checks
Multi-line function call not indented correctly; expected 12 spaces but found 16 Open
'The model class was not provided in the parameters.');
- Exclude checks