@@ -185,24 +185,15 @@ public function setMessage($message, $maxLength = self::MAX_MESSAGE_LENGTH): ICo
185185 * returns an array containing mentions that are included in the comment
186186 *
187187 * @return array each mention provides a 'type' and an 'id', see example below
188+ * @psalm-return list<array{type: 'guest'|'email'|'federated_group'|'group'|'federated_team'|'team'|'federated_user'|'user', id: non-empty-lowercase-string}>
189+ * @since 30.0.2 Type 'email' is supported
190+ * @since 29.0.0 Types 'federated_group', 'federated_team', 'team' and 'federated_user' are supported
191+ * @since 23.0.0 Type 'group' is supported
192+ * @since 17.0.0 Type 'guest' is supported
188193 * @since 11.0.0
189- *
190- * The return array looks like:
191- * [
192- * [
193- * 'type' => 'user',
194- * 'id' => 'citizen4'
195- * ],
196- * [
197- * 'type' => 'group',
198- * 'id' => 'media'
199- * ],
200- * …
201- * ]
202- *
203194 */
204195 public function getMentions (): array {
205- $ ok = preg_match_all ("/\B(?<![^a-z0-9_\-@\.\'\s])@( \"guest\/[a-f0-9]+ \"| \"(?:federated_)?(?:group|team|user){1}\/[a-z0-9_\-@\.\' \/:]+ \"| \"[a-z0-9_\-@\.\' ]+ \"|[a-z0-9_\-@\.\']+)/i " , $ this ->getMessage (), $ mentions );
196+ $ ok = preg_match_all ("/\B(?<![^a-z0-9_\-@\.\'\s])@( \"( guest|email) \/[a-f0-9]+ \"| \"(?:federated_)?(?:group|team|user){1}\/[a-z0-9_\-@\.\' \/:]+ \"| \"[a-z0-9_\-@\.\' ]+ \"|[a-z0-9_\-@\.\']+)/i " , $ this ->getMessage (), $ mentions );
206197 if (!$ ok || !isset ($ mentions [0 ])) {
207198 return [];
208199 }
@@ -213,20 +204,35 @@ public function getMentions(): array {
213204 $ result = [];
214205 foreach ($ mentionIds as $ mentionId ) {
215206 // Cut-off the @ and remove wrapping double-quotes
207+ /** @var non-empty-lowercase-string $cleanId */
216208 $ cleanId = trim (substr ($ mentionId , 1 ), '" ' );
217209
218210 if (str_starts_with ($ cleanId , 'guest/ ' )) {
219211 $ result [] = ['type ' => 'guest ' , 'id ' => $ cleanId ];
212+ } elseif (str_starts_with ($ cleanId , 'email/ ' )) {
213+ /** @var non-empty-lowercase-string $cleanId */
214+ $ cleanId = substr ($ cleanId , 6 );
215+ $ result [] = ['type ' => 'email ' , 'id ' => $ cleanId ];
220216 } elseif (str_starts_with ($ cleanId , 'federated_group/ ' )) {
221- $ result [] = ['type ' => 'federated_group ' , 'id ' => substr ($ cleanId , 16 )];
217+ /** @var non-empty-lowercase-string $cleanId */
218+ $ cleanId = substr ($ cleanId , 16 );
219+ $ result [] = ['type ' => 'federated_group ' , 'id ' => $ cleanId ];
222220 } elseif (str_starts_with ($ cleanId , 'group/ ' )) {
223- $ result [] = ['type ' => 'group ' , 'id ' => substr ($ cleanId , 6 )];
221+ /** @var non-empty-lowercase-string $cleanId */
222+ $ cleanId = substr ($ cleanId , 6 );
223+ $ result [] = ['type ' => 'group ' , 'id ' => $ cleanId ];
224224 } elseif (str_starts_with ($ cleanId , 'federated_team/ ' )) {
225- $ result [] = ['type ' => 'federated_team ' , 'id ' => substr ($ cleanId , 15 )];
225+ /** @var non-empty-lowercase-string $cleanId */
226+ $ cleanId = substr ($ cleanId , 15 );
227+ $ result [] = ['type ' => 'federated_team ' , 'id ' => $ cleanId ];
226228 } elseif (str_starts_with ($ cleanId , 'team/ ' )) {
227- $ result [] = ['type ' => 'team ' , 'id ' => substr ($ cleanId , 5 )];
229+ /** @var non-empty-lowercase-string $cleanId */
230+ $ cleanId = substr ($ cleanId , 5 );
231+ $ result [] = ['type ' => 'team ' , 'id ' => $ cleanId ];
228232 } elseif (str_starts_with ($ cleanId , 'federated_user/ ' )) {
229- $ result [] = ['type ' => 'federated_user ' , 'id ' => substr ($ cleanId , 15 )];
233+ /** @var non-empty-lowercase-string $cleanId */
234+ $ cleanId = substr ($ cleanId , 15 );
235+ $ result [] = ['type ' => 'federated_user ' , 'id ' => $ cleanId ];
230236 } else {
231237 $ result [] = ['type ' => 'user ' , 'id ' => $ cleanId ];
232238 }
0 commit comments