Test Failed
Pull Request — master (#70)
by Rafael
05:38
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\Users;
8
use Gewaer\Models\SystemModules;
9
use Gewaer\Models\Notifications;
10
use Phalcon\Di;
11
12
/**
13
 * Trait ResponseTrait
14
 *
15
 * @package Gewaer\Traits
16
 *
17
 * @property Users $user
18
 * @property AppsPlans $appPlan
19
 * @property CompanyBranches $branches
20
 * @property Companies $company
21
 * @property UserCompanyApps $app
22
 * @property \Phalcon\Di $di
23
 * @property Id $id
24
 *
25
 */
26
trait NotificationsTrait
27
{
28
    /**
29
     * Create a new notification
30
     * @param Users $user
31
     * @param string $content
32
     * @param int $notificationTypeId
33
     * @param string $systemModule
34
     * @return void
35
     */
36
    public static function create(array $user, string $content, int $notificationTypeId, string $systemModule): void
37
    {
38
        $notification =  new Notifications();
39
        $notification->users_id = $user['id'];
40
        $notification->companies_id = $user['default_company'];
41
        $notification->apps_id = Di::getDefault()->getApp()->getId();
42
        $notification->notification_type_id = $notificationTypeId;
43
        $notification->system_module_id = SystemModules::getSystemModuleByModelName($systemModule)->id;
44
        $notification->entity_id = $user['id'];
45
        $notification->content = $content;
46
        $notification->created_at = date('Y-m-d H:i:s');
47
48
        if (!$notification->save()) {
49
            Di::getDefault()->getLog()->error((string)current($notification->getMessages()));
50
        }
51
    }
52
}
53