Test Failed
Pull Request — master (#70)
by Rafael
06:04
created

NotificationsTrait   A

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 Gewaer\Traits;
6
7
use Gewaer\Models\SystemModules;
8
use Gewaer\Models\Notifications;
9
use Phalcon\Di;
10
11
/**
12
 * Trait ResponseTrait
13
 *
14
 * @package Gewaer\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 $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;
43
        $notification->entity_id = $user['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