chamilo/chamilo-lms

View on GitHub
public/main/admin/usergroup_import.php

Summary

Maintainability
A
0 mins
Test Coverage

Missing class import via use statement (line '47', column '22').
Open

    $usergroup = new UserGroupModel();

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 '16', column '22').
Open

    $usergroup = new UserGroupModel();

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 validate_data uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            // 2. Check whether class doesn't exist yet.
            if ($usergroup->usergroup_exists($class['name'])) {
                $class['line'] = $index + 2;
                $class['error'] = get_lang('Class name exists').

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 unused local variables such as '$index'.
Open

    foreach ($classes as $index => $class) {

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

Variable "error_message" is not in valid camel caps format
Open

        $error_message = get_lang('Errors when importing file');

Variable "error_message" is not in valid camel caps format
Open

            $error_message .= '<li>'.$error_class['error'].' ('.get_lang('Line').' '.$error_class['line'].')';

Variable "error_class" is not in valid camel caps format
Open

            $error_message .= '<li>'.$error_class['error'].' ('.get_lang('Line').' '.$error_class['line'].')';

Variable "tool_name" is not in valid camel caps format
Open

$tool_name = get_lang('Import class list via CSV');

Variable "this_section" is not in valid camel caps format
Open

$this_section = SECTION_PLATFORM_ADMIN;

Variable "error_message" is not in valid camel caps format
Open

        $error_message .= '<ul>';

Variable "error_class" is not in valid camel caps format
Open

        foreach ($errors as $index => $error_class) {

Variable "number_of_added_classes" is not in valid camel caps format
Open

        $number_of_added_classes = save_data($classes);

Variable "error_message" is not in valid camel caps format
Open

            $error_message .= '</li>';

Variable "tool_name" is not in valid camel caps format
Open

Display::display_header($tool_name);

Missing parameter name
Open

 * @param $classes

Variable "error_message" is not in valid camel caps format
Open

        $error_message .= get_lang('Error');

Variable "error_message" is not in valid camel caps format
Open

        Display::addFlash(Display::return_message($error_message, 'error', false));

Variable "error_class" is not in valid camel caps format
Open

            $error_message .= '<li>'.$error_class['error'].' ('.get_lang('Line').' '.$error_class['line'].')';

Consider putting global function "save_data" in a static class
Open

function save_data($classes)

Variable "error_message" is not in valid camel caps format
Open

        $error_message .= '</ul>';

Consider putting global function "validate_data" in a static class
Open

function validate_data($classes)

Variable "number_of_added_classes" is not in valid camel caps format
Open

        Display::addFlash(Display::return_message($number_of_added_classes.' '.get_lang('Added'), 'normal'));

There are no issues that match your filters.

Category
Status