src/ELearn/Views.php

Summary

Maintainability
A
0 mins
Test Coverage

Missing class import via use statement (line '15', column '20').
Open

        return new Pluf_HTTP_Response_Json($object->getList());
Severity: Minor
Found in src/ELearn/Views.php by phpmd

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(
Severity: Minor
Found in src/ELearn/Views.php by phpmd

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){
Severity: Major
Found in src/ELearn/Views.php by sonar-php

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){
Severity: Major
Found in src/ELearn/Views.php by sonar-php

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(
Severity: Major
Found in src/ELearn/Views.php by sonar-php

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

Avoid unused parameters such as '$request'.
Open

    public static function listAll($request, $match, $p){
Severity: Minor
Found in src/ELearn/Views.php by phpmd

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){
Severity: Minor
Found in src/ELearn/Views.php by phpmd

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){
Severity: Minor
Found in src/ELearn/Views.php by phan

Call to method __construct from undeclared class \Pluf_HTTP_Response_Json
Open

        return new Pluf_HTTP_Response_Json($object->getList());
Severity: Critical
Found in src/ELearn/Views.php by phan

Parameter $request has undeclared type \Pluf_HTTP_Request
Open

    public static function listAll($request, $match, $p){
Severity: Minor
Found in src/ELearn/Views.php by phan

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class ELearn_Views{
Severity: Minor
Found in src/ELearn/Views.php by phpcodesniffer

Avoid variables with short names like $p. Configured minimum length is 3.
Open

    private static function getModel ($p)
Severity: Minor
Found in src/ELearn/Views.php by phpmd

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
Severity: Minor
Found in src/ELearn/Views.php by phpmd

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){
Severity: Minor
Found in src/ELearn/Views.php by phpmd

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)
Severity: Minor
Found in src/ELearn/Views.php by phpcodesniffer

Expected 0 spaces before opening parenthesis; 1 found
Open

    private static function getModel ($p)
Severity: Minor
Found in src/ELearn/Views.php by phpcodesniffer

Opening brace of a class must be on the line after the definition
Open

class ELearn_Views{
Severity: Minor
Found in src/ELearn/Views.php by phpcodesniffer

The closing brace for the class must go on the next line after the body
Open

}
Severity: Minor
Found in src/ELearn/Views.php by phpcodesniffer

Whitespace found at end of line
Open

     * Return list of all instance of the data model defined in $p 
Severity: Minor
Found in src/ELearn/Views.php by phpcodesniffer

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.');
Severity: Minor
Found in src/ELearn/Views.php by phpcodesniffer

Class name "ELearn_Views" is not in camel caps format
Open

class ELearn_Views{
Severity: Minor
Found in src/ELearn/Views.php by phpcodesniffer

Expected 1 newline at end of file; 0 found
Open

}
Severity: Minor
Found in src/ELearn/Views.php by phpcodesniffer

Opening brace should be on a new line
Open

    public static function listAll($request, $match, $p){
Severity: Minor
Found in src/ELearn/Views.php by phpcodesniffer

Multi-line function call not indented correctly; expected 12 spaces but found 16
Open

                'The model class was not provided in the parameters.');
Severity: Minor
Found in src/ELearn/Views.php by phpcodesniffer

There are no issues that match your filters.

Category
Status