chamilo/chamilo-lms

View on GitHub
public/main/skills/skills_import.php

Summary

Maintainability
A
0 mins
Test Coverage

Missing class import via use statement (line '81', column '27').
Open

            $oskill = new SkillModel();
Severity: Minor
Found in public/main/skills/skills_import.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

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

            } else {
                $skill['parent_id'] = 1;
            }
Severity: Minor
Found in public/main/skills/skills_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

Avoid unused local variables such as '$index'.
Open

    foreach ($skills as $index => $skill) {
Severity: Minor
Found in public/main/skills/skills_import.php by phpmd

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

Avoid unused local variables such as '$index'.
Open

        foreach ($skills as $index => $skill) {
Severity: Minor
Found in public/main/skills/skills_import.php by phpmd

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 "allowed_file_mimetype" is not in valid camel caps format
Open

    $allowed_file_mimetype = ['csv'];

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

        foreach ($mandatory_fields as $field) {

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

            $skill_id = $oskill->add($skill);

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

    $skills_to_insert = $skill_id_error = [];

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

        $error_message = get_lang('You must import a file corresponding to the selected format');

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 "my_skill" is not in valid camel caps format
Open

                $skills_to_insert[] = $my_skill;

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

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

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

            if (isset($my_skill['title']) && !in_array($my_skill['title'], $skill_id_error)) {

Missing parameter name
Open

 * @param   array   List of users

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

            $saved_id = $skill['id'];

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

function parse_csv_data($file)

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

            if (isset($my_skill['title']) && !in_array($my_skill['title'], $skill_id_error)) {

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

$error_message = '';

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

            $skill_id_error[] = $my_errors['SkillName'];

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

function validate_data($skills)

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

function save_data($skills)

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

            $parents[$saved_id] = $skill_id;

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

$extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC', true);

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

        foreach ($skills as $my_skill) {

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

        save_data($skills_to_insert);

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

    $file_type = $_POST['file_type'];

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

        if (0 === strcmp($file_type, 'csv') && $ext_import_file == $allowed_file_mimetype[0]) {

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

        if (0 === strcmp($file_type, 'csv') && $ext_import_file == $allowed_file_mimetype[0]) {

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

            $error_kind_file = true;

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

$this_section = SECTION_PLATFORM_ADMIN;

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

            $skill_id_error[] = $my_errors['SkillName'];

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

            if (isset($my_skill['title']) && !in_array($my_skill['title'], $skill_id_error)) {

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

$tool_name = get_lang('Import skills from a CSV file');

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

    $error_message = '';

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

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

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

            $error_kind_file = false;

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

        $error_kind_file = true;

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

    $skills_to_insert = $skill_id_error = [];

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

                $skills_to_insert[] = $my_skill;

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

        $see_message_import = get_lang('Only skills that were not registered were imported');

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

        $warning_message = '<ul>';

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

    $mandatory_fields = ['id', 'parent_id', 'title'];

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

$user_id_error = [];

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

    $error_kind_file = false;

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

        if (0 === strcmp($file_type, 'csv') && $ext_import_file == $allowed_file_mimetype[0]) {

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

        foreach ($errors as $my_errors) {

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

    if (0 === strcmp($file_type, 'csv')) {

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

        $see_message_import = get_lang('File imported');

Missing parameter name
Open

 * @param $skills

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

            $parents[$saved_id] = $skill_id;

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

            $warning_message .= '<strong>'.$error_skill['SkillName'].'</strong>&nbsp;('.$error_skill['SkillName'].')';

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

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

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

    if ($error_kind_file) {

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

            $warning_message .= '</li>';

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

            $warning_message .= '<strong>'.$error_skill['SkillName'].'</strong>&nbsp;('.$error_skill['SkillName'].')';

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

Display :: display_header($tool_name);

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

            $warning_message .= '<li><b>'.$error_skill['error'].'</b>: ';

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

            $warning_message .= '<strong>'.$error_skill['SkillName'].'</strong>&nbsp;('.$error_skill['SkillName'].')';

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

    echo Display::return_message($see_message_import, 'normal');

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

if (!empty($see_message_import)) {

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

            $warning_message .= '<li><b>'.$error_skill['error'].'</b>: ';

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

        $warning_message .= '</ul>';

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

        $error_message = get_lang('You must import a file corresponding to the selected format');

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

if (!empty($error_message)) {

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

$form->addElement('header', '', $tool_name);

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

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

The variable $skill_id is not named in camelCase.
Open

function save_data($skills)
{
    if (is_array($skills)) {
        $parents = [];
        $urlId = api_get_current_access_url_id();
Severity: Minor
Found in public/main/skills/skills_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_data($skills)
{
    $errors = [];
    // 1. Check if mandatory fields are set.
    $mandatory_fields = ['id', 'parent_id', 'title'];
Severity: Minor
Found in public/main/skills/skills_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_data($skills)
{
    $errors = [];
    // 1. Check if mandatory fields are set.
    $mandatory_fields = ['id', 'parent_id', 'title'];
Severity: Minor
Found in public/main/skills/skills_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 $skill_id is not named in camelCase.
Open

function save_data($skills)
{
    if (is_array($skills)) {
        $parents = [];
        $urlId = api_get_current_access_url_id();
Severity: Minor
Found in public/main/skills/skills_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 $saved_id is not named in camelCase.
Open

function save_data($skills)
{
    if (is_array($skills)) {
        $parents = [];
        $urlId = api_get_current_access_url_id();
Severity: Minor
Found in public/main/skills/skills_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 $saved_id is not named in camelCase.
Open

function save_data($skills)
{
    if (is_array($skills)) {
        $parents = [];
        $urlId = api_get_current_access_url_id();
Severity: Minor
Found in public/main/skills/skills_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