NotificationsTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 24
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Traits;
6
7
use Canvas\Models\SystemModules;
8
use Canvas\Models\Notifications;
9
use Phalcon\Di;
10
11
/**
12
 * Trait ResponseTrait.
13
 *
14
 * @package Canvas\Traits
15
 *
16
 * @property Users $user
17
 * @property AppsPlans $appPlan
18
 * @property CompanyBranches $branches
19
 * @property Companies $company
20
 * @property UserCompanyApps $app
21
 * @property \Phalcon\Di $di
22
 * @property Id $id
23
 *
24
 */
25
trait NotificationsTrait
26
{
27
    /**
28
     * Create a new notification.
29
     * @param array $user
30
     * @param string $content
31
     * @param int $notificationTypeId
32
     * @param string $systemModule
33
     * @return void
34
     */
35
    public static function create(array $entity, array $user, string $content, int $notificationTypeId, string $systemModule): void
36
    {
37
        $notification = new Notifications();
38
        $notification->users_id = $user['id'];
39
        $notification->companies_id = $user['default_company'];
40
        $notification->apps_id = Di::getDefault()->getApp()->getId();
41
        $notification->notification_type_id = $notificationTypeId;
42
        $notification->system_module_id = SystemModules::getSystemModuleByModelName($systemModule)->id;
0 ignored issues
show
Deprecated Code introduced by
The function Canvas\Models\SystemModu...stemModuleByModelName() has been deprecated: v2 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

42
        $notification->system_module_id = /** @scrutinizer ignore-deprecated */ SystemModules::getSystemModuleByModelName($systemModule)->id;

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
43
        $notification->entity_id = $entity['id'];
44
        $notification->content = $content;
45
        $notification->created_at = date('Y-m-d H:i:s');
46
47
        if (!$notification->save()) {
48
            Di::getDefault()->getLog()->error((string) current($notification->getMessages()));
49
        }
50
    }
51
}
52