chamilo/chamilo-lms

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

Summary

Maintainability
A
0 mins
Test Coverage

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

    public function calc_score($studentId = null, $type = null)
    {
        $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
        $sessionId = $this->get_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 get_name uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            return $attendance_title;
        }

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

            } else {
                $cats[] = [$link->getIid(), $link->getTitle()];
            }

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 {
            // 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 {
                //We sent the 0/attendance_qualify_max instead of null for correct calculations
                return [0, $attendance['attendance_qualify_max']];
            }

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

        $sessionId = $this->get_session_id();

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

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

The property $attendance_table is not named in camelCase.
Open

class AttendanceLink extends AbstractLink
{
    private $attendance_table = null;

    public function __construct()

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

Missing function doc comment
Open

    public function __construct()

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

    public function needs_name_and_description()

Missing function doc comment
Open

    public function needs_max()

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

        $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : '';

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

            return $attendance_title;

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

    public function is_allowed_to_change_name()

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

            return $this->attendance_data['attendance_qualify_title'];

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

    public function get_type_name()

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

        $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);

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

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

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

        if (isset($attendance_qualify_title) && '' != $attendance_qualify_title) {

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

                FROM '.$tbl_attendance_result.'

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

    public function get_name()

Method name "AttendanceLink::get_attendance_table" is not in camel caps format
Open

    private function get_attendance_table()

Missing function doc comment
Open

    public function get_link()

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

    public function get_link()

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

        return $this->attendance_table;

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

        $sql = 'SELECT count(*) AS number FROM '.$tbl_attendance_result."

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

        $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);

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

    public function needs_results()

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

        $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : '';

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

    public function get_all_links(): array

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

    public function has_results()

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

        $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : '';

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

    public function needs_max()

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

    public function get_icon_name()

Method name "AttendanceLink::get_attendance_data" is not in camel caps format
Open

    private function get_attendance_data()

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

        $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : '';

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

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

Missing function doc comment
Open

    public function needs_results()

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

        $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : '';

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

        if (isset($attendance_qualify_title) && '' != $attendance_qualify_title) {

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

            $this->attendance_data = Database::fetch_array($query);

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

        $qb = $repo->getResourcesByCourse(api_get_course_entity($this->course_id), api_get_session_entity($sessionId));

Missing function doc comment
Open

    public function needs_name_and_description()

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

    public function get_description()

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

        return $this->attendance_data;

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

        $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : '';

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

    public function is_valid_link()

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

        $this->attendance_table = Database::get_course_table(TABLE_ATTENDANCE);

The variable $attendance_qualify_title is not named in camelCase.
Open

    public function get_name()
    {
        $this->get_attendance_data();
        $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : '';
        $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : '';

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

    public function calc_score($studentId = null, $type = null)
    {
        $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
        $sessionId = $this->get_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 $attendance_qualify_title is not named in camelCase.
Open

    public function get_name()
    {
        $this->get_attendance_data();
        $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : '';
        $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : '';

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

    public function get_name()
    {
        $this->get_attendance_data();
        $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : '';
        $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : '';

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

    public function get_name()
    {
        $this->get_attendance_data();
        $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : '';
        $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : '';

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

    public function has_results()
    {
        $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
        $sessionId = $this->get_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_attendance_result is not named in camelCase.
Open

    public function calc_score($studentId = null, $type = null)
    {
        $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
        $sessionId = $this->get_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 $attendance_title is not named in camelCase.
Open

    public function get_name()
    {
        $this->get_attendance_data();
        $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : '';
        $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_title'] : '';

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

    public function has_results()
    {
        $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
        $sessionId = $this->get_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 get_icon_name is not named in camelCase.
Open

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

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

    public function get_name()
    {
        $this->get_attendance_data();
        $attendance_title = isset($this->attendance_data['name']) ? $this->attendance_data['name'] : '';
        $attendance_qualify_title = isset($this->attendance_data['attendance_qualify_title']) ? $this->attendance_data['attendance_qualify_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 get_attendance_table is not named in camelCase.
Open

    private function get_attendance_table()
    {
        $this->attendance_table = Database::get_course_table(TABLE_ATTENDANCE);

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

    public function calc_score($studentId = null, $type = null)
    {
        $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
        $sessionId = $this->get_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 has_results is not named in camelCase.
Open

    public function has_results()
    {
        $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
        $sessionId = $this->get_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 get_all_links is not named in camelCase.
Open

    public function get_all_links(): array
    {
        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_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 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_attendance_data is not named in camelCase.
Open

    private function get_attendance_data()
    {
        if (!isset($this->attendance_data)) {
            $sql = 'SELECT * FROM '.$this->get_attendance_table().' att
                    WHERE att.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('Attendance');
    }

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()
    {
        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 get_link is not named in camelCase.
Open

    public function get_link()
    {
        // it was extracts the attendance id
        $sessionId = $this->get_session_id();
        $sql = 'SELECT * FROM '.$this->get_attendance_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

There are no issues that match your filters.

Category
Status