chamilo/chamilo-lms

View on GitHub
public/main/exercise/fill_blanks.class.php

Summary

Maintainability
A
0 mins
Test Coverage

The method getHtmlAnswer() has an NPath complexity of 448. The configured NPath complexity threshold is 200.
Open

    public static function getHtmlAnswer(
        $answer,
        $correct,
        $right,
        $feedbackType,

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 method getAnswerInfo() has an NPath complexity of 216. The configured NPath complexity threshold is 200.
Open

    public static function getAnswerInfo($userAnswer = '', $isStudentAnswer = false)
    {
        $listAnswerResults = [];
        $listAnswerResults['text'] = '';
        $listAnswerResults['words_count'] = 0;

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 using undefined variables such as '$listResult' which will lead to PHP notices.
Open

        if (count($listResult) < 2) {

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Avoid using undefined variables such as '$listResult' which will lead to PHP notices.
Open

            $listDoubleColon[] = $listResult[1];

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Avoid using undefined variables such as '$listResult' which will lead to PHP notices.
Open

            $listDoubleColon[] = $listResult[2];

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Avoid using undefined variables such as '$listResult' which will lead to PHP notices.
Open

        api_preg_match('/(.*)::(.*)$/s', $userAnswer, $listResult);

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Missing class import via use statement (line '516', column '26').
Open

        $objAnswer = new Answer($this->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 '39', column '33').
Open

            $objectAnswer = new Answer($this->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

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

                            } else {
                                $userResult[$data['user_id']][$bracketNumber] = -1; // wrong answer
                            }

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

        } else {
            return $inChar;
        }

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

                    } else {
                        // we take the last attempt, even if the student answer the question before
                        $userResult[$data['user_id']][$bracketNumber] = -2; // not answered
                    }

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

                } else {
                    // student didn't answer this bracket
                    if ($useLastAnsweredAttempt) {
                        // if we take into account the last answered attempt
                        if (!isset($userResult[$data['user_id']][$bracketNumber])) {

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

            } else {
                $listStudentAnswerInfo['student_answer'][$i] = self::getHtmlWrongAnswer(
                    $listStudentAnswerInfo['student_answer'][$i],
                    $listStudentAnswerInfo['words'][$i],
                    $feedbackType,

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

        } else {
            $listDoubleColon[] = $listResult[1];
            $listDoubleColon[] = $listResult[2];
        }

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

        } else {
            $listWeightings = explode(',', $listDetails[0]);
            $listSizeOfInput = explode(',', $listDetails[1]);
            $blankSeparatorNumber = $listDetails[2];
        }

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

        } else {
            if (1 == $this->isContent) {
                $form->setDefaults($defaults);
            }
        }

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 parameters such as '$answer'.
Open

        $answer,

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

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

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

            $blanks

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 parameters such as '$key'.
Open

                function (&$value, $key, $tabBlankChar) {

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

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

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

            foreach ($answer['student_answer'] as $bracketNumber => $studentAnswer) {

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 using count() function in for loops.
Open

        for ($i = 0; $i < count($listStudentAnswerInfo['student_answer']); $i++) {
            if (1 == $listStudentAnswerInfo['student_score'][$i]) {
                $listStudentAnswerInfo['student_answer'][$i] = self::getHtmlRightAnswer(
                    $listStudentAnswerInfo['student_answer'][$i],
                    $listStudentAnswerInfo['words'][$i],

CountInLoopExpression

Since: 2.7.0

Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.

Example

class Foo {

  public function bar()
  {
    $array = array();

    for ($i = 0; count($array); $i++) {
      // ...
    }
  }
}

Source https://phpmd.org/rules/design.html#countinloopexpression

Avoid using count() function in for loops.
Open

                for ($i = 1; $i < count($listPossibleAnswers); $i++) {
                    $correctAnswerHtml .= $listPossibleAnswers[$i];
                    if ($i != count($listPossibleAnswers) - 1) {
                        $correctAnswerHtml .= ' | ';
                    }

CountInLoopExpression

Since: 2.7.0

Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.

Example

class Foo {

  public function bar()
  {
    $array = array();

    for ($i = 0; count($array); $i++) {
      // ...
    }
  }
}

Source https://phpmd.org/rules/design.html#countinloopexpression

Avoid using count() function in for loops.
Open

        for ($i = 0; $i < count($listStudentAnswerInfo['common_words']); $i++) {
            if (RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK == $resultsDisabled) {
                if (empty($listStudentAnswerInfo['student_answer'][$i])) {
                    continue;
                }

CountInLoopExpression

Since: 2.7.0

Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.

Example

class Foo {

  public function bar()
  {
    $array = array();

    for ($i = 0; count($array); $i++) {
      // ...
    }
  }
}

Source https://phpmd.org/rules/design.html#countinloopexpression

Avoid using count() function in for loops.
Open

            for ($i = 0; $i < count($listWeightings); $i++) {
                $listSizeOfInput[] = 200;
            }

CountInLoopExpression

Since: 2.7.0

Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.

Example

class Foo {

  public function bar()
  {
    $array = array();

    for ($i = 0; count($array); $i++) {
      // ...
    }
  }
}

Source https://phpmd.org/rules/design.html#countinloopexpression

Avoid using count() function in for loops.
Open

                    for ($i = 0; $i < count($tabBlankChar); $i++) {
                        $trimChars .= $tabBlankChar[$i];
                    }

CountInLoopExpression

Since: 2.7.0

Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.

Example

class Foo {

  public function bar()
  {
    $array = array();

    for ($i = 0; count($array); $i++) {
      // ...
    }
  }
}

Source https://phpmd.org/rules/design.html#countinloopexpression

Avoid using count() function in for loops.
Open

            for ($i = 0; $i < count($listAnswerResults['words']); $i++) {
                $listBrackets[] = $listAnswerResults['words_with_bracket'][$i];
                $listWords[] = $listAnswerResults['words'][$i];
                if ($i + 1 < count($listAnswerResults['words'])) {
                    // should always be

CountInLoopExpression

Since: 2.7.0

Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.

Example

class Foo {

  public function bar()
  {
    $array = array();

    for ($i = 0; count($array); $i++) {
      // ...
    }
  }
}

Source https://phpmd.org/rules/design.html#countinloopexpression

Avoid using count() function in for loops.
Open

        for ($i = 0; $i < count($listWithStudentAnswer['common_words']) - 1; $i++) {
            $answerValue = null;
            if (isset($listWithStudentAnswer['student_answer'][$i])) {
                $answerValue = $listWithStudentAnswer['student_answer'][$i];
            }

CountInLoopExpression

Since: 2.7.0

Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.

Example

class Foo {

  public function bar()
  {
    $array = array();

    for ($i = 0; count($array); $i++) {
      // ...
    }
  }
}

Source https://phpmd.org/rules/design.html#countinloopexpression

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

        $is_multiple = $form->getSubmitValue('multiple_answer');

Missing parameter name
Open

     * @param $studentsIdList

Expected 9 spaces after parameter type; 1 found
Open

     * @param string $startDate

Missing function doc comment
Open

    public function createAnswersForm($form)

Missing function doc comment
Open

    public function processAnswersCreation($form, $exercise)

Expected 9 spaces after parameter type; 1 found
Open

     * @param string $endDate

Expected 12 spaces after parameter type; 1 found
Open

     * @param int $testId

Expected 11 spaces after parameter type; 3 found
Open

     * @param bool   $useLastAnsweredAttempt

Expected 12 spaces after parameter type; 1 found
Open

     * @param int $questionId

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

        $answer .= '@'.$is_multiple;

Missing function doc comment
Open

    public function return_header(Exercise $exercise, $counter = null, $score = [])

Method name "FillBlanks::return_header" is not in camel caps format
Open

    public function return_header(Exercise $exercise, $counter = null, $score = [])

The variable $is_multiple is not named in camelCase.
Open

    public function processAnswersCreation($form, $exercise)
    {
        $answer = $form->getSubmitValue('answer');
        // Due the ckeditor transform the elements to their HTML value

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

    public function processAnswersCreation($form, $exercise)
    {
        $answer = $form->getSubmitValue('answer');
        // Due the ckeditor transform the elements to their HTML value

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

    public function return_header(Exercise $exercise, $counter = null, $score = [])
    {
        $header = parent::return_header($exercise, $counter, $score);
        $header .= '<table class="'.$this->questionTableClass.'">
            <tr>

CamelCaseMethodName

Since: 0.2

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

Example

class ClassName {
    public function get_name() {
    }
}

Source

There are no issues that match your filters.

Category
Status