chamilo/chamilo-lms

View on GitHub
public/main/gradebook/lib/be/learnpathlink.class.php

Summary

Maintainability
A
0 mins
Test Coverage

Avoid assigning values to variables in if clauses and the like (line '102', column '17').
Open

    public function calc_score($studentId = null, $type = null)
    {
        $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
        $session_id = $this->get_session_id();
        if (empty($session_id)) {

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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

        } else {
            // all students -> get average
            $students = []; // user list, needed to make sure we only
            // take first attempts into account
            $rescount = 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 calc_score uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                switch ($type) {
                    case 'best':
                        return [$bestResult, 100];
                        break;

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

            } else {
                return null;
            }

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

        } else {
            $url .= '&action=build&lp_id='.$this->get_ref_id();
        }

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

class LearnpathLink extends AbstractLink
{
    private $learnpath_table;
    private $learnpath_data;

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

The property $learnpath_data is not named in camelCase.
Open

class LearnpathLink extends AbstractLink
{
    private $learnpath_table;
    private $learnpath_data;

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

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

        $session_id = $this->get_session_id();

Method name "LearnpathLink::has_results" is not in camel caps format
Open

    public function has_results()

Method name "LearnpathLink::calc_score" is not in camel caps format
Open

    public function calc_score($studentId = null, $type = null)

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

        $session_id = $this->get_session_id();

Method name "LearnpathLink::needs_name_and_description" is not in camel caps format
Open

    public function needs_name_and_description()

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

        return $this->learnpath_table;

Method name "LearnpathLink::get_type_name" is not in camel caps format
Open

    public function get_type_name()

Missing function doc comment
Open

    public function needs_results()

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

        $sql = "SELECT * FROM $tbl_stats

Method name "LearnpathLink::get_name" is not in camel caps format
Open

    public function get_name()

Method name "LearnpathLink::is_allowed_to_change_name" is not in camel caps format
Open

    public function is_allowed_to_change_name()

Missing function doc comment
Open

    public function get_icon_name()

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

        $this->learnpath_table = Database::get_course_table(TABLE_LP_MAIN);

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

        return $this->learnpath_data;

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

        if (empty($session_id)) {

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

                    session_id = $session_id ";

Missing function doc comment
Open

    public function needs_max()

Missing function doc comment
Open

    public function is_allowed_to_change_name()

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

            $this->learnpath_data = Database::fetch_array($result);

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

        if (!isset($this->learnpath_data)) {

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

        $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);

Method name "LearnpathLink::needs_results" is not in camel caps format
Open

    public function needs_results()

Method name "LearnpathLink::get_learnpath_table" is not in camel caps format
Open

    private function get_learnpath_table()

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

        $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);

Missing parameter name
Open

     * @param $studentId student id (default: all students who have results - then the average is returned)

Method name "LearnpathLink::get_all_links" is not in camel caps format
Open

    public function get_all_links()

Missing parameter name
Open

     * @param $type The type of score we want to get: best|average|ranking

Missing function doc comment
Open

    public function needs_name_and_description()

Method name "LearnpathLink::needs_max" is not in camel caps format
Open

    public function needs_max()

Method name "LearnpathLink::get_icon_name" is not in camel caps format
Open

    public function get_icon_name()

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

        $sql = "SELECT count(id) AS number FROM $tbl_stats

Multi-line function call not indented correctly; expected 12 spaces but found 16
Open

                $session_id

Missing function doc comment
Open

    public function get_type_name()

Method name "LearnpathLink::get_link" is not in camel caps format
Open

    public function get_link()

Method name "LearnpathLink::is_valid_link" is not in camel caps format
Open

    public function is_valid_link()

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

                $session_id

Method name "LearnpathLink::get_description" is not in camel caps format
Open

    public function get_description()

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

            $session_id = api_get_session_id();

Method name "LearnpathLink::get_learnpath_data" is not in camel caps format
Open

    private function get_learnpath_data()

Multi-line function call not indented correctly; expected 12 spaces but found 16
Open

                $session_id

The variable $session_id is not named in camelCase.
Open

    public function get_link()
    {
        $session_id = $this->get_session_id();
        $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq_params(
            $this->getCourseId(),

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

    public function get_link()
    {
        $session_id = $this->get_session_id();
        $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq_params(
            $this->getCourseId(),

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

    public function has_results()
    {
        $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
        $sql = "SELECT count(id) AS number FROM $tbl_stats
                WHERE lp_id = ".$this->get_ref_id();

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

    public function calc_score($studentId = null, $type = null)
    {
        $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
        $session_id = $this->get_session_id();
        if (empty($session_id)) {

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

    public function calc_score($studentId = null, $type = null)
    {
        $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
        $session_id = $this->get_session_id();
        if (empty($session_id)) {

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

    public function calc_score($studentId = null, $type = null)
    {
        $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
        $session_id = $this->get_session_id();
        if (empty($session_id)) {

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

    public function calc_score($studentId = null, $type = null)
    {
        $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
        $session_id = $this->get_session_id();
        if (empty($session_id)) {

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

    public function calc_score($studentId = null, $type = null)
    {
        $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
        $session_id = $this->get_session_id();
        if (empty($session_id)) {

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

    public function has_results()
    {
        $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
        $sql = "SELECT count(id) AS number FROM $tbl_stats
                WHERE lp_id = ".$this->get_ref_id();

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

    public function calc_score($studentId = null, $type = null)
    {
        $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
        $session_id = $this->get_session_id();
        if (empty($session_id)) {

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

    public function calc_score($studentId = null, $type = null)
    {
        $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
        $session_id = $this->get_session_id();
        if (empty($session_id)) {

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

The method needs_name_and_description is not named in camelCase.
Open

    public function needs_name_and_description()
    {
        return false;
    }

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

The method get_description is not named in camelCase.
Open

    public function get_description()
    {
        $data = $this->get_learnpath_data();

        return $data['description'];

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

The method is_allowed_to_change_name is not named in camelCase.
Open

    public function is_allowed_to_change_name()
    {
        return false;
    }

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

The method get_name is not named in camelCase.
Open

    public function get_name()
    {
        $data = $this->get_learnpath_data();

        return $data['title'];

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

The method is_valid_link is not named in camelCase.
Open

    public function is_valid_link()
    {
        $sql = 'SELECT count(iid) FROM '.$this->get_learnpath_table().'
                WHERE iid = '.$this->get_ref_id().' ';
        $result = Database::query($sql);

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

The method get_learnpath_table is not named in camelCase.
Open

    private function get_learnpath_table()
    {
        $this->learnpath_table = Database::get_course_table(TABLE_LP_MAIN);

        return $this->learnpath_table;

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

The method get_all_links is not named in camelCase.
Open

    public function get_all_links()
    {
        if (empty($this->getCourseId())) {
            return [];
        }

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

The method needs_results is not named in camelCase.
Open

    public function needs_results()
    {
        return false;
    }

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

The method get_learnpath_data is not named in camelCase.
Open

    private function get_learnpath_data()
    {
        if (!isset($this->learnpath_data)) {
            $sql = 'SELECT * FROM '.$this->get_learnpath_table().'
                    WHERE iid = '.$this->get_ref_id().' ';

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

The method get_type_name is not named in camelCase.
Open

    public function get_type_name()
    {
        return get_lang('Learning paths');
    }

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

The method needs_max is not named in camelCase.
Open

    public function needs_max()
    {
        return false;
    }

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

The method get_icon_name is not named in camelCase.
Open

    public function get_icon_name()
    {
        return 'learnpath';
    }

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

The method get_link is not named in camelCase.
Open

    public function get_link()
    {
        $session_id = $this->get_session_id();
        $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq_params(
            $this->getCourseId(),

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

The method has_results is not named in camelCase.
Open

    public function has_results()
    {
        $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
        $sql = "SELECT count(id) AS number FROM $tbl_stats
                WHERE lp_id = ".$this->get_ref_id();

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