chamilo/chamilo-lms

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

Summary

Maintainability
A
0 mins
Test Coverage

The method validate_courses_data uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                // 2.2 Check whether course code has been occupied.
                $courseInfo = api_get_course_info($course['Code']);
                if (!empty($courseInfo)) {
                    $course['error'] = get_lang('This code exists');
Severity: Minor
Found in public/main/admin/course_import.php by phpmd

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

The method validate_courses_data uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $course['error'] = get_lang('No course category was provided');
            $errors[] = $course;
        }
Severity: Minor
Found in public/main/admin/course_import.php by phpmd

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

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

$defined_auth_sources[] = PLATFORM_AUTH_SOURCE;

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

        $error_message .= '<li>'.get_lang('Line').' '.$error_course['line'].': <strong>'.$error_course['error'].'</strong>: ';

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

function parse_csv_courses_data($file)

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

    $defined_auth_sources = array_merge($defined_auth_sources, array_keys($extAuthSource));

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

        $ext_import_file = substr($_FILES['import_file']['name'], strrpos($_FILES['import_file']['name'], '.') + 1);

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

    $error_message = '<ul>';

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

$tool_name = get_lang('Import courses list').' CSV';

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

        $error_message .= get_lang('Course').': '.$error_course['Title'].' ('.$error_course['Code'].')';

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

        foreach ($mandatory_fields as $field) {

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

        if (!in_array($ext_import_file, $allowed_file_mimetype)) {

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

    $error_message .= '</ul>';

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

function getTeacherListInArray($teachers)

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

        $error_message = get_lang('The file upload has failed.');

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

function validate_courses_data($courses)

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

Display::display_header($tool_name);

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

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

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

        $mandatory_fields = ['Code', 'Title', 'CourseCategory'];

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

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

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

        $error_message .= get_lang('Course').': '.$error_course['Title'].' ('.$error_course['Code'].')';

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

$form->addHeader($tool_name);

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

        $error_message .= '</li>';

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

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

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

    $defined_auth_sources = array_merge($defined_auth_sources, array_keys($extAuthSource));

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

        $error_message .= '<li>'.get_lang('Line').' '.$error_course['line'].': <strong>'.$error_course['error'].'</strong>: ';

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

        $error_message .= '<li>'.get_lang('Line').' '.$error_course['line'].': <strong>'.$error_course['error'].'</strong>: ';

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

        $course_language = $course['Language'];

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

        $params['course_language'] = $course_language;

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

        $allowed_file_mimetype = ['csv'];

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

        $error_message .= get_lang('Course').': '.$error_course['Title'].' ('.$error_course['Code'].')';

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

function save_courses_data($courses)

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

$this_section = SECTION_PLATFORM_ADMIN;

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

        if (!in_array($ext_import_file, $allowed_file_mimetype)) {

The variable $course_language is not named in camelCase.
Open

function save_courses_data($courses)
{
    $msg = '';
    foreach ($courses as $course) {
        $course_language = $course['Language'];
Severity: Minor
Found in public/main/admin/course_import.php by phpmd

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $mandatory_fields is not named in camelCase.
Open

function validate_courses_data($courses)
{
    $errors = [];
    $coursecodes = [];
    foreach ($courses as $index => $course) {
Severity: Minor
Found in public/main/admin/course_import.php by phpmd

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $course_language is not named in camelCase.
Open

function save_courses_data($courses)
{
    $msg = '';
    foreach ($courses as $course) {
        $course_language = $course['Language'];
Severity: Minor
Found in public/main/admin/course_import.php by phpmd

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $mandatory_fields is not named in camelCase.
Open

function validate_courses_data($courses)
{
    $errors = [];
    $coursecodes = [];
    foreach ($courses as $index => $course) {
Severity: Minor
Found in public/main/admin/course_import.php by phpmd

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

There are no issues that match your filters.

Category
Status