chamilo/chamilo-lms

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

Summary

Maintainability
A
0 mins
Test Coverage

The method createAnswersForm() has an NPath complexity of 6912. The configured NPath complexity threshold is 200.
Open

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 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

Missing class import via use statement (line '192', 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 '45', column '27').
Open

            $answer = 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 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

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

            } else {
                if (1 == $test) {
                    $weighting = 0;
                } else {
                    $weighting = -abs($answer_score);

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

                } else {
                    $weighting = -abs($answer_score);
                }

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

            $nb_answers = 1;

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

        for ($i = 1; $i <= $nb_answers; $i++) {

Missing function doc comment
Open

    public function processAnswersCreation($form, $exercise)

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

        if (!in_array($exercise->results_disabled, [RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER])) {

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

        $nbr_corrects = 0 == $nbr_corrects ? 1 : $nbr_corrects;

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

        $answer_score /= $nbr_corrects;

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

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

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

            $boxes_names[] = 'correct['.$i.']';

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

        $answer_score = trim($form->getSubmitValue('weighting[1]'));

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

        for ($i = 1; $i <= $nb_answers; $i++) {

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

        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

        $questionWeighting = $answer_score;

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

            $answer_number = $form->addElement(

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

        if ($obj_ex->edit_exercise_in_lp ||

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

        if ($obj_ex->edit_exercise_in_lp ||

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

                $nbr_corrects++;

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

        for ($i = 1; $i <= $nb_answers; $i++) {

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

        $form->setConstants(['nb_answers' => $nb_answers]);

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

        $nb_answers = $form->getSubmitValue('nb_answers');

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

        $answer_score = 0 == $nbr_corrects ? 0 : $answer_score;

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

        if ($nb_answers < 1) {

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

        $nbr_corrects = 0;

Missing function doc comment
Open

    public function createAnswersForm($form)

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

                    $weighting = -abs($answer_score);

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

        $nbr_corrects = 0 == $nbr_corrects ? 1 : $nbr_corrects;

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

        $nbr_corrects = 0 == $nbr_corrects ? 1 : $nbr_corrects;

Missing function doc comment
Open

    public function __construct()

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

        $answer_score = 0 == $nbr_corrects ? 0 : $answer_score;

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

        $answer_score = 0 == $nbr_corrects ? 0 : $answer_score;

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

        $obj_ex = Session::read('objExercise');

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

                $nb_answers = $answer->nbrAnswers;

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

            $boxes_names,

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

            (empty($this->exerciseList) && empty($obj_ex->id))

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

        $answer_score /= $nbr_corrects;

Missing function doc comment
Open

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

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

        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;

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

        $boxes_names = [];

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

            $answer_number->freeze();

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

                $weighting = abs($answer_score);

The variable $boxes_names is not named in camelCase.
Open

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function processAnswersCreation($form, $exercise)
    {
        $objAnswer = new Answer($this->id);
        $nb_answers = $form->getSubmitValue('nb_answers');

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

    public function createAnswersForm($form)
    {
        $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
        $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);

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