Test Failed
Pull Request — master (#70)
by Rafael
05:48
created

PushNotifications   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 102
ccs 0
cts 35
cp 0
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A assemble() 0 3 1
A __construct() 0 3 1
A system() 0 15 2
A users() 0 15 2
A apps() 0 26 2
1
<?php
2
3
namespace Gewaer\Notifications\PushNotifications;
4
5
use Namshi\Notificator\Notification;
6
use Gewaer\Contracts\PushNotificationsContract;
7
use Gewaer\Models\Users;
8
use Gewaer\Notifications\PushNotifications\AppsPushNotifications;
9
use Gewaer\Notifications\PushNotifications\UsersPushNotifications;
10
use Gewaer\Notifications\PushNotifications\SystemPushNotifications;
11
use Phalcon\Di;
12
use PhpAmqpLib\Message\AMQPMessage;
13
14
class PushNotifications extends Notification implements PushNotificationsContract
15
{
16
    public $user;
17
18
    public $content;
19
20
    public $systemModule;
21
22
    public function __construct(string $content)
23
    {
24
        $this->content  = $content;
25
    }
26
27
    /**
28
     * Assemble Notification
29
     */
30
    public function assemble()
31
    {
32
        return $this->content;
33
    }
34
35
    /**
36
     * Create a new Apps Notification
37
     * @param string $content
38
     * @param string $systemModule
39
     * @param Users $user
40
     * @return void
41
     */
42
    public static function apps(string $content, string $systemModule, Users $user = null): void
43
    {
44
        if (!isset($user)) {
45
            $user =  Di::getDefault()->getUserData();
46
        }
47
        /**
48
         * Create a new Apps Push Notification
49
         */
50
        $notification =  new AppsPushNotifications($user, $content, $systemModule);
51
52
53
        /**
54
         * Convert notification to Rabbitmq message
55
         */
56
        $msg =  new AMQPMessage($notification->assemble(), ['delivery_mode' => 2]);
57
58
        $channel = Di::getDefault()->getQueue()->channel();
59
60
        $channel->basic_publish($msg, '', 'notifications');
61
        die();
62
        
63
64
        /**
65
         * Send to notifications queue
66
         */
67
        Di::getDefault()->getManager()->trigger($notification);
0 ignored issues
show
Unused Code introduced by
Phalcon\Di::getDefault()...>trigger($notification) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
68
    }
69
70
    /**
71
     * Create a new Users Notification
72
     * @param string $content
73
     * @param string $systemModule
74
     * @param Users $user
75
     * @return void
76
     */
77
    public static function users(string $content, string $systemModule, Users $user = null): void
78
    {
79
        if (!isset($user)) {
80
            $user =  Di::getDefault()->getUserData();
0 ignored issues
show
Unused Code introduced by
The assignment to $user is dead and can be removed.
Loading history...
81
        }
82
83
        /**
84
         * Create a new Apps Push Notification
85
         */
86
        $notification =  new UsersPushNotifications(Di::getDefault()->getUserData(), $content, $systemModule);
87
88
        /**
89
         * Send to notifications queue
90
         */
91
        Di::getDefault()->getManager()->trigger($notification);
92
    }
93
94
    /**
95
     * Create a new System Notification
96
     * @param string $content
97
     * @param string $systemModule
98
     * @param Users $user
99
     * @return void
100
     */
101
    public static function system(string $content, string $systemModule, Users $user = null): void
102
    {
103
        if (!isset($user)) {
104
            $user =  Di::getDefault()->getUserData();
0 ignored issues
show
Unused Code introduced by
The assignment to $user is dead and can be removed.
Loading history...
105
        }
106
107
        /**
108
         * Create a new Apps Push Notification
109
         */
110
        $notification =  new SystemPushNotifications(Di::getDefault()->getUserData(), $content, $systemModule);
111
112
        /**
113
         * Send to notifications queue
114
         */
115
        Di::getDefault()->getManager()->trigger($notification);
116
    }
117
}
118