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

PushNotificationsHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 44
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 25 2
A shouldHandle() 0 3 1
1
<?php
2
3
namespace Gewaer\Handlers;
4
5
use Namshi\Notificator\Notification\Handler\HandlerInterface;
6
use Gewaer\Contracts\PushNotificationsContract;
7
use Phalcon\Http\Response;
8
use Namshi\Notificator\NotificationInterface;
9
use Phalcon\Di;
10
use Gewaer\Notifications\PushNotifications\AppsPushNotifications;
11
use Gewaer\Notifications\PushNotifications\PushNotifications;
12
use Gewaer\Models\Notifications;
13
use Gewaer\Traits\NotificationsTrait;
14
use Gewaer\Models\SystemModules;
15
16
class PushNotificationsHandler implements HandlerInterface
17
{
18
    /**
19
     * Notifications Trait
20
     */
21
    use NotificationsTrait;
0 ignored issues
show
Bug introduced by
The trait Gewaer\Traits\NotificationsTrait requires the property $id which is not provided by Gewaer\Handlers\PushNotificationsHandler.
Loading history...
22
23
    /**
24
     * Stablishes type of handler
25
     */
26
    public function shouldHandle(NotificationInterface $notification)
27
    {
28
        return $notification instanceof PushNotificationsContract;
29
    }
30
    
31
    /**
32
     * Handles actions to take depending of notifications
33
     * @param NotificationInterface $notification
34
     */
35
    public function handle(NotificationInterface $notification)
36
    {
37
        $this->create($notification->user,$notification->content,$notification->notificationTypeId,$notification->systemModule);
0 ignored issues
show
Bug introduced by
Accessing systemModule on the interface Namshi\Notificator\NotificationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Accessing user on the interface Namshi\Notificator\NotificationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Accessing content on the interface Namshi\Notificator\NotificationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Accessing notificationTypeId on the interface Namshi\Notificator\NotificationInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
38
        die();
39
        $notificationType = $notification->notificationTypeId;
0 ignored issues
show
Unused Code introduced by
$notificationType = $not...ion->notificationTypeId 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...
40
41
        switch ($notificationType) {
42
            case '1':
43
                $newTypeRecord =  new AppsPushNotifications($notification->getMessage(), $notification->notificationTypeId);
44
                Di::getDefault()->getLog()->info($newTypeRecord->getMessage());
45
                break;
46
            // case '2':
47
            // $notificationType =  new AppsPushNotifications($notification->getMessage(), $notification->source_id);
48
            // Di::getDefault()->getLog()->info($notificationType->getMessage());
49
            // break;
50
51
            // case '3':
52
            // $notificationType =  new AppsPushNotifications($notification->getMessage(), $notification->source_id);
53
            // Di::getDefault()->getLog()->info($notificationType->getMessage());
54
            // break;
55
            
56
            default:
57
                $newTypeRecord =  new PushNotifications($notification->getMessage(), $notification->notificationTypeId);
58
                Di::getDefault()->getLog()->info($newTypeRecord->getMessage());
59
                break;
60
        }
61
    }
62
}
63