diff options
author | Joas Schilling <coding@schilljs.com> | 2024-10-17 12:37:14 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2024-10-18 06:21:01 +0000 |
commit | 570428e4e694114529b99e137290870b208751de (patch) | |
tree | 3ae2ac49fbc33dae11e89eb5aa75cd10704ede9d | |
parent | bd30a7ac21bf63cfc117f1fe7798d82978a879ee (diff) | |
download | nextcloud-server-570428e4e694114529b99e137290870b208751de.tar.gz nextcloud-server-570428e4e694114529b99e137290870b208751de.zip |
fix(comments): Document supported types and provide psalm typing
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/private/Comments/Comment.php | 40 | ||||
-rw-r--r-- | lib/public/Comments/IComment.php | 19 |
2 files changed, 26 insertions, 33 deletions
diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index 11b7fb03dc1..c240a541156 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -185,21 +185,12 @@ class Comment implements IComment { * returns an array containing mentions that are included in the comment * * @return array each mention provides a 'type' and an 'id', see example below + * @psalm-return list<array{type: 'guest'|'email'|'federated_group'|'group'|'federated_team'|'team'|'federated_user'|'user', id: non-empty-lowercase-string}> + * @since 30.0.2 Type 'email' is supported + * @since 29.0.0 Types 'federated_group', 'federated_team', 'team' and 'federated_user' are supported + * @since 23.0.0 Type 'group' is supported + * @since 17.0.0 Type 'guest' is supported * @since 11.0.0 - * - * The return array looks like: - * [ - * [ - * 'type' => 'user', - * 'id' => 'citizen4' - * ], - * [ - * 'type' => 'group', - * 'id' => 'media' - * ], - * … - * ] - * */ public function getMentions(): array { $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); @@ -213,6 +204,7 @@ class Comment implements IComment { $result = []; foreach ($mentionIds as $mentionId) { // Cut-off the @ and remove wrapping double-quotes + /** @var non-empty-lowercase-string $cleanId */ $cleanId = trim(substr($mentionId, 1), '"'); if (str_starts_with($cleanId, 'guest/')) { @@ -222,15 +214,25 @@ class Comment implements IComment { $cleanId = substr($cleanId, 6); $result[] = ['type' => 'email', 'id' => $cleanId]; } elseif (str_starts_with($cleanId, 'federated_group/')) { - $result[] = ['type' => 'federated_group', 'id' => substr($cleanId, 16)]; + /** @var non-empty-lowercase-string $cleanId */ + $cleanId = substr($cleanId, 16); + $result[] = ['type' => 'federated_group', 'id' => $cleanId]; } elseif (str_starts_with($cleanId, 'group/')) { - $result[] = ['type' => 'group', 'id' => substr($cleanId, 6)]; + /** @var non-empty-lowercase-string $cleanId */ + $cleanId = substr($cleanId, 6); + $result[] = ['type' => 'group', 'id' => $cleanId]; } elseif (str_starts_with($cleanId, 'federated_team/')) { - $result[] = ['type' => 'federated_team', 'id' => substr($cleanId, 15)]; + /** @var non-empty-lowercase-string $cleanId */ + $cleanId = substr($cleanId, 15); + $result[] = ['type' => 'federated_team', 'id' => $cleanId]; } elseif (str_starts_with($cleanId, 'team/')) { - $result[] = ['type' => 'team', 'id' => substr($cleanId, 5)]; + /** @var non-empty-lowercase-string $cleanId */ + $cleanId = substr($cleanId, 5); + $result[] = ['type' => 'team', 'id' => $cleanId]; } elseif (str_starts_with($cleanId, 'federated_user/')) { - $result[] = ['type' => 'federated_user', 'id' => substr($cleanId, 15)]; + /** @var non-empty-lowercase-string $cleanId */ + $cleanId = substr($cleanId, 15); + $result[] = ['type' => 'federated_user', 'id' => $cleanId]; } else { $result[] = ['type' => 'user', 'id' => $cleanId]; } diff --git a/lib/public/Comments/IComment.php b/lib/public/Comments/IComment.php index e37a3ee9757..cdfcf188761 100644 --- a/lib/public/Comments/IComment.php +++ b/lib/public/Comments/IComment.php @@ -124,21 +124,12 @@ interface IComment { * returns an array containing mentions that are included in the comment * * @return array each mention provides a 'type' and an 'id', see example below + * @psalm-return list<array{type: 'guest'|'email'|'federated_group'|'group'|'federated_team'|'team'|'federated_user'|'user', id: non-empty-lowercase-string}> + * @since 30.0.2 Type 'email' is supported + * @since 29.0.0 Types 'federated_group', 'federated_team', 'team' and 'federated_user' are supported + * @since 23.0.0 Type 'group' is supported + * @since 17.0.0 Type 'guest' is supported * @since 11.0.0 - * - * The return array looks like: - * [ - * [ - * 'type' => 'user', - * 'id' => 'citizen4' - * ], - * [ - * 'type' => 'group', - * 'id' => 'media' - * ], - * … - * ] - * */ public function getMentions(); |