chamilo/chamilo-lms

View on GitHub
public/main/search/search_suggestions.php

Summary

Maintainability
A
0 mins
Test Coverage

The function get_suggestions_from_search_engine() has an NPath complexity of 348. The configured NPath complexity threshold is 200.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

NPathComplexity

Since: 0.1

The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

Example

class Foo {
    function bar() {
        // lots of complicated code
    }
}

Source https://phpmd.org/rules/codesize.html#npathcomplexity

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

            foreach ($item_tool_id as $ri => $item_ref_id) {

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 '$id'.
Open

                    foreach ($field_val as $id => $val) {

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

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

                    } else {
                        //no identical field id, continue as usual
                        $c = count($output);
                        if (0 == $c) {
                            $output[] = $row2['value'].' - ';

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

                        } else {
                            foreach ($output as $i => $out) {
                                //use the latest combination of fields
                                $output[$i] .= $row2['value'].' - ';
                            }

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

    $sql = "SELECT * FROM $table_sfv where value LIKE '%$q%'".$sql_add."

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

                        $current_field_val .= $val.' - ';

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

                $field_val = [];

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

                    $field_val[$row2['field_id']] = $row2['value'];

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

                    if (!in_array($s, $more_sugg)) {

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

                        $more_sugg[] = $s;

Missing function doc comment
Open

function get_suggestions_from_search_engine($q)

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

        $sql_add = " AND course_code = '".$cid."' ";

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

    $more_sugg = [];

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

                    $current_field_val = '';

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

    $sql = "SELECT * FROM $table_sfv where value LIKE '%$q%'".$sql_add."

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

    while ($row = Database::fetch_array($sql_result)) {

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

            foreach ($item_tool_id as $ri => $item_ref_id) {

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

                            $output[($c + $i)] = $current_field_val;

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

    $sql_add = '';

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

        foreach ($course_id as $ti => $item_tool_id) {

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

            foreach ($item_tool_id as $ri => $item_ref_id) {

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

function get_suggestions_from_search_engine($q)

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

                $field_id = 0;

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

    $sql_result = Database::query($sql);

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

                        $field_id = $row2['field_id'];

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

    foreach ($data as $cc => $course_id) {

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

                    foreach ($field_val as $id => $val) {

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

        foreach ($course_id as $ti => $item_tool_id) {

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

                    if ($field_id == $row2['field_id']) {

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

    $table_sfv = Database::get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);

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

                $sql2 = "SELECT * FROM $table_sfv

The variable $sql_add is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $more_sugg is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $sql_add is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $field_id is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $field_val is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $field_val is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $table_sfv is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $table_sfv is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $sql_add is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $field_id is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $sql_result is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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_id is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $current_field_val is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $more_sugg is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $item_ref_id is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $current_field_val is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $item_tool_id is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $field_val is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $field_id is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $sql_result is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $item_tool_id is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $more_sugg is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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_id is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $table_sfv is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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 $current_field_val is not named in camelCase.
Open

function get_suggestions_from_search_engine($q)
{
    global $charset;

    $json = [];

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