chamilo/chamilo-lms

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

Summary

Maintainability
A
0 mins
Test Coverage

The method Notification::send() calls the typical debug function print_r() which is mostly only used during development.
Open

                    error_log('Updating record : '.print_r($item_to_send, 1));

DevelopmentCodeFragment

Since: 2.3.0

Functions like vardump(), printr() etc. are normally only used during development and therefore such calls in production code are a good indicator that they were just forgotten.

Example

class SuspectCode {

    public function doSomething(array $items)
    {
        foreach ($items as $i => $item) {
            // …

            if ('qafoo' == $item) var_dump($i);

            // …
        }
    }
}

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

The method formatContent() has an NPath complexity of 660. The configured NPath complexity threshold is 200.
Open

    public function formatContent($messageId, $content, $senderInfo, $recipientLanguage = null, $baseUrl = null)
    {
        $newMessageText = $linkToNewMessage = '';
        $showEmail = ('true' === api_get_setting('mail.show_user_email_in_notification'));
        $senderInfoName = '';

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

    public function saveNotification(
        $messageId,
        $type,
        $userList,
        $title,

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 '473', column '36').
Open

            $extraFieldValue = new ExtraFieldValue('user');

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

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

    public function __construct()
    {
        $this->table = Database::get_main_table(TABLE_NOTIFICATION);

        if ($smtpFromEmail = api_get_setting('mail.smtp_from_email')) {

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

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

    public function __construct()
    {
        $this->table = Database::get_main_table(TABLE_NOTIFICATION);

        if ($smtpFromEmail = api_get_setting('mail.smtp_from_email')) {

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

        } else {
            // Default no-reply email
            $this->adminEmail = api_get_setting('mail.noreply_email_address');
            $this->adminName = api_get_setting('platform.site_name');
            $this->titlePrefix = '['.api_get_setting('platform.site_name').'] ';

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

                $topicPage = isset($_REQUEST['topics_page_nr']) ? (int) $_REQUEST['topics_page_nr'] : 0;

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

class Notification extends Model
{
    // mail_notify_message ("At once", "Daily", "No")
    const NOTIFY_MESSAGE_AT_ONCE = 1;
    const NOTIFY_MESSAGE_DAILY = 8;

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

                    $item_to_send['dest_mail'],

Expected 10 spaces after parameter name; 1 found
Open

     * @param string|null $recipientLanguage The language of the recipient for translation.

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

                    Security::filter_terms($item_to_send['title']),

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

                    error_log('Updating record : '.print_r($item_to_send, 1));

Expected 7 spaces after parameter type; 2 found
Open

     * @param array  $senderInfo Information about the sender.

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

                $item_to_send['sent_at'] = api_get_utc_datetime();

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

                        $userSetting = $extra_data[$settingToCheck];

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

                    'dest_user_id' => $user_id,

Missing function doc comment
Open

    public function __construct()

Doc comment for parameter $type does not match actual variable name $messageId
Open

     * @param int    $type                       message type

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

                    $item_to_send['dest_mail'],

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

                    Security::filter_terms($item_to_send['content']),

Expected 17 spaces after parameter name; 1 found
Open

     * @param array  $senderInfo Information about the sender.

Doc comment for parameter $messageId does not match actual variable name $type
Open

     * @param int    $messageId

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

                    $extra_data = UserManager::get_extra_user_data($user_id);

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

                    if (isset($extra_data[$settingToCheck])) {

Expected 22 spaces after parameter name; 1 found
Open

     * @param string $title The original title of the notification.

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

        $avoid_my_self = false;

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

                    $extra_data = UserManager::get_extra_user_data($user_id);

Expected 8 spaces after parameter type; 3 found
Open

     * @param bool   $forceTitleWhenSendingEmail Whether to force the use of the original title.

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

    public $max_content_length = 254;

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

                if ($avoid_my_self) {

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

                    if ($user_id == api_get_user_id()) {

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

                $userInfo = api_get_user_info($user_id);

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

                $this->update($item_to_send);

Expected 6 spaces after parameter type; 1 found
Open

     * @param string $title The original title of the notification.

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

            foreach ($userList as $user_id) {

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

            foreach ($notifications as $item_to_send) {

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

                $avoid_my_self = true;

The variable $user_id is not named in camelCase.
Open

    public function saveNotification(
        $messageId,
        $type,
        $userList,
        $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 $user_id is not named in camelCase.
Open

    public function saveNotification(
        $messageId,
        $type,
        $userList,
        $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 $item_to_send is not named in camelCase.
Open

    public function send($frequency = 8)
    {
        $notifications = $this->find(
            'all',
            ['where' => ['sent_at IS NULL AND send_freq = ?' => $frequency]]

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

    public function saveNotification(
        $messageId,
        $type,
        $userList,
        $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 $user_id is not named in camelCase.
Open

    public function saveNotification(
        $messageId,
        $type,
        $userList,
        $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 $avoid_my_self is not named in camelCase.
Open

    public function saveNotification(
        $messageId,
        $type,
        $userList,
        $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 $item_to_send is not named in camelCase.
Open

    public function send($frequency = 8)
    {
        $notifications = $this->find(
            'all',
            ['where' => ['sent_at IS NULL AND send_freq = ?' => $frequency]]

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

    public function saveNotification(
        $messageId,
        $type,
        $userList,
        $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 $item_to_send is not named in camelCase.
Open

    public function send($frequency = 8)
    {
        $notifications = $this->find(
            'all',
            ['where' => ['sent_at IS NULL AND send_freq = ?' => $frequency]]

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

    public function send($frequency = 8)
    {
        $notifications = $this->find(
            'all',
            ['where' => ['sent_at IS NULL AND send_freq = ?' => $frequency]]

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

    public function saveNotification(
        $messageId,
        $type,
        $userList,
        $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 $user_id is not named in camelCase.
Open

    public function saveNotification(
        $messageId,
        $type,
        $userList,
        $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 $item_to_send is not named in camelCase.
Open

    public function send($frequency = 8)
    {
        $notifications = $this->find(
            'all',
            ['where' => ['sent_at IS NULL AND send_freq = ?' => $frequency]]

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

    public function saveNotification(
        $messageId,
        $type,
        $userList,
        $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 $item_to_send is not named in camelCase.
Open

    public function send($frequency = 8)
    {
        $notifications = $this->find(
            'all',
            ['where' => ['sent_at IS NULL AND send_freq = ?' => $frequency]]

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

    public function send($frequency = 8)
    {
        $notifications = $this->find(
            'all',
            ['where' => ['sent_at IS NULL AND send_freq = ?' => $frequency]]

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

    public function send($frequency = 8)
    {
        $notifications = $this->find(
            'all',
            ['where' => ['sent_at IS NULL AND send_freq = ?' => $frequency]]

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

    public function saveNotification(
        $messageId,
        $type,
        $userList,
        $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 $extra_data is not named in camelCase.
Open

    public function saveNotification(
        $messageId,
        $type,
        $userList,
        $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

There are no issues that match your filters.

Category
Status