Completed
Pull Request — master (#6)
by Mark
03:07
created

IonicPushMessage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
3
namespace NotificationChannels\IonicPushNotifications;
4
5
class IonicPushMessage
6
{
7
    /** @var string */
8
    protected $sendTo = 'tokens';
9
10
    /** @var string */
11
    protected $profile;
12
13
    /** @var string */
14
    protected $title = '';
15
16
    /** @var string */
17
    protected $message = '';
18
19
    /** @var string */
20
    protected $sound = '';
21
22
23
    /** @var array */
24
    protected $payload = [];
25
26
    /** @var array */
27
    protected $iosData = [];
28
29
    /** @var array */
30
    protected $androidData = [];
31
32
33
34
    /**
35
     * @param array $data
0 ignored issues
show
Bug introduced by
There is no parameter named $data. 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...
36
     *
37
     * @return static
38
     */
39
    public static function create($title, $message)
40
    {
41
        return new static($title, $message);
42
    }
43
44
    /**
45
     * @param string $title
46
     * @param string $message
47
     */
48
    public function __construct($title, $message)
49
    {
50
        $this->title = $title;
51
        $this->message = $message;
52
    }
53
54
    /**
55
     * Set the security profile to use.
56
     *
57
     * @param  string  $profile
58
     *
59
     * @return $this
60
     */
61
    public function profile($profile)
62
    {
63
        $this->profile = $profile;
64
        return $this;
65
    }
66
67
    /**
68
     * Set the method of targeting users - tokens (default), user_ids, or emails.
69
     *
70
     * @param  string  $profile
0 ignored issues
show
Bug introduced by
There is no parameter named $profile. 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...
71
     *
72
     * @return $this
73
     */
74
    public function sendTo($sendTo)
75
    {
76
        $this->sendTo = $sendTo;
77
        return $this;
78
    }
79
80
    /**
81
     * Set the security sound to use.
82
     *
83
     * @param  string  $sound
84
     *
85
     * @return $this
86
     */
87
    public function sound($sound)
88
    {
89
        $this->sound = $sound;
90
        return $this;
91
    }
92
93
    /**
94
     * Send custom key/value data with your notifications.
95
     *
96
     * @param  array  $payload
97
     *
98
     * @return $this
99
     */
100
    public function payload($payload)
101
    {
102
        $this->payload = $payload;
103
        return $this;
104
    }
105
106
107
    /**
108
     * Dynamically add query parameters or call API endpoints.
109
     *
110
     * @param string $method
111
     * @param array  $args
112
     *
113
     * @return object
114
     */
115
    public function __call($method, $args)
116
    {
117
        if (substr($method, 0, 3) == 'ios') {
118
            $key = snake_case(substr($method, 3));
119
120
            $this->iosData[$key] = $args[0];
121
        } elseif (substr($method, 0, 7) == 'android') {
122
            $key = snake_case(substr($method, 7));
123
124
            $this->androidData[$key] = $args[0];
125
        }
126
        return $this;
127
    }
128
129
    /**
130
     * @return array
131
     */
132
    public function toArray()
133
    {
134
        return $this->data;
0 ignored issues
show
Bug introduced by
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
135
    }
136
}
137