1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fenos\Notifynder\Senders; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Class NotifynderSenderFactory |
7
|
|
|
* |
8
|
|
|
* @package Fenos\Notifynder |
9
|
|
|
*/ |
10
|
|
|
use Fenos\Notifynder\Builder\NotifynderBuilder; |
11
|
|
|
use Fenos\Notifynder\Contracts\NotifynderCategory; |
12
|
|
|
use Fenos\Notifynder\Contracts\NotifynderGroup; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class SenderFactory. |
16
|
|
|
*/ |
17
|
|
|
class SenderFactory |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var NotifynderGroup |
21
|
|
|
*/ |
22
|
|
|
protected $notifynderGroup; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var NotifynderCategory |
26
|
|
|
*/ |
27
|
|
|
private $notifynderCategory; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param NotifynderGroup $notifynderGroup |
31
|
|
|
* @param NotifynderCategory $notifynderCategory |
32
|
|
|
*/ |
33
|
|
|
public function __construct(NotifynderGroup $notifynderGroup, |
34
|
|
|
NotifynderCategory $notifynderCategory) |
35
|
|
|
{ |
36
|
|
|
$this->notifynderGroup = $notifynderGroup; |
37
|
|
|
$this->notifynderCategory = $notifynderCategory; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get the right sender when the data is |
42
|
|
|
* passed. |
43
|
|
|
* |
44
|
|
|
* @param array $infoNotifications |
45
|
|
|
* @param $category |
46
|
|
|
* @return SendMultiple|SendOne |
47
|
|
|
*/ |
48
|
|
|
public function getSender($infoNotifications, $category = null) |
49
|
|
|
{ |
50
|
|
|
if ($infoNotifications instanceof NotifynderBuilder) { |
51
|
|
|
$infoNotifications = $infoNotifications->toArray(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// if the array is multidimensional |
55
|
|
|
// it means that we want to send |
56
|
|
|
// multiple notifications |
57
|
|
|
if ($this->isMultiArray($infoNotifications)) { |
58
|
|
|
return $this->sendMultiple($infoNotifications); |
59
|
|
|
} else { |
60
|
|
|
return $this->sendSingle($infoNotifications, $category); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Send Single Notification Sender. |
66
|
|
|
* |
67
|
|
|
* @param array $infoNotifications |
68
|
|
|
* @param $category |
69
|
|
|
* @return SendOne |
70
|
|
|
*/ |
71
|
|
|
public function sendSingle(array $infoNotifications, $category) |
72
|
|
|
{ |
73
|
|
|
return new SendOne($infoNotifications, $category); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Send Multiple Notification Sender. |
78
|
|
|
* |
79
|
|
|
* @param array $infoNotifications |
80
|
|
|
* @return SendMultiple |
81
|
|
|
*/ |
82
|
|
|
public function sendMultiple(array $infoNotifications) |
83
|
|
|
{ |
84
|
|
|
return new SendMultiple($infoNotifications); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get the the send group instance. |
89
|
|
|
* |
90
|
|
|
* @param string $groupName |
91
|
|
|
* @param array | \Closure $info |
92
|
|
|
* @return SendGroup |
93
|
|
|
*/ |
94
|
|
|
public function sendGroup($groupName, array $info) |
95
|
|
|
{ |
96
|
|
|
return new SendGroup( |
97
|
|
|
$this->notifynderGroup, |
98
|
|
|
$this->notifynderCategory, |
99
|
|
|
$groupName, |
100
|
|
|
$info |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Check if the array passed is |
106
|
|
|
* multidimensional. |
107
|
|
|
* |
108
|
|
|
* @param $arr |
109
|
|
|
* @return bool |
110
|
|
|
*/ |
111
|
|
View Code Duplication |
protected function isMultiArray(array $arr) |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
$rv = array_filter($arr, 'is_array'); |
114
|
|
|
if (count($rv) > 0) { |
115
|
|
|
return true; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return false; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.