Completed
Push — master ( 34780a...58c117 )
by Barry vd.
03:47
created

Packet::setNotification()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace NotificationChannels\Gcm;
4
5
use ZendService\Google\Gcm\Message;
6
use Zend\Json\Json;
7
8
class Packet extends Message
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $notification;
14
15
    /**
16
     * Set the notification.
17
     *
18
     * @param array $ids
0 ignored issues
show
Bug introduced by
There is no parameter named $ids. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
19
     * @return Message
20
     */
21
    public function setNotification($notification)
22
    {
23
        $this->notification = $notification;
24
25
        return $this;
26
    }
27
28
    /**
29
     * To JSON
30
     * Utility method to put the JSON into the
31
     * GCM proper format for sending the message.
32
     *
33
     * @return string
34
     */
35
    public function toJson()
36
    {
37
        $json = [];
38
        if ($this->registrationIds) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->registrationIds of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
39
            $json['registration_ids'] = $this->registrationIds;
40
        }
41
        if ($this->collapseKey) {
42
            $json['collapse_key'] = $this->collapseKey;
43
        }
44
        if ($this->data) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->data of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
45
            $json['data'] = $this->data;
46
        }
47
        if ($this->notification) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->notification of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
48
            $json['notification'] = $this->notification;
49
        }
50
        if ($this->delayWhileIdle) {
51
            $json['delay_while_idle'] = $this->delayWhileIdle;
52
        }
53
        if ($this->timeToLive != 2419200) {
54
            $json['time_to_live'] = $this->timeToLive;
55
        }
56
        if ($this->restrictedPackageName) {
57
            $json['restricted_package_name'] = $this->restrictedPackageName;
58
        }
59
        if ($this->dryRun) {
60
            $json['dry_run'] = $this->dryRun;
61
        }
62
63
        return Json::encode($json);
64
    }
65
}
66