chamilo/chamilo-lms

View on GitHub
public/main/exercise/export/exercise_import.inc.php

Summary

Maintainability
A
0 mins
Test Coverage

The function parseQti2() has an NPath complexity of 2711. The configured NPath complexity threshold is 200.
Open

function parseQti2($xmlData)
{
    global $exerciseInfo;
    global $questionTempDir;
    global $resourcesLinks;

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

The function import_exercise() has an NPath complexity of 1774752. The configured NPath complexity threshold is 200.
Open

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

Missing class import via use statement (line '80', column '21').
Open

    $exercise = new Exercise();

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 '124', column '36').
Open

                        $cat = new TestCategory();

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 '146', column '27').
Open

            $answer = new Answer($last_question_id);

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 '105', column '29').
Open

            $question = new Ims2Question();

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

                } else {
                    $currentMatchSet++;
                }

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

                    } else {
                        $exerciseInfo['question'][$currentQuestionIdent]['correct_answers'][] = $nodeValue;
                    }

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

                    } else {
                        $answer->new_correct[$i] = 0;
                    }

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

                } else {
                    if (!isset($exerciseInfo['question'][$currentQuestionIdent]['wrong_answers'])) {
                        $exerciseInfo['question'][$currentQuestionIdent]['wrong_answers'] = [];
                    }

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

        } else {
            $isManifest = isQtiManifest($data);
            if ($isManifest) {
                $resourcesLinks = qtiProcessManifest($data);
            }

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

                    } else {
                        $i = $j;
                        $j++;
                        $matchAnswerIds[$key] = $j;
                    }

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

                } else {
                    $exerciseInfo['question'][$currentQuestionIdent]['answer'][$currentAnswerId]['value'] .= $simpleChoiceValue;
                }

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

                    } else {
                        $exerciseInfo['question'][$currentQuestionIdent]['statement'] = $currentQuestionItemBody;
                    }

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

                } else {
                    $exerciseInfo['question'][$currentQuestionIdent]['answer'][$currentAnswerId]['feedback'] .= trim(
                        $node->nodeValue
                    );
                }

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

                    } else {
                        $question->category = $categoryId;
                    }

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

                } else {
                    if (FREE_ANSWER == $exerciseInfo['question'][$currentQuestionIdent]['type']) {
                        $currentQuestionItemBody = trim($currentQuestionItemBody);

                        if (!empty($currentQuestionItemBody)) {

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

    global $questionTempDir;

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

    $filePath = null;

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

    if (!empty($last_exercise_id)) {

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

                        $answer->new_correct[$i] = 0;

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

                        $answer->new_weighting[$i] = $question_array['weighting'][$key];

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

        foreach ($exerciseInfo['question'] as $question_array) {

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

                $totalCorrectWeight = $question_array['weighting'][0];

Doc comment for parameter $filePath does not match actual variable name $data
Open

 * @param string $filePath The absolute filepath

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

            $question->updateTitle(formatText(strip_tags($question_array['title'])));

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

    global $record_item_body;

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

                    if (isset($question_array['weighting'][$key])) {

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

function isQtiManifest($data)

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

function qti_parse_file($data)

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

    $record_item_body = false;

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

            $question->type = $question_array['type'];

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

                $category = formatText(strip_tags($question_array['category']));

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

            $answer->new_nbrAnswers = count($answerList);

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

function formatText($text)

Doc comment for parameter $filePath does not match actual variable name $data
Open

 * @param string $filePath The absolute filepath

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

            if (isset($question_array['category'])) {

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

            $answer = new Answer($last_question_id);

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

            $answerList = $question_array['answer'];

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

                        $answer->new_correct[$i] = 1;

Doc comment for parameter $filePath does not match actual variable name $data
Open

 * @param string $filePath The absolute filepath

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

function qtiProcessManifest($data)

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

    $last_exercise_id = $exercise->getId();

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

                        $totalCorrectWeight += $answer->new_weighting[$i];

Doc comment for parameter $exercisePath does not match actual variable name $data
Open

 * @param string $exercisePath

Superfluous parameter comment
Open

 * @param string $questionFile

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

                    $answer_id = $node->getAttribute('mapKey');

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

            if (!in_array($question_array['type'], [UNIQUE_ANSWER, MULTIPLE_ANSWER, FREE_ANSWER])) {

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

            if (!empty($question_array['description'])) {

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

                    $answer->new_answer[$i] = isset($answers['value']) ? formatText($answers['value']) : '';

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

                    $answer->new_position[$i] = $i;

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

                    if ($answer->new_correct[$i]) {

Superfluous parameter comment
Open

 * @param string $file

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

function isQtiQuestionBank($data)

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

            $last_question_id = $question->getId();

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

                    $answer->new_weighting[$i] = 0;

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

                    if (in_array($key, $question_array['correct_answers'])) {

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

        return $last_exercise_id;

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

function parseQti2($xmlData)

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

                        $currentQuestionItemBody .= '['.$correct_answer_value.']';

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

function import_exercise($file)

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

                $description .= $question_array['description'];

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

                    $answer->new_comment[$i] = isset($answers['feedback']) ? formatText($answers['feedback']) : null;

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

                    $exerciseInfo['question'][$currentQuestionIdent]['weighting'][$answer_id] = $node->getAttribute(

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

                        $correct_answer_value = $exerciseInfo['question'][$currentQuestionIdent]['correct_answers'][$currentAnswerId];

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

                        $answer->new_weighting[$i] = $question_array['weighting'][$key];

The variable $question_array is not named in camelCase.
Open

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function qti_parse_file($data)
{
    global $record_item_body;
    global $questionTempDir;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function parseQti2($xmlData)
{
    global $exerciseInfo;
    global $questionTempDir;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function parseQti2($xmlData)
{
    global $exerciseInfo;
    global $questionTempDir;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function parseQti2($xmlData)
{
    global $exerciseInfo;
    global $questionTempDir;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function qti_parse_file($data)
{
    global $record_item_body;
    global $questionTempDir;

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

function parseQti2($xmlData)
{
    global $exerciseInfo;
    global $questionTempDir;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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

function import_exercise($file)
{
    global $exerciseInfo;
    global $resourcesLinks;

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