Completed
Pull Request — master (#6)
by Mark
10:00 queued 02:55
created

IonicPushMessage   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 2 Features 0
Metric Value
wmc 10
c 4
b 2
f 0
lcom 4
cbo 0
dl 0
loc 134
ccs 0
cts 29
cp 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A __construct() 0 5 1
A profile() 0 6 1
A sendTo() 0 6 1
A sound() 0 6 1
A payload() 0 6 1
A __call() 0 14 3
A toArray() 0 4 1
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
     * @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...
34
     *
35
     * @return static
36
     */
37
    public static function create($title, $message)
38
    {
39
        return new static($title, $message);
40
    }
41
42
    /**
43
     * @param string $title
44
     * @param string $message
45
     */
46
    public function __construct($title, $message)
47
    {
48
        $this->title = $title;
49
        $this->message = $message;
50
    }
51
52
    /**
53
     * Set the security profile to use.
54
     *
55
     * @param  string  $profile
56
     *
57
     * @return $this
58
     */
59
    public function profile($profile)
60
    {
61
        $this->profile = $profile;
62
63
        return $this;
64
    }
65
66
    /**
67
     * Set the method of targeting users - tokens (default), user_ids, or emails.
68
     *
69
     * @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...
70
     *
71
     * @return $this
72
     */
73
    public function sendTo($sendTo)
74
    {
75
        $this->sendTo = $sendTo;
76
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
91
        return $this;
92
    }
93
94
    /**
95
     * Send custom key/value data with your notifications.
96
     *
97
     * @param  array  $payload
98
     *
99
     * @return $this
100
     */
101
    public function payload($payload)
102
    {
103
        $this->payload = $payload;
104
105
        return $this;
106
    }
107
108
    /**
109
     * Dynamically add query parameters or call API endpoints.
110
     *
111
     * @param string $method
112
     * @param array  $args
113
     *
114
     * @return object
115
     */
116
    public function __call($method, $args)
117
    {
118
        if (substr($method, 0, 3) == 'ios') {
119
            $key = snake_case(substr($method, 3));
120
121
            $this->iosData[$key] = $args[0];
122
        } elseif (substr($method, 0, 7) == 'android') {
123
            $key = snake_case(substr($method, 7));
124
125
            $this->androidData[$key] = $args[0];
126
        }
127
128
        return $this;
129
    }
130
131
    /**
132
     * @return array
133
     */
134
    public function toArray()
135
    {
136
        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...
137
    }
138
}
139