Test Failed
Push — master ( 647c72...cd42b5 )
by
unknown
10:25
created

Notifier::createNotificationResponseData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 19
rs 9.9332
c 0
b 0
f 0
1
<?php
2
	/**
3
	 * Notifier
4
	 *
5
	 * Superclass for every notifier.
6
	 */
7
	class Notifier {
8
		/**
9
		 * @var array list of the notifications, which is send to the client.
10
		 */
11
		private $responseNotificationData;
12
13
		/**
14
		 * @var int notification counter of the class
15
		 */
16
		private $notifyCount;
17
18
		public function __construct()
19
		{
20
			$this->notifyCount = 0;
21
			$this->responseNotificationData = array();
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
		{
31
			return 0;
32
		}
33
34
		/**
35
		 * Function which resets the data and the response data class variable.
36
		 */
37
		public function reset()
38
		{
39
			$this->notifyCount = 0;
40
			$this->responseNotificationData = array();
41
		}
42
43
		/**
44
		 * Function which returns name of the notifier class.
45
		 * @return string notifier name.
46
		 */
47
		public function getNotifierName()
48
		{
49
			return strtolower(get_class($this));
50
		}
51
52
		/**
53
		 * Function which adds notification data to module, so later it can be retrieved to send.
54
		 * @param string $actionType type of action that response data corresponds.
55
		 * @return array data object.
56
		 */
57
		protected function addNotificationActionData($actionType, $data)
58
		{
59
			if (!isset($this->responseNotificationData[$actionType])) {
60
				$this->responseNotificationData[$actionType] = $data;
61
			}
62
		}
63
64
		/**
65
		 * Function which returns notification data that will be sent to client. If there isn't any data added
66
		 * to response data then it will return a blank array.
67
		 * @return object response data.
68
		 */
69
		protected function createNotificationResponseData()
70
		{
71
			if (!empty($this->responseNotificationData)) {
72
				$moduleName = $this->getNotifierName();
73
				$idName = $moduleName . (++$this->notifyCount);
74
75
				$response = array(
76
					$moduleName => array(
77
						$idName => $this->responseNotificationData
78
					)
79
				);
80
81
				// Clear notification data, the response which is being returned
82
				// should be sent to the client.
83
				$this->responseNotificationData = array();
84
85
				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...
86
			} else {
87
				return array();
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...
88
			}
89
		}
90
91
		/**
92
		 * If an event elsewhere has occurred, it enters in this method. This method
93
		 * executes one ore more actions, depends on the event.
94
		 * @param int $event Event.
95
		 * @param string $entryid Entryid.
96
		 * @param array $data array of data.
97
		 */
98
		public function update($event, $entryid, $data)
0 ignored issues
show
Unused Code introduced by
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

98
		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...
Unused Code introduced by
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

98
		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...
Unused Code introduced by
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

98
		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...
99
		{
100
			// you must implement this function for each notifier
101
		}
102
	}
103
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
104