Issues (752)

server/includes/notifiers/class.notifier.php (5 issues)

1
<?php
2
3
/**
4
 * Notifier.
5
 *
6
 * Superclass for every notifier.
7
 */
8
class Notifier {
9
	/**
10
	 * @var array list of the notifications, which is send to the client
11
	 */
12
	private $responseNotificationData;
13
14
	/**
15
	 * @var int notification counter of the class
16
	 */
17
	private $notifyCount;
18
19
	public function __construct() {
20
		$this->notifyCount = 0;
21
		$this->responseNotificationData = [];
22
	}
23
24
	/**
25
	 * @return Number Return the bitmask of events which are handled
26
	 *                by this notifier. The bitmask can consist of the
27
	 *                OBJECT_SAVE, OBJECT_DELETE, TABLE_SAVE, TABLE_DELETE, REQUEST_START and REQUEST_END flags
28
	 */
29
	public function getEvents() {
30
		return 0;
31
	}
32
33
	/**
34
	 * Function which resets the data and the response data class variable.
35
	 */
36
	public function reset() {
37
		$this->notifyCount = 0;
38
		$this->responseNotificationData = [];
39
	}
40
41
	/**
42
	 * Function which returns name of the notifier class.
43
	 *
44
	 * @return string notifier name
45
	 */
46
	public function getNotifierName() {
47
		return strtolower(static::class);
48
	}
49
50
	/**
51
	 * Function which adds notification data to module, so later it can be retrieved to send.
52
	 *
53
	 * @param string $actionType type of action that response data corresponds
54
	 * @param mixed  $data
55
	 */
56
	protected function addNotificationActionData($actionType, $data) {
57
		if (!isset($this->responseNotificationData[$actionType])) {
58
			$this->responseNotificationData[$actionType] = $data;
59
		}
60
	}
61
62
	/**
63
	 * Function which returns notification data that will be sent to client. If there isn't any data added
64
	 * to response data then it will return a blank array.
65
	 *
66
	 * @return object response data
67
	 */
68
	protected function createNotificationResponseData() {
69
		if (!empty($this->responseNotificationData)) {
70
			$moduleName = $this->getNotifierName();
71
			$idName = $moduleName . (++$this->notifyCount);
72
73
			$response = [
74
				$moduleName => [
75
					$idName => $this->responseNotificationData,
76
				],
77
			];
78
79
			// Clear notification data, the response which is being returned
80
			// should be sent to the client.
81
			$this->responseNotificationData = [];
82
83
			return $response;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response returns the type array<string,array<string,array>> which is incompatible with the documented return type object.
Loading history...
84
		}
85
86
		return [];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array() returns the type array which is incompatible with the documented return type object.
Loading history...
87
	}
88
89
	/**
90
	 * If an event elsewhere has occurred, it enters in this method. This method
91
	 * executes one or more actions, depends on the event.
92
	 *
93
	 * @param int    $event   event
94
	 * @param string $entryid entryid
95
	 * @param array  $data    array of data
96
	 */
97
	public function update($event, $entryid, $data) {
0 ignored issues
show
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

97
	public function update($event, $entryid, /** @scrutinizer ignore-unused */ $data) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

97
	public function update(/** @scrutinizer ignore-unused */ $event, $entryid, $data) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $entryid is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

97
	public function update($event, /** @scrutinizer ignore-unused */ $entryid, $data) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
98
		// you must implement this function for each notifier
99
	}
100
}
101