Completed
Push — master ( 6a16a2...464d12 )
by
unknown
22:58
created
apps/dav/lib/CalDAV/Search/Xml/Request/CalendarSearchReport.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -107,32 +107,32 @@  discard block
 block discarded – undo
107 107
 				case '{DAV:}prop':
108 108
 					$newProps['properties'] = array_keys($elem['value']);
109 109
 					break;
110
-				case '{' . SearchPlugin::NS_Nextcloud . '}filter':
110
+				case '{'.SearchPlugin::NS_Nextcloud.'}filter':
111 111
 					foreach ($elem['value'] as $subElem) {
112
-						if ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}comp-filter') {
112
+						if ($subElem['name'] === '{'.SearchPlugin::NS_Nextcloud.'}comp-filter') {
113 113
 							if (!isset($newProps['filters']['comps']) || !is_array($newProps['filters']['comps'])) {
114 114
 								$newProps['filters']['comps'] = [];
115 115
 							}
116 116
 							$newProps['filters']['comps'][] = $subElem['value'];
117
-						} elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}prop-filter') {
117
+						} elseif ($subElem['name'] === '{'.SearchPlugin::NS_Nextcloud.'}prop-filter') {
118 118
 							if (!isset($newProps['filters']['props']) || !is_array($newProps['filters']['props'])) {
119 119
 								$newProps['filters']['props'] = [];
120 120
 							}
121 121
 							$newProps['filters']['props'][] = $subElem['value'];
122
-						} elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}param-filter') {
122
+						} elseif ($subElem['name'] === '{'.SearchPlugin::NS_Nextcloud.'}param-filter') {
123 123
 							if (!isset($newProps['filters']['params']) || !is_array($newProps['filters']['params'])) {
124 124
 								$newProps['filters']['params'] = [];
125 125
 							}
126 126
 							$newProps['filters']['params'][] = $subElem['value'];
127
-						} elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}search-term') {
127
+						} elseif ($subElem['name'] === '{'.SearchPlugin::NS_Nextcloud.'}search-term') {
128 128
 							$newProps['filters']['search-term'] = $subElem['value'];
129 129
 						}
130 130
 					}
131 131
 					break;
132
-				case '{' . SearchPlugin::NS_Nextcloud . '}limit':
132
+				case '{'.SearchPlugin::NS_Nextcloud.'}limit':
133 133
 					$newProps['limit'] = $elem['value'];
134 134
 					break;
135
-				case '{' . SearchPlugin::NS_Nextcloud . '}offset':
135
+				case '{'.SearchPlugin::NS_Nextcloud.'}offset':
136 136
 					$newProps['offset'] = $elem['value'];
137 137
 					break;
138 138
 
@@ -140,21 +140,21 @@  discard block
 block discarded – undo
140 140
 		}
141 141
 
142 142
 		if (empty($newProps['filters'])) {
143
-			throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}filter element is required for this request');
143
+			throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}filter element is required for this request');
144 144
 		}
145 145
 
146 146
 		$propsOrParamsDefined = (!empty($newProps['filters']['props']) || !empty($newProps['filters']['params']));
147 147
 		$noCompsDefined = empty($newProps['filters']['comps']);
148 148
 		if ($propsOrParamsDefined && $noCompsDefined) {
149
-			throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter given without any {' . SearchPlugin::NS_Nextcloud . '}comp-filter');
149
+			throw new BadRequest('{'.SearchPlugin::NS_Nextcloud.'}prop-filter or {'.SearchPlugin::NS_Nextcloud.'}param-filter given without any {'.SearchPlugin::NS_Nextcloud.'}comp-filter');
150 150
 		}
151 151
 
152 152
 		if (!isset($newProps['filters']['search-term'])) {
153
-			throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}search-term is required for this request');
153
+			throw new BadRequest('{'.SearchPlugin::NS_Nextcloud.'}search-term is required for this request');
154 154
 		}
155 155
 
156 156
 		if (empty($newProps['filters']['props']) && empty($newProps['filters']['params'])) {
157
-			throw new BadRequest('At least one{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter is required for this request');
157
+			throw new BadRequest('At least one{'.SearchPlugin::NS_Nextcloud.'}prop-filter or {'.SearchPlugin::NS_Nextcloud.'}param-filter is required for this request');
158 158
 		}
159 159
 
160 160
 
Please login to merge, or discard this patch.
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -35,133 +35,133 @@
 block discarded – undo
35 35
  */
36 36
 class CalendarSearchReport implements XmlDeserializable {
37 37
 
38
-	/**
39
-	 * An array with requested properties.
40
-	 *
41
-	 * @var array
42
-	 */
43
-	public $properties;
44
-
45
-	/**
46
-	 * List of property/component filters.
47
-	 *
48
-	 * @var array
49
-	 */
50
-	public $filters;
51
-
52
-	/**
53
-	 * @var int
54
-	 */
55
-	public $limit;
56
-
57
-	/**
58
-	 * @var int
59
-	 */
60
-	public $offset;
61
-
62
-	/**
63
-	 * The deserialize method is called during xml parsing.
64
-	 *
65
-	 * This method is called statically, this is because in theory this method
66
-	 * may be used as a type of constructor, or factory method.
67
-	 *
68
-	 * Often you want to return an instance of the current class, but you are
69
-	 * free to return other data as well.
70
-	 *
71
-	 * You are responsible for advancing the reader to the next element. Not
72
-	 * doing anything will result in a never-ending loop.
73
-	 *
74
-	 * If you just want to skip parsing for this element altogether, you can
75
-	 * just call $reader->next();
76
-	 *
77
-	 * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
78
-	 * the next element.
79
-	 *
80
-	 * @param Reader $reader
81
-	 * @return mixed
82
-	 */
83
-	public static function xmlDeserialize(Reader $reader) {
84
-		$elems = $reader->parseInnerTree([
85
-			'{http://nextcloud.com/ns}comp-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\CompFilter',
86
-			'{http://nextcloud.com/ns}prop-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\PropFilter',
87
-			'{http://nextcloud.com/ns}param-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\ParamFilter',
88
-			'{http://nextcloud.com/ns}search-term' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\SearchTermFilter',
89
-			'{http://nextcloud.com/ns}limit' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\LimitFilter',
90
-			'{http://nextcloud.com/ns}offset' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\OffsetFilter',
91
-			'{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue',
92
-		]);
93
-
94
-		$newProps = [
95
-			'filters' => [],
96
-			'properties' => [],
97
-			'limit' => null,
98
-			'offset' => null
99
-		];
100
-
101
-		if (!is_array($elems)) {
102
-			$elems = [];
103
-		}
104
-
105
-		foreach ($elems as $elem) {
106
-			switch ($elem['name']) {
107
-				case '{DAV:}prop':
108
-					$newProps['properties'] = array_keys($elem['value']);
109
-					break;
110
-				case '{' . SearchPlugin::NS_Nextcloud . '}filter':
111
-					foreach ($elem['value'] as $subElem) {
112
-						if ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}comp-filter') {
113
-							if (!isset($newProps['filters']['comps']) || !is_array($newProps['filters']['comps'])) {
114
-								$newProps['filters']['comps'] = [];
115
-							}
116
-							$newProps['filters']['comps'][] = $subElem['value'];
117
-						} elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}prop-filter') {
118
-							if (!isset($newProps['filters']['props']) || !is_array($newProps['filters']['props'])) {
119
-								$newProps['filters']['props'] = [];
120
-							}
121
-							$newProps['filters']['props'][] = $subElem['value'];
122
-						} elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}param-filter') {
123
-							if (!isset($newProps['filters']['params']) || !is_array($newProps['filters']['params'])) {
124
-								$newProps['filters']['params'] = [];
125
-							}
126
-							$newProps['filters']['params'][] = $subElem['value'];
127
-						} elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}search-term') {
128
-							$newProps['filters']['search-term'] = $subElem['value'];
129
-						}
130
-					}
131
-					break;
132
-				case '{' . SearchPlugin::NS_Nextcloud . '}limit':
133
-					$newProps['limit'] = $elem['value'];
134
-					break;
135
-				case '{' . SearchPlugin::NS_Nextcloud . '}offset':
136
-					$newProps['offset'] = $elem['value'];
137
-					break;
138
-
139
-			}
140
-		}
141
-
142
-		if (empty($newProps['filters'])) {
143
-			throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}filter element is required for this request');
144
-		}
145
-
146
-		$propsOrParamsDefined = (!empty($newProps['filters']['props']) || !empty($newProps['filters']['params']));
147
-		$noCompsDefined = empty($newProps['filters']['comps']);
148
-		if ($propsOrParamsDefined && $noCompsDefined) {
149
-			throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter given without any {' . SearchPlugin::NS_Nextcloud . '}comp-filter');
150
-		}
151
-
152
-		if (!isset($newProps['filters']['search-term'])) {
153
-			throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}search-term is required for this request');
154
-		}
155
-
156
-		if (empty($newProps['filters']['props']) && empty($newProps['filters']['params'])) {
157
-			throw new BadRequest('At least one{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter is required for this request');
158
-		}
159
-
160
-
161
-		$obj = new self();
162
-		foreach ($newProps as $key => $value) {
163
-			$obj->$key = $value;
164
-		}
165
-		return $obj;
166
-	}
38
+    /**
39
+     * An array with requested properties.
40
+     *
41
+     * @var array
42
+     */
43
+    public $properties;
44
+
45
+    /**
46
+     * List of property/component filters.
47
+     *
48
+     * @var array
49
+     */
50
+    public $filters;
51
+
52
+    /**
53
+     * @var int
54
+     */
55
+    public $limit;
56
+
57
+    /**
58
+     * @var int
59
+     */
60
+    public $offset;
61
+
62
+    /**
63
+     * The deserialize method is called during xml parsing.
64
+     *
65
+     * This method is called statically, this is because in theory this method
66
+     * may be used as a type of constructor, or factory method.
67
+     *
68
+     * Often you want to return an instance of the current class, but you are
69
+     * free to return other data as well.
70
+     *
71
+     * You are responsible for advancing the reader to the next element. Not
72
+     * doing anything will result in a never-ending loop.
73
+     *
74
+     * If you just want to skip parsing for this element altogether, you can
75
+     * just call $reader->next();
76
+     *
77
+     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
78
+     * the next element.
79
+     *
80
+     * @param Reader $reader
81
+     * @return mixed
82
+     */
83
+    public static function xmlDeserialize(Reader $reader) {
84
+        $elems = $reader->parseInnerTree([
85
+            '{http://nextcloud.com/ns}comp-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\CompFilter',
86
+            '{http://nextcloud.com/ns}prop-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\PropFilter',
87
+            '{http://nextcloud.com/ns}param-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\ParamFilter',
88
+            '{http://nextcloud.com/ns}search-term' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\SearchTermFilter',
89
+            '{http://nextcloud.com/ns}limit' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\LimitFilter',
90
+            '{http://nextcloud.com/ns}offset' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\OffsetFilter',
91
+            '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue',
92
+        ]);
93
+
94
+        $newProps = [
95
+            'filters' => [],
96
+            'properties' => [],
97
+            'limit' => null,
98
+            'offset' => null
99
+        ];
100
+
101
+        if (!is_array($elems)) {
102
+            $elems = [];
103
+        }
104
+
105
+        foreach ($elems as $elem) {
106
+            switch ($elem['name']) {
107
+                case '{DAV:}prop':
108
+                    $newProps['properties'] = array_keys($elem['value']);
109
+                    break;
110
+                case '{' . SearchPlugin::NS_Nextcloud . '}filter':
111
+                    foreach ($elem['value'] as $subElem) {
112
+                        if ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}comp-filter') {
113
+                            if (!isset($newProps['filters']['comps']) || !is_array($newProps['filters']['comps'])) {
114
+                                $newProps['filters']['comps'] = [];
115
+                            }
116
+                            $newProps['filters']['comps'][] = $subElem['value'];
117
+                        } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}prop-filter') {
118
+                            if (!isset($newProps['filters']['props']) || !is_array($newProps['filters']['props'])) {
119
+                                $newProps['filters']['props'] = [];
120
+                            }
121
+                            $newProps['filters']['props'][] = $subElem['value'];
122
+                        } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}param-filter') {
123
+                            if (!isset($newProps['filters']['params']) || !is_array($newProps['filters']['params'])) {
124
+                                $newProps['filters']['params'] = [];
125
+                            }
126
+                            $newProps['filters']['params'][] = $subElem['value'];
127
+                        } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}search-term') {
128
+                            $newProps['filters']['search-term'] = $subElem['value'];
129
+                        }
130
+                    }
131
+                    break;
132
+                case '{' . SearchPlugin::NS_Nextcloud . '}limit':
133
+                    $newProps['limit'] = $elem['value'];
134
+                    break;
135
+                case '{' . SearchPlugin::NS_Nextcloud . '}offset':
136
+                    $newProps['offset'] = $elem['value'];
137
+                    break;
138
+
139
+            }
140
+        }
141
+
142
+        if (empty($newProps['filters'])) {
143
+            throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}filter element is required for this request');
144
+        }
145
+
146
+        $propsOrParamsDefined = (!empty($newProps['filters']['props']) || !empty($newProps['filters']['params']));
147
+        $noCompsDefined = empty($newProps['filters']['comps']);
148
+        if ($propsOrParamsDefined && $noCompsDefined) {
149
+            throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter given without any {' . SearchPlugin::NS_Nextcloud . '}comp-filter');
150
+        }
151
+
152
+        if (!isset($newProps['filters']['search-term'])) {
153
+            throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}search-term is required for this request');
154
+        }
155
+
156
+        if (empty($newProps['filters']['props']) && empty($newProps['filters']['params'])) {
157
+            throw new BadRequest('At least one{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter is required for this request');
158
+        }
159
+
160
+
161
+        $obj = new self();
162
+        foreach ($newProps as $key => $value) {
163
+            $obj->$key = $value;
164
+        }
165
+        return $obj;
166
+    }
167 167
 }
Please login to merge, or discard this patch.
lib/public/Diagnostics/IEventLogger.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -35,55 +35,55 @@
 block discarded – undo
35 35
  * @since 8.0.0
36 36
  */
37 37
 interface IEventLogger {
38
-	/**
39
-	 * Mark the start of an event setting its ID $id and providing event description $description.
40
-	 *
41
-	 * @param string $id
42
-	 * @param string $description
43
-	 * @since 8.0.0
44
-	 */
45
-	public function start($id, $description);
38
+    /**
39
+     * Mark the start of an event setting its ID $id and providing event description $description.
40
+     *
41
+     * @param string $id
42
+     * @param string $description
43
+     * @since 8.0.0
44
+     */
45
+    public function start($id, $description);
46 46
 
47
-	/**
48
-	 * Mark the end of an event with specific ID $id, marked by start() method.
49
-	 * Ending event should store \OCP\Diagnostics\IEvent to
50
-	 * be returned with getEvents() method.
51
-	 *
52
-	 * @param string $id
53
-	 * @since 8.0.0
54
-	 */
55
-	public function end($id);
47
+    /**
48
+     * Mark the end of an event with specific ID $id, marked by start() method.
49
+     * Ending event should store \OCP\Diagnostics\IEvent to
50
+     * be returned with getEvents() method.
51
+     *
52
+     * @param string $id
53
+     * @since 8.0.0
54
+     */
55
+    public function end($id);
56 56
 
57
-	/**
58
-	 * Mark the start and the end of an event with specific ID $id and description $description,
59
-	 * explicitly marking start and end of the event, represented by $start and $end timestamps.
60
-	 * Logging event should store \OCP\Diagnostics\IEvent to
61
-	 * be returned with getEvents() method.
62
-	 *
63
-	 * @param string $id
64
-	 * @param string $description
65
-	 * @param float $start
66
-	 * @param float $end
67
-	 * @since 8.0.0
68
-	 */
69
-	public function log($id, $description, $start, $end);
57
+    /**
58
+     * Mark the start and the end of an event with specific ID $id and description $description,
59
+     * explicitly marking start and end of the event, represented by $start and $end timestamps.
60
+     * Logging event should store \OCP\Diagnostics\IEvent to
61
+     * be returned with getEvents() method.
62
+     *
63
+     * @param string $id
64
+     * @param string $description
65
+     * @param float $start
66
+     * @param float $end
67
+     * @since 8.0.0
68
+     */
69
+    public function log($id, $description, $start, $end);
70 70
 
71
-	/**
72
-	 * This method should return all \OCP\Diagnostics\IEvent objects stored using
73
-	 * start()/end() or log() methods
74
-	 *
75
-	 * @return \OCP\Diagnostics\IEvent[]
76
-	 * @since 8.0.0
77
-	 */
78
-	public function getEvents();
71
+    /**
72
+     * This method should return all \OCP\Diagnostics\IEvent objects stored using
73
+     * start()/end() or log() methods
74
+     *
75
+     * @return \OCP\Diagnostics\IEvent[]
76
+     * @since 8.0.0
77
+     */
78
+    public function getEvents();
79 79
 
80
-	/**
81
-	 * Activate the module for the duration of the request. Deactivated module
82
-	 * does not create and store \OCP\Diagnostics\IEvent objects.
83
-	 * Only activated module should create and store objects to be
84
-	 * returned with getEvents() call.
85
-	 *
86
-	 * @since 12.0.0
87
-	 */
88
-	public function activate();
80
+    /**
81
+     * Activate the module for the duration of the request. Deactivated module
82
+     * does not create and store \OCP\Diagnostics\IEvent objects.
83
+     * Only activated module should create and store objects to be
84
+     * returned with getEvents() call.
85
+     *
86
+     * @since 12.0.0
87
+     */
88
+    public function activate();
89 89
 }
Please login to merge, or discard this patch.
lib/public/Diagnostics/IQuery.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -30,38 +30,38 @@
 block discarded – undo
30 30
  * @since 8.0.0
31 31
  */
32 32
 interface IQuery {
33
-	/**
34
-	 * @return string
35
-	 * @since 8.0.0
36
-	 */
37
-	public function getSql();
33
+    /**
34
+     * @return string
35
+     * @since 8.0.0
36
+     */
37
+    public function getSql();
38 38
 
39
-	/**
40
-	 * @return array
41
-	 * @since 8.0.0
42
-	 */
43
-	public function getParams();
39
+    /**
40
+     * @return array
41
+     * @since 8.0.0
42
+     */
43
+    public function getParams();
44 44
 
45
-	/**
46
-	 * @return float
47
-	 * @since 8.0.0
48
-	 */
49
-	public function getDuration();
45
+    /**
46
+     * @return float
47
+     * @since 8.0.0
48
+     */
49
+    public function getDuration();
50 50
 
51
-	/**
52
-	 * @return float
53
-	 * @since 11.0.0
54
-	 */
55
-	public function getStartTime();
51
+    /**
52
+     * @return float
53
+     * @since 11.0.0
54
+     */
55
+    public function getStartTime();
56 56
 
57
-	/**
58
-	 * @return array
59
-	 * @since 11.0.0
60
-	 */
61
-	public function getStacktrace();
62
-	/**
63
-	 * @return array
64
-	 * @since 12.0.0
65
-	 */
66
-	public function getStart();
57
+    /**
58
+     * @return array
59
+     * @since 11.0.0
60
+     */
61
+    public function getStacktrace();
62
+    /**
63
+     * @return array
64
+     * @since 12.0.0
65
+     */
66
+    public function getStart();
67 67
 }
Please login to merge, or discard this patch.
lib/private/Diagnostics/Query.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -26,65 +26,65 @@
 block discarded – undo
26 26
 use OCP\Diagnostics\IQuery;
27 27
 
28 28
 class Query implements IQuery {
29
-	private $sql;
29
+    private $sql;
30 30
 
31
-	private $params;
31
+    private $params;
32 32
 
33
-	private $start;
33
+    private $start;
34 34
 
35
-	private $end;
35
+    private $end;
36 36
 
37
-	private $stack;
37
+    private $stack;
38 38
 
39
-	/**
40
-	 * @param string $sql
41
-	 * @param array $params
42
-	 * @param int $start
43
-	 */
44
-	public function __construct($sql, $params, $start, array $stack) {
45
-		$this->sql = $sql;
46
-		$this->params = $params;
47
-		$this->start = $start;
48
-		$this->stack = $stack;
49
-	}
39
+    /**
40
+     * @param string $sql
41
+     * @param array $params
42
+     * @param int $start
43
+     */
44
+    public function __construct($sql, $params, $start, array $stack) {
45
+        $this->sql = $sql;
46
+        $this->params = $params;
47
+        $this->start = $start;
48
+        $this->stack = $stack;
49
+    }
50 50
 
51
-	public function end($time) {
52
-		$this->end = $time;
53
-	}
51
+    public function end($time) {
52
+        $this->end = $time;
53
+    }
54 54
 
55
-	/**
56
-	 * @return array
57
-	 */
58
-	public function getParams() {
59
-		return $this->params;
60
-	}
55
+    /**
56
+     * @return array
57
+     */
58
+    public function getParams() {
59
+        return $this->params;
60
+    }
61 61
 
62
-	/**
63
-	 * @return string
64
-	 */
65
-	public function getSql() {
66
-		return $this->sql;
67
-	}
62
+    /**
63
+     * @return string
64
+     */
65
+    public function getSql() {
66
+        return $this->sql;
67
+    }
68 68
 
69
-	/**
70
-	 * @return float
71
-	 */
72
-	public function getStart() {
73
-		return $this->start;
74
-	}
69
+    /**
70
+     * @return float
71
+     */
72
+    public function getStart() {
73
+        return $this->start;
74
+    }
75 75
 	
76
-	/**
77
-	 * @return float
78
-	 */
79
-	public function getDuration() {
80
-		return $this->end - $this->start;
81
-	}
76
+    /**
77
+     * @return float
78
+     */
79
+    public function getDuration() {
80
+        return $this->end - $this->start;
81
+    }
82 82
 
83
-	public function getStartTime() {
84
-		return $this->start;
85
-	}
83
+    public function getStartTime() {
84
+        return $this->start;
85
+    }
86 86
 
87
-	public function getStacktrace() {
88
-		return $this->stack;
89
-	}
87
+    public function getStacktrace() {
88
+        return $this->stack;
89
+    }
90 90
 }
Please login to merge, or discard this patch.
lib/private/App/AppStore/Version/VersionParser.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
 	 * @return bool
33 33
 	 */
34 34
 	private function isValidVersionString($versionString) {
35
-		return (bool)preg_match('/^[0-9.]+$/', $versionString);
35
+		return (bool) preg_match('/^[0-9.]+$/', $versionString);
36 36
 	}
37 37
 
38 38
 	/**
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -11,56 +11,56 @@
 block discarded – undo
11 11
  * @package OC\App\AppStore
12 12
  */
13 13
 class VersionParser {
14
-	/**
15
-	 * @param string $versionString
16
-	 * @return bool
17
-	 */
18
-	private function isValidVersionString($versionString) {
19
-		return (bool)preg_match('/^[0-9.]+$/', $versionString);
20
-	}
14
+    /**
15
+     * @param string $versionString
16
+     * @return bool
17
+     */
18
+    private function isValidVersionString($versionString) {
19
+        return (bool)preg_match('/^[0-9.]+$/', $versionString);
20
+    }
21 21
 
22
-	/**
23
-	 * Returns the version for a version string
24
-	 *
25
-	 * @param string $versionSpec
26
-	 * @return Version
27
-	 * @throws \Exception If the version cannot be parsed
28
-	 */
29
-	public function getVersion($versionSpec) {
30
-		// * indicates that the version is compatible with all versions
31
-		if ($versionSpec === '*') {
32
-			return new Version('', '');
33
-		}
22
+    /**
23
+     * Returns the version for a version string
24
+     *
25
+     * @param string $versionSpec
26
+     * @return Version
27
+     * @throws \Exception If the version cannot be parsed
28
+     */
29
+    public function getVersion($versionSpec) {
30
+        // * indicates that the version is compatible with all versions
31
+        if ($versionSpec === '*') {
32
+            return new Version('', '');
33
+        }
34 34
 
35
-		// Count the amount of =, if it is one then it's either maximum or minimum
36
-		// version. If it is two then it is maximum and minimum.
37
-		$versionElements = explode(' ', $versionSpec);
38
-		$firstVersion = $versionElements[0] ?? '';
39
-		$firstVersionNumber = substr($firstVersion, 2);
40
-		$secondVersion = $versionElements[1] ?? '';
41
-		$secondVersionNumber = substr($secondVersion, 2);
35
+        // Count the amount of =, if it is one then it's either maximum or minimum
36
+        // version. If it is two then it is maximum and minimum.
37
+        $versionElements = explode(' ', $versionSpec);
38
+        $firstVersion = $versionElements[0] ?? '';
39
+        $firstVersionNumber = substr($firstVersion, 2);
40
+        $secondVersion = $versionElements[1] ?? '';
41
+        $secondVersionNumber = substr($secondVersion, 2);
42 42
 
43
-		switch (count($versionElements)) {
44
-			case 1:
45
-				if (!$this->isValidVersionString($firstVersionNumber)) {
46
-					break;
47
-				}
48
-				if (str_starts_with($firstVersion, '>')) {
49
-					return new Version($firstVersionNumber, '');
50
-				}
51
-				return new Version('', $firstVersionNumber);
52
-			case 2:
53
-				if (!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) {
54
-					break;
55
-				}
56
-				return new Version($firstVersionNumber, $secondVersionNumber);
57
-		}
43
+        switch (count($versionElements)) {
44
+            case 1:
45
+                if (!$this->isValidVersionString($firstVersionNumber)) {
46
+                    break;
47
+                }
48
+                if (str_starts_with($firstVersion, '>')) {
49
+                    return new Version($firstVersionNumber, '');
50
+                }
51
+                return new Version('', $firstVersionNumber);
52
+            case 2:
53
+                if (!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) {
54
+                    break;
55
+                }
56
+                return new Version($firstVersionNumber, $secondVersionNumber);
57
+        }
58 58
 
59
-		throw new \Exception(
60
-			sprintf(
61
-				'Version cannot be parsed: %s',
62
-				$versionSpec
63
-			)
64
-		);
65
-	}
59
+        throw new \Exception(
60
+            sprintf(
61
+                'Version cannot be parsed: %s',
62
+                $versionSpec
63
+            )
64
+        );
65
+    }
66 66
 }
Please login to merge, or discard this patch.
lib/private/DB/MigrationException.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,17 +24,17 @@
 block discarded – undo
24 24
 namespace OC\DB;
25 25
 
26 26
 class MigrationException extends \Exception {
27
-	private $table;
27
+    private $table;
28 28
 
29
-	public function __construct($table, $message) {
30
-		$this->table = $table;
31
-		parent::__construct($message);
32
-	}
29
+    public function __construct($table, $message) {
30
+        $this->table = $table;
31
+        parent::__construct($message);
32
+    }
33 33
 
34
-	/**
35
-	 * @return string
36
-	 */
37
-	public function getTable() {
38
-		return $this->table;
39
-	}
34
+    /**
35
+     * @return string
36
+     */
37
+    public function getTable() {
38
+        return $this->table;
39
+    }
40 40
 }
Please login to merge, or discard this patch.
lib/private/Command/FileAccess.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -25,12 +25,12 @@
 block discarded – undo
25 25
 use OCP\IUser;
26 26
 
27 27
 trait FileAccess {
28
-	protected function setupFS(IUser $user) {
29
-		\OC_Util::setupFS($user->getUID());
30
-	}
28
+    protected function setupFS(IUser $user) {
29
+        \OC_Util::setupFS($user->getUID());
30
+    }
31 31
 
32
-	protected function getUserFolder(IUser $user) {
33
-		$this->setupFS($user);
34
-		return \OC::$server->getUserFolder($user->getUID());
35
-	}
32
+    protected function getUserFolder(IUser $user) {
33
+        $this->setupFS($user);
34
+        return \OC::$server->getUserFolder($user->getUID());
35
+    }
36 36
 }
Please login to merge, or discard this patch.
lib/private/Group/Backend.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
 	 * compared with \OC\Group\Backend::CREATE_GROUP etc.
68 68
 	 */
69 69
 	public function implementsActions($actions) {
70
-		return (bool)($this->getSupportedActions() & $actions);
70
+		return (bool) ($this->getSupportedActions() & $actions);
71 71
 	}
72 72
 
73 73
 	/**
Please login to merge, or discard this patch.
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -11,107 +11,107 @@
 block discarded – undo
11 11
  * Abstract base class for user management
12 12
  */
13 13
 abstract class Backend implements \OCP\GroupInterface {
14
-	/**
15
-	 * error code for functions not provided by the group backend
16
-	 */
17
-	public const NOT_IMPLEMENTED = -501;
14
+    /**
15
+     * error code for functions not provided by the group backend
16
+     */
17
+    public const NOT_IMPLEMENTED = -501;
18 18
 
19
-	protected $possibleActions = [
20
-		self::CREATE_GROUP => 'createGroup',
21
-		self::DELETE_GROUP => 'deleteGroup',
22
-		self::ADD_TO_GROUP => 'addToGroup',
23
-		self::REMOVE_FROM_GOUP => 'removeFromGroup',
24
-		self::COUNT_USERS => 'countUsersInGroup',
25
-		self::GROUP_DETAILS => 'getGroupDetails',
26
-		self::IS_ADMIN => 'isAdmin',
27
-	];
19
+    protected $possibleActions = [
20
+        self::CREATE_GROUP => 'createGroup',
21
+        self::DELETE_GROUP => 'deleteGroup',
22
+        self::ADD_TO_GROUP => 'addToGroup',
23
+        self::REMOVE_FROM_GOUP => 'removeFromGroup',
24
+        self::COUNT_USERS => 'countUsersInGroup',
25
+        self::GROUP_DETAILS => 'getGroupDetails',
26
+        self::IS_ADMIN => 'isAdmin',
27
+    ];
28 28
 
29
-	/**
30
-	 * Get all supported actions
31
-	 * @return int bitwise-or'ed actions
32
-	 *
33
-	 * Returns the supported actions as int to be
34
-	 * compared with \OC\Group\Backend::CREATE_GROUP etc.
35
-	 */
36
-	public function getSupportedActions() {
37
-		$actions = 0;
38
-		foreach ($this->possibleActions as $action => $methodName) {
39
-			if (method_exists($this, $methodName)) {
40
-				$actions |= $action;
41
-			}
42
-		}
29
+    /**
30
+     * Get all supported actions
31
+     * @return int bitwise-or'ed actions
32
+     *
33
+     * Returns the supported actions as int to be
34
+     * compared with \OC\Group\Backend::CREATE_GROUP etc.
35
+     */
36
+    public function getSupportedActions() {
37
+        $actions = 0;
38
+        foreach ($this->possibleActions as $action => $methodName) {
39
+            if (method_exists($this, $methodName)) {
40
+                $actions |= $action;
41
+            }
42
+        }
43 43
 
44
-		return $actions;
45
-	}
44
+        return $actions;
45
+    }
46 46
 
47
-	/**
48
-	 * Check if backend implements actions
49
-	 * @param int $actions bitwise-or'ed actions
50
-	 * @return bool
51
-	 *
52
-	 * Returns the supported actions as int to be
53
-	 * compared with \OC\Group\Backend::CREATE_GROUP etc.
54
-	 */
55
-	public function implementsActions($actions) {
56
-		return (bool)($this->getSupportedActions() & $actions);
57
-	}
47
+    /**
48
+     * Check if backend implements actions
49
+     * @param int $actions bitwise-or'ed actions
50
+     * @return bool
51
+     *
52
+     * Returns the supported actions as int to be
53
+     * compared with \OC\Group\Backend::CREATE_GROUP etc.
54
+     */
55
+    public function implementsActions($actions) {
56
+        return (bool)($this->getSupportedActions() & $actions);
57
+    }
58 58
 
59
-	/**
60
-	 * is user in group?
61
-	 * @param string $uid uid of the user
62
-	 * @param string $gid gid of the group
63
-	 * @return bool
64
-	 *
65
-	 * Checks whether the user is member of a group or not.
66
-	 */
67
-	public function inGroup($uid, $gid) {
68
-		return in_array($gid, $this->getUserGroups($uid));
69
-	}
59
+    /**
60
+     * is user in group?
61
+     * @param string $uid uid of the user
62
+     * @param string $gid gid of the group
63
+     * @return bool
64
+     *
65
+     * Checks whether the user is member of a group or not.
66
+     */
67
+    public function inGroup($uid, $gid) {
68
+        return in_array($gid, $this->getUserGroups($uid));
69
+    }
70 70
 
71
-	/**
72
-	 * Get all groups a user belongs to
73
-	 * @param string $uid Name of the user
74
-	 * @return list<string> an array of group names
75
-	 *
76
-	 * This function fetches all groups a user belongs to. It does not check
77
-	 * if the user exists at all.
78
-	 */
79
-	public function getUserGroups($uid) {
80
-		return [];
81
-	}
71
+    /**
72
+     * Get all groups a user belongs to
73
+     * @param string $uid Name of the user
74
+     * @return list<string> an array of group names
75
+     *
76
+     * This function fetches all groups a user belongs to. It does not check
77
+     * if the user exists at all.
78
+     */
79
+    public function getUserGroups($uid) {
80
+        return [];
81
+    }
82 82
 
83
-	/**
84
-	 * get a list of all groups
85
-	 * @param string $search
86
-	 * @param int $limit
87
-	 * @param int $offset
88
-	 * @return array an array of group names
89
-	 *
90
-	 * Returns a list with all groups
91
-	 */
83
+    /**
84
+     * get a list of all groups
85
+     * @param string $search
86
+     * @param int $limit
87
+     * @param int $offset
88
+     * @return array an array of group names
89
+     *
90
+     * Returns a list with all groups
91
+     */
92 92
 
93
-	public function getGroups($search = '', $limit = -1, $offset = 0) {
94
-		return [];
95
-	}
93
+    public function getGroups($search = '', $limit = -1, $offset = 0) {
94
+        return [];
95
+    }
96 96
 
97
-	/**
98
-	 * check if a group exists
99
-	 * @param string $gid
100
-	 * @return bool
101
-	 */
102
-	public function groupExists($gid) {
103
-		return in_array($gid, $this->getGroups($gid, 1));
104
-	}
97
+    /**
98
+     * check if a group exists
99
+     * @param string $gid
100
+     * @return bool
101
+     */
102
+    public function groupExists($gid) {
103
+        return in_array($gid, $this->getGroups($gid, 1));
104
+    }
105 105
 
106
-	/**
107
-	 * get a list of all users in a group
108
-	 * @param string $gid
109
-	 * @param string $search
110
-	 * @param int $limit
111
-	 * @param int $offset
112
-	 * @return array<int,string> an array of user ids
113
-	 */
114
-	public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
115
-		return [];
116
-	}
106
+    /**
107
+     * get a list of all users in a group
108
+     * @param string $gid
109
+     * @param string $search
110
+     * @param int $limit
111
+     * @param int $offset
112
+     * @return array<int,string> an array of user ids
113
+     */
114
+    public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
115
+        return [];
116
+    }
117 117
 }
Please login to merge, or discard this patch.
lib/private/Activity/EventMerger.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 
134 134
 		// Check that all parameters from $event exist in $previousEvent
135 135
 		foreach ($params1 as $key => $parameter) {
136
-			if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
136
+			if (preg_match('/^'.$mergeParameter.'(\d+)?$/', $key)) {
137 137
 				if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) {
138 138
 					$combined++;
139
-					$params[$mergeParameter . $combined] = $parameter;
139
+					$params[$mergeParameter.$combined] = $parameter;
140 140
 				}
141 141
 				continue;
142 142
 			}
@@ -151,10 +151,10 @@  discard block
 block discarded – undo
151 151
 
152 152
 		// Check that all parameters from $previousEvent exist in $event
153 153
 		foreach ($params2 as $key => $parameter) {
154
-			if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
154
+			if (preg_match('/^'.$mergeParameter.'(\d+)?$/', $key)) {
155 155
 				if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) {
156 156
 					$combined++;
157
-					$params[$mergeParameter . $combined] = $parameter;
157
+					$params[$mergeParameter.$combined] = $parameter;
158 158
 				}
159 159
 				continue;
160 160
 			}
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 */
179 179
 	protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) {
180 180
 		foreach ($parameters as $key => $param) {
181
-			if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
181
+			if (preg_match('/^'.$mergeParameter.'(\d+)?$/', $key)) {
182 182
 				if ($param === $parameter) {
183 183
 					return true;
184 184
 				}
@@ -196,30 +196,30 @@  discard block
 block discarded – undo
196 196
 	protected function getExtendedSubject($subject, $parameter, $counter) {
197 197
 		switch ($counter) {
198 198
 			case 1:
199
-				$replacement = '{' . $parameter . '1}';
199
+				$replacement = '{'.$parameter.'1}';
200 200
 				break;
201 201
 			case 2:
202 202
 				$replacement = $this->l10n->t(
203 203
 					'%1$s and %2$s',
204
-					['{' . $parameter . '2}', '{' . $parameter . '1}']
204
+					['{'.$parameter.'2}', '{'.$parameter.'1}']
205 205
 				);
206 206
 				break;
207 207
 			case 3:
208 208
 				$replacement = $this->l10n->t(
209 209
 					'%1$s, %2$s and %3$s',
210
-					['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
210
+					['{'.$parameter.'3}', '{'.$parameter.'2}', '{'.$parameter.'1}']
211 211
 				);
212 212
 				break;
213 213
 			case 4:
214 214
 				$replacement = $this->l10n->t(
215 215
 					'%1$s, %2$s, %3$s and %4$s',
216
-					['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
216
+					['{'.$parameter.'4}', '{'.$parameter.'3}', '{'.$parameter.'2}', '{'.$parameter.'1}']
217 217
 				);
218 218
 				break;
219 219
 			case 5:
220 220
 				$replacement = $this->l10n->t(
221 221
 					'%1$s, %2$s, %3$s, %4$s and %5$s',
222
-					['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
222
+					['{'.$parameter.'5}', '{'.$parameter.'4}', '{'.$parameter.'3}', '{'.$parameter.'2}', '{'.$parameter.'1}']
223 223
 				);
224 224
 				break;
225 225
 			default:
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 		}
228 228
 
229 229
 		return str_replace(
230
-			'{' . $parameter . '}',
230
+			'{'.$parameter.'}',
231 231
 			$replacement,
232 232
 			$subject
233 233
 		);
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	protected function generateParsedSubject($subject, $parameters) {
242 242
 		$placeholders = $replacements = [];
243 243
 		foreach ($parameters as $placeholder => $parameter) {
244
-			$placeholders[] = '{' . $placeholder . '}';
244
+			$placeholders[] = '{'.$placeholder.'}';
245 245
 			if ($parameter['type'] === 'file') {
246 246
 				$replacements[] = trim($parameter['path'], '/');
247 247
 			} elseif (isset($parameter['name'])) {
Please login to merge, or discard this patch.
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -10,231 +10,231 @@
 block discarded – undo
10 10
 use OCP\IL10N;
11 11
 
12 12
 class EventMerger implements IEventMerger {
13
-	/** @var IL10N */
14
-	protected $l10n;
15
-
16
-	/**
17
-	 * @param IL10N $l10n
18
-	 */
19
-	public function __construct(IL10N $l10n) {
20
-		$this->l10n = $l10n;
21
-	}
22
-
23
-	/**
24
-	 * Combines two events when possible to have grouping:
25
-	 *
26
-	 * Example1: Two events with subject '{user} created {file}' and
27
-	 * $mergeParameter file with different file and same user will be merged
28
-	 * to '{user} created {file1} and {file2}' and the childEvent on the return
29
-	 * will be set, if the events have been merged.
30
-	 *
31
-	 * Example2: Two events with subject '{user} created {file}' and
32
-	 * $mergeParameter file with same file and same user will be merged to
33
-	 * '{user} created {file1}' and the childEvent on the return will be set, if
34
-	 * the events have been merged.
35
-	 *
36
-	 * The following requirements have to be met, in order to be merged:
37
-	 * - Both events need to have the same `getApp()`
38
-	 * - Both events must not have a message `getMessage()`
39
-	 * - Both events need to have the same subject `getSubject()`
40
-	 * - Both events need to have the same object type `getObjectType()`
41
-	 * - The time difference between both events must not be bigger then 3 hours
42
-	 * - Only up to 5 events can be merged.
43
-	 * - All parameters apart from such starting with $mergeParameter must be
44
-	 *   the same for both events.
45
-	 *
46
-	 * @param string $mergeParameter
47
-	 * @param IEvent $event
48
-	 * @param IEvent|null $previousEvent
49
-	 * @return IEvent
50
-	 */
51
-	public function mergeEvents($mergeParameter, IEvent $event, ?IEvent $previousEvent = null) {
52
-		// No second event => can not combine
53
-		if (!$previousEvent instanceof IEvent) {
54
-			return $event;
55
-		}
56
-
57
-		// Different app => can not combine
58
-		if ($event->getApp() !== $previousEvent->getApp()) {
59
-			return $event;
60
-		}
61
-
62
-		// Message is set => can not combine
63
-		if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') {
64
-			return $event;
65
-		}
66
-
67
-		// Different subject => can not combine
68
-		if ($event->getSubject() !== $previousEvent->getSubject()) {
69
-			return $event;
70
-		}
71
-
72
-		// Different object type => can not combine
73
-		if ($event->getObjectType() !== $previousEvent->getObjectType()) {
74
-			return $event;
75
-		}
76
-
77
-		// More than 3 hours difference => can not combine
78
-		if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) {
79
-			return $event;
80
-		}
81
-
82
-		// Other parameters are not the same => can not combine
83
-		try {
84
-			[$combined, $parameters] = $this->combineParameters($mergeParameter, $event, $previousEvent);
85
-		} catch (\UnexpectedValueException $e) {
86
-			return $event;
87
-		}
88
-
89
-		try {
90
-			$newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined);
91
-			$parsedSubject = $this->generateParsedSubject($newSubject, $parameters);
92
-
93
-			$event->setRichSubject($newSubject, $parameters)
94
-				->setParsedSubject($parsedSubject)
95
-				->setChildEvent($previousEvent)
96
-				->setTimestamp(max($event->getTimestamp(), $previousEvent->getTimestamp()));
97
-		} catch (\UnexpectedValueException $e) {
98
-			return $event;
99
-		}
100
-
101
-		return $event;
102
-	}
103
-
104
-	/**
105
-	 * @param string $mergeParameter
106
-	 * @param IEvent $event
107
-	 * @param IEvent $previousEvent
108
-	 * @return array
109
-	 * @throws \UnexpectedValueException
110
-	 */
111
-	protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) {
112
-		$params1 = $event->getRichSubjectParameters();
113
-		$params2 = $previousEvent->getRichSubjectParameters();
114
-		$params = [];
115
-
116
-		$combined = 0;
117
-
118
-		// Check that all parameters from $event exist in $previousEvent
119
-		foreach ($params1 as $key => $parameter) {
120
-			if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
121
-				if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) {
122
-					$combined++;
123
-					$params[$mergeParameter . $combined] = $parameter;
124
-				}
125
-				continue;
126
-			}
127
-
128
-			if (!isset($params2[$key]) || $params2[$key] !== $parameter) {
129
-				// Parameter missing on $previousEvent or different => can not combine
130
-				throw new \UnexpectedValueException();
131
-			}
132
-
133
-			$params[$key] = $parameter;
134
-		}
135
-
136
-		// Check that all parameters from $previousEvent exist in $event
137
-		foreach ($params2 as $key => $parameter) {
138
-			if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
139
-				if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) {
140
-					$combined++;
141
-					$params[$mergeParameter . $combined] = $parameter;
142
-				}
143
-				continue;
144
-			}
145
-
146
-			if (!isset($params1[$key]) || $params1[$key] !== $parameter) {
147
-				// Parameter missing on $event or different => can not combine
148
-				throw new \UnexpectedValueException();
149
-			}
150
-
151
-			$params[$key] = $parameter;
152
-		}
153
-
154
-		return [$combined, $params];
155
-	}
156
-
157
-	/**
158
-	 * @param array[] $parameters
159
-	 * @param string $mergeParameter
160
-	 * @param array $parameter
161
-	 * @return bool
162
-	 */
163
-	protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) {
164
-		foreach ($parameters as $key => $param) {
165
-			if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
166
-				if ($param === $parameter) {
167
-					return true;
168
-				}
169
-			}
170
-		}
171
-		return false;
172
-	}
173
-
174
-	/**
175
-	 * @param string $subject
176
-	 * @param string $parameter
177
-	 * @param int $counter
178
-	 * @return mixed
179
-	 */
180
-	protected function getExtendedSubject($subject, $parameter, $counter) {
181
-		switch ($counter) {
182
-			case 1:
183
-				$replacement = '{' . $parameter . '1}';
184
-				break;
185
-			case 2:
186
-				$replacement = $this->l10n->t(
187
-					'%1$s and %2$s',
188
-					['{' . $parameter . '2}', '{' . $parameter . '1}']
189
-				);
190
-				break;
191
-			case 3:
192
-				$replacement = $this->l10n->t(
193
-					'%1$s, %2$s and %3$s',
194
-					['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
195
-				);
196
-				break;
197
-			case 4:
198
-				$replacement = $this->l10n->t(
199
-					'%1$s, %2$s, %3$s and %4$s',
200
-					['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
201
-				);
202
-				break;
203
-			case 5:
204
-				$replacement = $this->l10n->t(
205
-					'%1$s, %2$s, %3$s, %4$s and %5$s',
206
-					['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
207
-				);
208
-				break;
209
-			default:
210
-				throw new \UnexpectedValueException();
211
-		}
212
-
213
-		return str_replace(
214
-			'{' . $parameter . '}',
215
-			$replacement,
216
-			$subject
217
-		);
218
-	}
219
-
220
-	/**
221
-	 * @param string $subject
222
-	 * @param array[] $parameters
223
-	 * @return string
224
-	 */
225
-	protected function generateParsedSubject($subject, $parameters) {
226
-		$placeholders = $replacements = [];
227
-		foreach ($parameters as $placeholder => $parameter) {
228
-			$placeholders[] = '{' . $placeholder . '}';
229
-			if ($parameter['type'] === 'file') {
230
-				$replacements[] = trim($parameter['path'], '/');
231
-			} elseif (isset($parameter['name'])) {
232
-				$replacements[] = $parameter['name'];
233
-			} else {
234
-				$replacements[] = $parameter['id'];
235
-			}
236
-		}
237
-
238
-		return str_replace($placeholders, $replacements, $subject);
239
-	}
13
+    /** @var IL10N */
14
+    protected $l10n;
15
+
16
+    /**
17
+     * @param IL10N $l10n
18
+     */
19
+    public function __construct(IL10N $l10n) {
20
+        $this->l10n = $l10n;
21
+    }
22
+
23
+    /**
24
+     * Combines two events when possible to have grouping:
25
+     *
26
+     * Example1: Two events with subject '{user} created {file}' and
27
+     * $mergeParameter file with different file and same user will be merged
28
+     * to '{user} created {file1} and {file2}' and the childEvent on the return
29
+     * will be set, if the events have been merged.
30
+     *
31
+     * Example2: Two events with subject '{user} created {file}' and
32
+     * $mergeParameter file with same file and same user will be merged to
33
+     * '{user} created {file1}' and the childEvent on the return will be set, if
34
+     * the events have been merged.
35
+     *
36
+     * The following requirements have to be met, in order to be merged:
37
+     * - Both events need to have the same `getApp()`
38
+     * - Both events must not have a message `getMessage()`
39
+     * - Both events need to have the same subject `getSubject()`
40
+     * - Both events need to have the same object type `getObjectType()`
41
+     * - The time difference between both events must not be bigger then 3 hours
42
+     * - Only up to 5 events can be merged.
43
+     * - All parameters apart from such starting with $mergeParameter must be
44
+     *   the same for both events.
45
+     *
46
+     * @param string $mergeParameter
47
+     * @param IEvent $event
48
+     * @param IEvent|null $previousEvent
49
+     * @return IEvent
50
+     */
51
+    public function mergeEvents($mergeParameter, IEvent $event, ?IEvent $previousEvent = null) {
52
+        // No second event => can not combine
53
+        if (!$previousEvent instanceof IEvent) {
54
+            return $event;
55
+        }
56
+
57
+        // Different app => can not combine
58
+        if ($event->getApp() !== $previousEvent->getApp()) {
59
+            return $event;
60
+        }
61
+
62
+        // Message is set => can not combine
63
+        if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') {
64
+            return $event;
65
+        }
66
+
67
+        // Different subject => can not combine
68
+        if ($event->getSubject() !== $previousEvent->getSubject()) {
69
+            return $event;
70
+        }
71
+
72
+        // Different object type => can not combine
73
+        if ($event->getObjectType() !== $previousEvent->getObjectType()) {
74
+            return $event;
75
+        }
76
+
77
+        // More than 3 hours difference => can not combine
78
+        if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) {
79
+            return $event;
80
+        }
81
+
82
+        // Other parameters are not the same => can not combine
83
+        try {
84
+            [$combined, $parameters] = $this->combineParameters($mergeParameter, $event, $previousEvent);
85
+        } catch (\UnexpectedValueException $e) {
86
+            return $event;
87
+        }
88
+
89
+        try {
90
+            $newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined);
91
+            $parsedSubject = $this->generateParsedSubject($newSubject, $parameters);
92
+
93
+            $event->setRichSubject($newSubject, $parameters)
94
+                ->setParsedSubject($parsedSubject)
95
+                ->setChildEvent($previousEvent)
96
+                ->setTimestamp(max($event->getTimestamp(), $previousEvent->getTimestamp()));
97
+        } catch (\UnexpectedValueException $e) {
98
+            return $event;
99
+        }
100
+
101
+        return $event;
102
+    }
103
+
104
+    /**
105
+     * @param string $mergeParameter
106
+     * @param IEvent $event
107
+     * @param IEvent $previousEvent
108
+     * @return array
109
+     * @throws \UnexpectedValueException
110
+     */
111
+    protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) {
112
+        $params1 = $event->getRichSubjectParameters();
113
+        $params2 = $previousEvent->getRichSubjectParameters();
114
+        $params = [];
115
+
116
+        $combined = 0;
117
+
118
+        // Check that all parameters from $event exist in $previousEvent
119
+        foreach ($params1 as $key => $parameter) {
120
+            if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
121
+                if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) {
122
+                    $combined++;
123
+                    $params[$mergeParameter . $combined] = $parameter;
124
+                }
125
+                continue;
126
+            }
127
+
128
+            if (!isset($params2[$key]) || $params2[$key] !== $parameter) {
129
+                // Parameter missing on $previousEvent or different => can not combine
130
+                throw new \UnexpectedValueException();
131
+            }
132
+
133
+            $params[$key] = $parameter;
134
+        }
135
+
136
+        // Check that all parameters from $previousEvent exist in $event
137
+        foreach ($params2 as $key => $parameter) {
138
+            if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
139
+                if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) {
140
+                    $combined++;
141
+                    $params[$mergeParameter . $combined] = $parameter;
142
+                }
143
+                continue;
144
+            }
145
+
146
+            if (!isset($params1[$key]) || $params1[$key] !== $parameter) {
147
+                // Parameter missing on $event or different => can not combine
148
+                throw new \UnexpectedValueException();
149
+            }
150
+
151
+            $params[$key] = $parameter;
152
+        }
153
+
154
+        return [$combined, $params];
155
+    }
156
+
157
+    /**
158
+     * @param array[] $parameters
159
+     * @param string $mergeParameter
160
+     * @param array $parameter
161
+     * @return bool
162
+     */
163
+    protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) {
164
+        foreach ($parameters as $key => $param) {
165
+            if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) {
166
+                if ($param === $parameter) {
167
+                    return true;
168
+                }
169
+            }
170
+        }
171
+        return false;
172
+    }
173
+
174
+    /**
175
+     * @param string $subject
176
+     * @param string $parameter
177
+     * @param int $counter
178
+     * @return mixed
179
+     */
180
+    protected function getExtendedSubject($subject, $parameter, $counter) {
181
+        switch ($counter) {
182
+            case 1:
183
+                $replacement = '{' . $parameter . '1}';
184
+                break;
185
+            case 2:
186
+                $replacement = $this->l10n->t(
187
+                    '%1$s and %2$s',
188
+                    ['{' . $parameter . '2}', '{' . $parameter . '1}']
189
+                );
190
+                break;
191
+            case 3:
192
+                $replacement = $this->l10n->t(
193
+                    '%1$s, %2$s and %3$s',
194
+                    ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
195
+                );
196
+                break;
197
+            case 4:
198
+                $replacement = $this->l10n->t(
199
+                    '%1$s, %2$s, %3$s and %4$s',
200
+                    ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
201
+                );
202
+                break;
203
+            case 5:
204
+                $replacement = $this->l10n->t(
205
+                    '%1$s, %2$s, %3$s, %4$s and %5$s',
206
+                    ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}']
207
+                );
208
+                break;
209
+            default:
210
+                throw new \UnexpectedValueException();
211
+        }
212
+
213
+        return str_replace(
214
+            '{' . $parameter . '}',
215
+            $replacement,
216
+            $subject
217
+        );
218
+    }
219
+
220
+    /**
221
+     * @param string $subject
222
+     * @param array[] $parameters
223
+     * @return string
224
+     */
225
+    protected function generateParsedSubject($subject, $parameters) {
226
+        $placeholders = $replacements = [];
227
+        foreach ($parameters as $placeholder => $parameter) {
228
+            $placeholders[] = '{' . $placeholder . '}';
229
+            if ($parameter['type'] === 'file') {
230
+                $replacements[] = trim($parameter['path'], '/');
231
+            } elseif (isset($parameter['name'])) {
232
+                $replacements[] = $parameter['name'];
233
+            } else {
234
+                $replacements[] = $parameter['id'];
235
+            }
236
+        }
237
+
238
+        return str_replace($placeholders, $replacements, $subject);
239
+    }
240 240
 }
Please login to merge, or discard this patch.