Conditions | 5 |
Paths | 2 |
Total Lines | 76 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
28 | public function notificationAction() |
||
29 | { |
||
30 | $channel = $this->queue->channel(); |
||
31 | |||
32 | // Create the queue if it doesnt already exist. |
||
33 | $channel->queue_declare( |
||
34 | $queue = "notifications", |
||
35 | $passive = false, |
||
36 | $durable = true, |
||
37 | $exclusive = false, |
||
38 | $auto_delete = false, |
||
39 | $nowait = false, |
||
40 | $arguments = null, |
||
41 | $ticket = null |
||
42 | ); |
||
43 | |||
44 | echo ' [*] Waiting for notifications. To exit press CTRL+C', "\n"; |
||
45 | |||
46 | $callback = function ($msg) { |
||
47 | $msgObject = json_decode($msg->body); |
||
48 | |||
49 | |||
50 | |||
51 | echo ' [x] Received from system module: ',$msgObject->system_module, "\n"; |
||
52 | |||
53 | |||
54 | /** |
||
55 | * Lets determine what type of notification we are dealing with |
||
56 | */ |
||
57 | switch ($msgObject->notification_type_id) { |
||
58 | case 1: |
||
59 | $notification = new AppsPushNotifications((array)$msgObject->user, $msgObject->content, $msgObject->system_module); |
||
60 | break; |
||
61 | case 2: |
||
62 | $notification = new UsersPushNotifications((array)$msgObject->user, $msgObject->content, $msgObject->system_module); |
||
63 | break; |
||
64 | |||
65 | case 3: |
||
66 | $notification = new SystemPushNotifications((array)$msgObject->user, $msgObject->content, $msgObject->system_module); |
||
67 | break; |
||
68 | |||
69 | default: |
||
70 | # code... |
||
71 | break; |
||
72 | } |
||
1 ignored issue
–
show
|
|||
73 | |||
74 | |||
75 | /** |
||
76 | * Trigger Event Manager |
||
77 | */ |
||
78 | Di::getDefault()->getManager()->trigger($notification); |
||
79 | |||
80 | /** |
||
81 | * Log the delivery info |
||
82 | */ |
||
83 | $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); |
||
84 | }; |
||
85 | |||
86 | $channel->basic_qos(null, 1, null); |
||
87 | |||
88 | $channel->basic_consume( |
||
89 | $queue = "notifications", |
||
90 | $consumer_tag = '', |
||
91 | $no_local = false, |
||
92 | $no_ack = false, |
||
93 | $exclusive = false, |
||
94 | $nowait = false, |
||
95 | $callback |
||
96 | ); |
||
97 | |||
98 | while (count($channel->callbacks)) { |
||
99 | $channel->wait(); |
||
100 | } |
||
101 | |||
102 | $channel->close(); |
||
103 | $this->queue->close(); |
||
104 | } |
||
106 |