Completed
Push — master ( 317cd2...e80d89 )
by Daniel
38:10 queued 20:59
created
apps/comments/lib/Search/Result.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -13,92 +13,92 @@
 block discarded – undo
13 13
  * @deprecated 20.0.0
14 14
  */
15 15
 class Result extends BaseResult {
16
-	/**
17
-	 * @deprecated 20.0.0
18
-	 */
19
-	public $type = 'comment';
20
-	/**
21
-	 * @deprecated 20.0.0
22
-	 */
23
-	public $comment;
24
-	/**
25
-	 * @deprecated 20.0.0
26
-	 */
27
-	public $authorId;
28
-	/**
29
-	 * @deprecated 20.0.0
30
-	 */
31
-	public $path;
32
-	/**
33
-	 * @deprecated 20.0.0
34
-	 */
35
-	public $fileName;
16
+    /**
17
+     * @deprecated 20.0.0
18
+     */
19
+    public $type = 'comment';
20
+    /**
21
+     * @deprecated 20.0.0
22
+     */
23
+    public $comment;
24
+    /**
25
+     * @deprecated 20.0.0
26
+     */
27
+    public $authorId;
28
+    /**
29
+     * @deprecated 20.0.0
30
+     */
31
+    public $path;
32
+    /**
33
+     * @deprecated 20.0.0
34
+     */
35
+    public $fileName;
36 36
 
37
-	/**
38
-	 * @throws NotFoundException
39
-	 * @deprecated 20.0.0
40
-	 */
41
-	public function __construct(
42
-		string $search,
43
-		IComment $comment,
44
-		/**
45
-		 * @deprecated 20.0.0
46
-		 */
47
-		public string $authorName,
48
-		string $path,
49
-	) {
50
-		parent::__construct(
51
-			$comment->getId(),
52
-			$comment->getMessage()
53
-			/* @todo , [link to file] */
54
-		);
37
+    /**
38
+     * @throws NotFoundException
39
+     * @deprecated 20.0.0
40
+     */
41
+    public function __construct(
42
+        string $search,
43
+        IComment $comment,
44
+        /**
45
+         * @deprecated 20.0.0
46
+         */
47
+        public string $authorName,
48
+        string $path,
49
+    ) {
50
+        parent::__construct(
51
+            $comment->getId(),
52
+            $comment->getMessage()
53
+            /* @todo , [link to file] */
54
+        );
55 55
 
56
-		$this->comment = $this->getRelevantMessagePart($comment->getMessage(), $search);
57
-		$this->authorId = $comment->getActorId();
58
-		$this->fileName = basename($path);
59
-		$this->path = $this->getVisiblePath($path);
60
-	}
56
+        $this->comment = $this->getRelevantMessagePart($comment->getMessage(), $search);
57
+        $this->authorId = $comment->getActorId();
58
+        $this->fileName = basename($path);
59
+        $this->path = $this->getVisiblePath($path);
60
+    }
61 61
 
62
-	/**
63
-	 * @throws NotFoundException
64
-	 */
65
-	protected function getVisiblePath(string $path): string {
66
-		$segments = explode('/', trim($path, '/'), 3);
62
+    /**
63
+     * @throws NotFoundException
64
+     */
65
+    protected function getVisiblePath(string $path): string {
66
+        $segments = explode('/', trim($path, '/'), 3);
67 67
 
68
-		if (!isset($segments[2])) {
69
-			throw new NotFoundException('Path not inside visible section');
70
-		}
68
+        if (!isset($segments[2])) {
69
+            throw new NotFoundException('Path not inside visible section');
70
+        }
71 71
 
72
-		return $segments[2];
73
-	}
72
+        return $segments[2];
73
+    }
74 74
 
75
-	/**
76
-	 * @throws NotFoundException
77
-	 */
78
-	protected function getRelevantMessagePart(string $message, string $search): string {
79
-		$start = mb_stripos($message, $search);
80
-		if ($start === false) {
81
-			throw new NotFoundException('Comment section not found');
82
-		}
75
+    /**
76
+     * @throws NotFoundException
77
+     */
78
+    protected function getRelevantMessagePart(string $message, string $search): string {
79
+        $start = mb_stripos($message, $search);
80
+        if ($start === false) {
81
+            throw new NotFoundException('Comment section not found');
82
+        }
83 83
 
84
-		$end = $start + mb_strlen($search);
84
+        $end = $start + mb_strlen($search);
85 85
 
86
-		if ($start <= 25) {
87
-			$start = 0;
88
-			$prefix = '';
89
-		} else {
90
-			$start -= 25;
91
-			$prefix = '…';
92
-		}
86
+        if ($start <= 25) {
87
+            $start = 0;
88
+            $prefix = '';
89
+        } else {
90
+            $start -= 25;
91
+            $prefix = '…';
92
+        }
93 93
 
94
-		if ((mb_strlen($message) - $end) <= 25) {
95
-			$end = mb_strlen($message);
96
-			$suffix = '';
97
-		} else {
98
-			$end += 25;
99
-			$suffix = '…';
100
-		}
94
+        if ((mb_strlen($message) - $end) <= 25) {
95
+            $end = mb_strlen($message);
96
+            $suffix = '';
97
+        } else {
98
+            $end += 25;
99
+            $suffix = '…';
100
+        }
101 101
 
102
-		return $prefix . mb_substr($message, $start, $end - $start) . $suffix;
103
-	}
102
+        return $prefix . mb_substr($message, $start, $end - $start) . $suffix;
103
+    }
104 104
 }
Please login to merge, or discard this patch.
apps/comments/lib/Search/CommentsSearchProvider.php 2 patches
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -20,52 +20,52 @@
 block discarded – undo
20 20
 use function pathinfo;
21 21
 
22 22
 class CommentsSearchProvider implements IProvider {
23
-	public function __construct(
24
-		private IUserManager $userManager,
25
-		private IL10N $l10n,
26
-		private IURLGenerator $urlGenerator,
27
-		private LegacyProvider $legacyProvider,
28
-	) {
29
-	}
23
+    public function __construct(
24
+        private IUserManager $userManager,
25
+        private IL10N $l10n,
26
+        private IURLGenerator $urlGenerator,
27
+        private LegacyProvider $legacyProvider,
28
+    ) {
29
+    }
30 30
 
31
-	public function getId(): string {
32
-		return 'comments';
33
-	}
31
+    public function getId(): string {
32
+        return 'comments';
33
+    }
34 34
 
35
-	public function getName(): string {
36
-		return $this->l10n->t('Comments');
37
-	}
35
+    public function getName(): string {
36
+        return $this->l10n->t('Comments');
37
+    }
38 38
 
39
-	public function getOrder(string $route, array $routeParameters): int {
40
-		if ($route === 'files.View.index') {
41
-			// Files first
42
-			return 0;
43
-		}
44
-		return 10;
45
-	}
39
+    public function getOrder(string $route, array $routeParameters): int {
40
+        if ($route === 'files.View.index') {
41
+            // Files first
42
+            return 0;
43
+        }
44
+        return 10;
45
+    }
46 46
 
47
-	public function search(IUser $user, ISearchQuery $query): SearchResult {
48
-		return SearchResult::complete(
49
-			$this->l10n->t('Comments'),
50
-			array_map(function (Result $result) {
51
-				$path = $result->path;
52
-				$pathInfo = pathinfo($path);
53
-				$isUser = $this->userManager->userExists($result->authorId);
54
-				$avatarUrl = $isUser
55
-					? $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $result->authorId, 'size' => 42])
56
-					: $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $result->authorId, 'size' => 42]);
57
-				return new SearchResultEntry(
58
-					$avatarUrl,
59
-					$result->name,
60
-					$path,
61
-					$this->urlGenerator->linkToRouteAbsolute('files.view.index', [
62
-						'dir' => $pathInfo['dirname'],
63
-						'scrollto' => $pathInfo['basename'],
64
-					]),
65
-					'',
66
-					true
67
-				);
68
-			}, $this->legacyProvider->search($query->getTerm()))
69
-		);
70
-	}
47
+    public function search(IUser $user, ISearchQuery $query): SearchResult {
48
+        return SearchResult::complete(
49
+            $this->l10n->t('Comments'),
50
+            array_map(function (Result $result) {
51
+                $path = $result->path;
52
+                $pathInfo = pathinfo($path);
53
+                $isUser = $this->userManager->userExists($result->authorId);
54
+                $avatarUrl = $isUser
55
+                    ? $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $result->authorId, 'size' => 42])
56
+                    : $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $result->authorId, 'size' => 42]);
57
+                return new SearchResultEntry(
58
+                    $avatarUrl,
59
+                    $result->name,
60
+                    $path,
61
+                    $this->urlGenerator->linkToRouteAbsolute('files.view.index', [
62
+                        'dir' => $pathInfo['dirname'],
63
+                        'scrollto' => $pathInfo['basename'],
64
+                    ]),
65
+                    '',
66
+                    true
67
+                );
68
+            }, $this->legacyProvider->search($query->getTerm()))
69
+        );
70
+    }
71 71
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
 	public function search(IUser $user, ISearchQuery $query): SearchResult {
48 48
 		return SearchResult::complete(
49 49
 			$this->l10n->t('Comments'),
50
-			array_map(function (Result $result) {
50
+			array_map(function(Result $result) {
51 51
 				$path = $result->path;
52 52
 				$pathInfo = pathinfo($path);
53 53
 				$isUser = $this->userManager->userExists($result->authorId);
Please login to merge, or discard this patch.
apps/comments/lib/Search/LegacyProvider.php 2 patches
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -20,78 +20,78 @@
 block discarded – undo
20 20
 use function count;
21 21
 
22 22
 class LegacyProvider extends Provider {
23
-	/**
24
-	 * Search for $query
25
-	 *
26
-	 * @param string $query
27
-	 * @return array An array of OCP\Search\Result's
28
-	 * @since 7.0.0
29
-	 */
30
-	public function search($query): array {
31
-		$cm = Server::get(ICommentsManager::class);
32
-		$us = Server::get(IUserSession::class);
33
-
34
-		$user = $us->getUser();
35
-		if (!$user instanceof IUser) {
36
-			return [];
37
-		}
38
-		$uf = \OC::$server->getUserFolder($user->getUID());
39
-
40
-		if ($uf === null) {
41
-			return [];
42
-		}
43
-
44
-		$result = [];
45
-		$numComments = 50;
46
-		$offset = 0;
47
-
48
-		while (count($result) < $numComments) {
49
-			/** @var IComment[] $comments */
50
-			$comments = $cm->search($query, 'files', '', 'comment', $offset, $numComments);
51
-
52
-			foreach ($comments as $comment) {
53
-				if ($comment->getActorType() !== 'users') {
54
-					continue;
55
-				}
56
-
57
-				$displayName = $cm->resolveDisplayName('user', $comment->getActorId());
58
-
59
-				try {
60
-					$file = $this->getFileForComment($uf, $comment);
61
-					$result[] = new Result($query,
62
-						$comment,
63
-						$displayName,
64
-						$file->getPath()
65
-					);
66
-				} catch (NotFoundException $e) {
67
-					continue;
68
-				}
69
-			}
70
-
71
-			if (count($comments) < $numComments) {
72
-				// Didn't find more comments when we tried to get, so there are no more comments.
73
-				return $result;
74
-			}
75
-
76
-			$offset += $numComments;
77
-			$numComments = 50 - count($result);
78
-		}
79
-
80
-		return $result;
81
-	}
82
-
83
-	/**
84
-	 * @param Folder $userFolder
85
-	 * @param IComment $comment
86
-	 * @return Node
87
-	 * @throws NotFoundException
88
-	 */
89
-	protected function getFileForComment(Folder $userFolder, IComment $comment): Node {
90
-		$nodes = $userFolder->getById((int)$comment->getObjectId());
91
-		if (empty($nodes)) {
92
-			throw new NotFoundException('File not found');
93
-		}
94
-
95
-		return array_shift($nodes);
96
-	}
23
+    /**
24
+     * Search for $query
25
+     *
26
+     * @param string $query
27
+     * @return array An array of OCP\Search\Result's
28
+     * @since 7.0.0
29
+     */
30
+    public function search($query): array {
31
+        $cm = Server::get(ICommentsManager::class);
32
+        $us = Server::get(IUserSession::class);
33
+
34
+        $user = $us->getUser();
35
+        if (!$user instanceof IUser) {
36
+            return [];
37
+        }
38
+        $uf = \OC::$server->getUserFolder($user->getUID());
39
+
40
+        if ($uf === null) {
41
+            return [];
42
+        }
43
+
44
+        $result = [];
45
+        $numComments = 50;
46
+        $offset = 0;
47
+
48
+        while (count($result) < $numComments) {
49
+            /** @var IComment[] $comments */
50
+            $comments = $cm->search($query, 'files', '', 'comment', $offset, $numComments);
51
+
52
+            foreach ($comments as $comment) {
53
+                if ($comment->getActorType() !== 'users') {
54
+                    continue;
55
+                }
56
+
57
+                $displayName = $cm->resolveDisplayName('user', $comment->getActorId());
58
+
59
+                try {
60
+                    $file = $this->getFileForComment($uf, $comment);
61
+                    $result[] = new Result($query,
62
+                        $comment,
63
+                        $displayName,
64
+                        $file->getPath()
65
+                    );
66
+                } catch (NotFoundException $e) {
67
+                    continue;
68
+                }
69
+            }
70
+
71
+            if (count($comments) < $numComments) {
72
+                // Didn't find more comments when we tried to get, so there are no more comments.
73
+                return $result;
74
+            }
75
+
76
+            $offset += $numComments;
77
+            $numComments = 50 - count($result);
78
+        }
79
+
80
+        return $result;
81
+    }
82
+
83
+    /**
84
+     * @param Folder $userFolder
85
+     * @param IComment $comment
86
+     * @return Node
87
+     * @throws NotFoundException
88
+     */
89
+    protected function getFileForComment(Folder $userFolder, IComment $comment): Node {
90
+        $nodes = $userFolder->getById((int)$comment->getObjectId());
91
+        if (empty($nodes)) {
92
+            throw new NotFoundException('File not found');
93
+        }
94
+
95
+        return array_shift($nodes);
96
+    }
97 97
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@
 block discarded – undo
87 87
 	 * @throws NotFoundException
88 88
 	 */
89 89
 	protected function getFileForComment(Folder $userFolder, IComment $comment): Node {
90
-		$nodes = $userFolder->getById((int)$comment->getObjectId());
90
+		$nodes = $userFolder->getById((int) $comment->getObjectId());
91 91
 		if (empty($nodes)) {
92 92
 			throw new NotFoundException('File not found');
93 93
 		}
Please login to merge, or discard this patch.