NotificationsTrait::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 5
dl 0
loc 14
ccs 0
cts 13
cp 0
crap 6
rs 9.9
c 0
b 0
f 0
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