chamilo/chamilo-lms

View on GitHub
public/main/inc/lib/AnnouncementEmail.php

Summary

Maintainability
A
0 mins
Test Coverage

The method send() has an NPath complexity of 324. The configured NPath complexity threshold is 200.
Open

    public function send($sendToUsersInSession = false, $sendToDrhUsers = false, $senderId = 0, $directMessage = false)
    {
        $senderId = empty($senderId) ? api_get_user_id() : (int) $senderId;
        $subject = $this->subject($directMessage);

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

            } else {
                $userList = GroupManager::get_users($group_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 method subject uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $result = $this->course['title'].' - '.$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 send uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                if (!empty($this->logger)) {
                    $this->logger->addInfo(
                        'Message "'.$subject.'" was already sent. Announcement: #'.$this->announcement->getIid().'.
                        User: #'.$userId

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

        } else {
            $userList = CourseManager::get_user_list_from_course_code(
                $courseCode,
                $this->session_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

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

        $course_id = $this->course['real_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 $session_id is not named in camelCase.
Open

class AnnouncementEmail
{
    public $session_id;
    public $logger;
    protected $course;

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

        $this->session_id = empty($sessionId) ? api_get_session_id() : (int) $sessionId;

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

        $sent_to = $this->announcement->getUsersAndGroupSubscribedToResource();

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

        $groups = $sent_to['groups'] ?? [];

Missing function doc comment
Open

    public function __construct(array $courseInfo, $sessionId, CAnnouncement $announcement, Monolog\Logger $logger = null)

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

                $userList = GroupManager::get_users($group_id);

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

                $this->session_id

Member variable "session_id" is not in valid camel caps format
Open

    public $session_id;

Method name "AnnouncementEmail::all_users" is not in camel caps format
Open

    public function all_users()

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

        if (empty($this->session_id)) {

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

            $group_id = api_get_group_id();

Method name "AnnouncementEmail::sent_to" is not in camel caps format
Open

    public function sent_to()

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

            if (empty($group_id)) {

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

        $users = $sent_to['users'] ?? [];

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

        $course_id = $this->course['real_id'];

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

        $course_param = 'cid='.$this->course['real_id'].'&sid='.$session_id.'&gid='.api_get_group_id();

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

        $session_id = $this->session_id;

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

        $course_param = 'cid='.$this->course['real_id'].'&sid='.$session_id.'&gid='.api_get_group_id();

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

        $result .= '<a href="'.api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.$course_param.'">'.$course_name.'</a><br/>';

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

        $result .= '<a href="'.api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.$course_param.'">'.$course_name.'</a><br/>';

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

        $session_id = $this->session_id;

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

        $course_name = $this->course['title'];

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

            $session_id

The variable $course_name is not named in camelCase.
Open

    public function message($receiverUserId)
    {
        $content = $this->announcement->getContent();
        $session_id = $this->session_id;
        $courseCode = $this->course['code'];

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

    public function message($receiverUserId)
    {
        $content = $this->announcement->getContent();
        $session_id = $this->session_id;
        $courseCode = $this->course['code'];

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

    public function attachment()
    {
        $result = [];
        $table = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
        $id = $this->announcement->getIid();

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

    public function sent_to()
    {
        $sent_to = $this->announcement->getUsersAndGroupSubscribedToResource();
        $users = $sent_to['users'] ?? [];
        $groups = $sent_to['groups'] ?? [];

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 message($receiverUserId)
    {
        $content = $this->announcement->getContent();
        $session_id = $this->session_id;
        $courseCode = $this->course['code'];

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

    public function all_users()
    {
        $courseCode = $this->course['code'];
        if (empty($this->session_id)) {
            $group_id = api_get_group_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 message($receiverUserId)
    {
        $content = $this->announcement->getContent();
        $session_id = $this->session_id;
        $courseCode = $this->course['code'];

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

    public function sent_to()
    {
        $sent_to = $this->announcement->getUsersAndGroupSubscribedToResource();
        $users = $sent_to['users'] ?? [];
        $groups = $sent_to['groups'] ?? [];

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

    public function all_users()
    {
        $courseCode = $this->course['code'];
        if (empty($this->session_id)) {
            $group_id = api_get_group_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 $course_param is not named in camelCase.
Open

    public function message($receiverUserId)
    {
        $content = $this->announcement->getContent();
        $session_id = $this->session_id;
        $courseCode = $this->course['code'];

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

    public function all_users()
    {
        $courseCode = $this->course['code'];
        if (empty($this->session_id)) {
            $group_id = api_get_group_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 message($receiverUserId)
    {
        $content = $this->announcement->getContent();
        $session_id = $this->session_id;
        $courseCode = $this->course['code'];

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

    public function sent_to()
    {
        $sent_to = $this->announcement->getUsersAndGroupSubscribedToResource();
        $users = $sent_to['users'] ?? [];
        $groups = $sent_to['groups'] ?? [];

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

    public function message($receiverUserId)
    {
        $content = $this->announcement->getContent();
        $session_id = $this->session_id;
        $courseCode = $this->course['code'];

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

    public function all_users()
    {
        $courseCode = $this->course['code'];
        if (empty($this->session_id)) {
            $group_id = api_get_group_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 sent_to is not named in camelCase.
Open

    public function sent_to()
    {
        $sent_to = $this->announcement->getUsersAndGroupSubscribedToResource();
        $users = $sent_to['users'] ?? [];
        $groups = $sent_to['groups'] ?? [];

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