src/ELearn/Shortcuts.php

Summary

Maintainability
A
0 mins
Test Coverage

Missing class import via use statement (line '13', column '17').
Open

    $item = new ELearn_Topic();
Severity: Minor
Found in src/ELearn/Shortcuts.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 '44', column '19').
Open

        throw new Pluf_Exception(__('Part name must not be new, find'));
Severity: Minor
Found in src/ELearn/Shortcuts.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 '55', column '15').
Open

    throw new Pluf_Exception(sprintf(__('Part with the same name exist (name: %s'), $name));
Severity: Minor
Found in src/ELearn/Shortcuts.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 '84', column '15').
Open

    throw new Pluf_Exception_DoesNotExist("Part not found (Part name:" . $name . ")");
Severity: Minor
Found in src/ELearn/Shortcuts.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 '10', column '14').
Open

    $q = new Pluf_SQL('title=%s', array(
Severity: Minor
Found in src/ELearn/Shortcuts.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 '67', column '14').
Open

    $q = new Pluf_SQL('name=%s', array(
Severity: Minor
Found in src/ELearn/Shortcuts.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 '46', column '14').
Open

    $q = new Pluf_SQL('name=%s', array(
Severity: Minor
Found in src/ELearn/Shortcuts.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 '70', column '17').
Open

    $item = new ELearn_Part();
Severity: Minor
Found in src/ELearn/Shortcuts.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

Avoid using static access to class 'Pluf_Log' in method 'ELearn_Shortcuts_GetPartByNameOr404'.
Open

        Pluf_Log::error(
            sprintf(
                'more than one Part exist with the name $s', $name));
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Define a constant instead of duplicating this literal "filter" 4 times.
Open

        'filter' => $q->gen()
Severity: Critical
Found in src/ELearn/Shortcuts.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Add curly braces around the nested statement(s).
Open

    if ($count > 30)
Severity: Critical
Found in src/ELearn/Shortcuts.php by sonar-php

While not technically incorrect, the omission of curly braces can be misleading, and may lead to the introduction of errors during maintenance.

Noncompliant Code Example

if (condition)  // Noncompliant
  executeSomething();

Compliant Solution

if (condition) {
  executeSomething();
}

See

  • MISRA C:2004, 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
  • MISRA C:2004, 14.9 - An if (expression) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
  • MISRA C++:2008, 6-3-1 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
  • MISRA C++:2008, 6-4-1 - An if (condition) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
  • MISRA C:2012, 15.6 - The body of an iteration-statement or a selection-statement shall be a compound-statement
  • CERT, EXP19-C. - Use braces for the body of an if, for, or while statement
  • CERT, EXP52-J. - Use braces for the body of an if, for, or while statement

Call to method __construct from undeclared class \Pluf_Exception
Open

    throw new Pluf_Exception(sprintf(__('Part with the same name exist (name: %s'), $name));
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Call to method error from undeclared class \Pluf_Log
Open

        Pluf_Log::error(
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Reference to instance property REQUEST from undeclared class \Pluf_HTTP_Request
Open

    $count = array_key_exists('_px_c', $request->REQUEST) ? intval($request->REQUEST['_px_c']) : 30;
Severity: Minor
Found in src/ELearn/Shortcuts.php by phan

Call to method gen from undeclared class \Pluf_SQL
Open

            'filter' => $q->gen()
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Call to method __construct from undeclared class \Pluf_SQL
Open

    $q = new Pluf_SQL('name=%s', array(
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Call to method gen from undeclared class \Pluf_SQL
Open

        'filter' => $q->gen()
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Call to undeclared function \__() (Did you mean _())
Open

    throw new Pluf_Exception(sprintf(__('Part with the same name exist (name: %s'), $name));
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

@throws type of ELearn_Shortcuts_GetPartByNameOr404 has undeclared type \CMS_Exception_ObjectNotFound
Open

function ELearn_Shortcuts_GetPartByNameOr404 ($name)
Severity: Minor
Found in src/ELearn/Shortcuts.php by phan

Call to method __construct from undeclared class \Pluf_SQL
Open

    $q = new Pluf_SQL('name=%s', array(
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Call to method getList from undeclared class \Pluf_Model
Open

    $items = $model->getList(
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Call to undeclared function \__() (Did you mean _())
Open

        throw new Pluf_Exception(__('Part name must not be new, find'));
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

@throws type of ELearn_Shortcuts_CleanName has undeclared type \Pluf_Exception
Open

function ELearn_Shortcuts_CleanName($name)
Severity: Minor
Found in src/ELearn/Shortcuts.php by phan

Parameter $model has undeclared type \Pluf_Model
Open

function ELearn_Shortcuts_FindAll($model, $filter, $sort){
Severity: Minor
Found in src/ELearn/Shortcuts.php by phan

Call to method factory from undeclared class \Pluf
Open

    $items = Pluf::factory('ELearn_Part')->getList(array(
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Call to method __construct from undeclared class \Pluf_SQL
Open

    $q = new Pluf_SQL('title=%s', array(
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Call to method __construct from undeclared class \Pluf_Exception
Open

        throw new Pluf_Exception(__('Part name must not be new, find'));
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Call to method __construct from undeclared class \Pluf_Exception_DoesNotExist
Open

    throw new Pluf_Exception_DoesNotExist("Part not found (Part name:" . $name . ")");
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Call to undeclared method \ELearn_Topic::getList
Open

    $item = $item->getList(array(
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Call to method gen from undeclared class \Pluf_SQL
Open

        'filter' => $q->gen()
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Call to undeclared method \ELearn_Part::getList
Open

    $item = $item->getList(
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

Call to method count on non-class type null
Open

    if ($item->count() > 1) {
Severity: Critical
Found in src/ELearn/Shortcuts.php by phan

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

    $q = new Pluf_SQL('name=%s', array(
Severity: Minor
Found in src/ELearn/Shortcuts.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

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

    $q = new Pluf_SQL('name=%s', array(
Severity: Minor
Found in src/ELearn/Shortcuts.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

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

    $q = new Pluf_SQL('title=%s', array(
Severity: Minor
Found in src/ELearn/Shortcuts.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 0 spaces before opening parenthesis; 1 found
Open

function ELearn_Shortcuts_GetPartByNameOr404 ($name)
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Expected "function abc(...)"; found "function abc (...)"
Open

function ELearn_Shortcuts_GetPartByNameOr404 ($name)
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Only one argument is allowed per line in a multi-line function call
Open

                'more than one Part exist with the name $s', $name));
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Only one argument is allowed per line in a multi-line function call
Open

                'more than one Part exist with the name $s', $name));
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Inline control structures are not allowed
Open

    if ($count > 30)
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Line exceeds 120 characters; contains 136 characters
Open

 * بررسی می‌کند که آیا محتویی هم نام با نام در نظر گرفته شده در ملک وجود دارد
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Line exceeds 120 characters; contains 126 characters
Open

 * نام یک محتوی باید در یک ملک به صورت انحصاری تعیین شود. بنابر این روال
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

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

                'more than one Part exist with the name $s', $name));
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Whitespace found at end of line
Open

 * @param string $name            
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Multi-line function call not indented correctly; expected 4 spaces but found 8
Open

        ));
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Closing parenthesis of a multi-line function call must be on a line by itself
Open

        ));
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Closing parenthesis of a multi-line function call must be on a line by itself
Open

                'more than one Part exist with the name $s', $name));
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Opening brace should be on a new line
Open

function ELearn_Shortcuts_FindAll($model, $filter, $sort){
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Whitespace found at end of line
Open

 * 
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Expected 1 newline at end of file; 0 found
Open

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

Whitespace found at end of line
Open

 * 
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

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

                'more than one Part exist with the name $s', $name));
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Closing parenthesis of a multi-line function call must be on a line by itself
Open

        ));
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Multi-line function call not indented correctly; expected 4 spaces but found 8
Open

        ));
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

Closing parenthesis of a multi-line function call must be on a line by itself
Open

                'more than one Part exist with the name $s', $name));
Severity: Minor
Found in src/ELearn/Shortcuts.php by phpcodesniffer

There are no issues that match your filters.

Category
Status