@@ -258,8 +258,8 @@ protected function getFindSoftDeletedChildrenQuery(string $type): IQueryBuilder
258258 * @psalm-param T $type
259259 * @param int $folderId
260260 * @param bool $softDeleted
261- * @return Entity[]
262- * @psalm-return E[]
261+ * @return list< Entity>
262+ * @psalm-return list<E>
263263 * @psalm-template T as TreeMapper::TYPE_*
264264 * @psalm-template E as (T is TreeMapper::TYPE_FOLDER ? Folder : (T is TreeMapper::TYPE_BOOKMARK ? Bookmark : SharedFolder))
265265 */
@@ -313,21 +313,41 @@ public function findParentsOf(string $type, int $itemId, $withSoftDeletions = fa
313313 * @param string $type
314314 * @psalm-param T $type
315315 * @param int $folderId
316- * @return Entity[]
317- * @psalm-return E[]
316+ * @return list< Entity>
317+ * @psalm-return list<E>
318318 * @psalm-template T as TreeMapper::TYPE_*
319319 * @psalm-template E as (T is TreeMapper::TYPE_FOLDER ? Folder : (T is TreeMapper::TYPE_BOOKMARK ? Bookmark : SharedFolder))
320320 */
321321 public function findByAncestorFolder (string $ type , int $ folderId ): array {
322- $ descendants = [];
323- $ newDescendants = $ this ->findChildren ($ type , $ folderId );
324- do {
325- array_push ($ descendants , ...$ newDescendants );
326- $ newDescendants = array_merge (...array_map (function (Entity $ descendant ) use ($ type ) {
327- return $ this ->findChildren ($ type , $ descendant ->getId ());
328- }, $ newDescendants ));
329- } while (count ($ newDescendants ) > 0 );
330- return $ descendants ;
322+ if ($ type === TreeMapper::TYPE_FOLDER ) {
323+ $ descendants = [];
324+ $ newDescendants = $ this ->findChildren (TreeMapper::TYPE_FOLDER , $ folderId );
325+ do {
326+ array_push ($ descendants , ...$ newDescendants );
327+ $ newDescendants = array_merge (...array_map (function (Folder $ folder ): array {
328+ return $ this ->findChildren (TreeMapper::TYPE_FOLDER , $ folder ->getId ());
329+ }, $ newDescendants ));
330+ } while (count ($ newDescendants ) > 0 );
331+ return $ descendants ;
332+ }
333+
334+ if ($ type === TreeMapper::TYPE_SHARE ) {
335+ $ descendantFolders = $ this ->findChildren (TreeMapper::TYPE_FOLDER , $ folderId );
336+ $ descendants = array_merge (...array_map (function (Folder $ folder ): array {
337+ return $ this ->findChildren (TreeMapper::TYPE_SHARE , $ folder ->getId ());
338+ }, $ descendantFolders ));
339+ return $ descendants ;
340+ }
341+
342+ if ($ type === TreeMapper::TYPE_BOOKMARK ) {
343+ $ descendantFolders = $ this ->findChildren (TreeMapper::TYPE_FOLDER , $ folderId );
344+ $ descendants = array_merge (...array_map (function (Folder $ folder ): array {
345+ return $ this ->findChildren (TreeMapper::TYPE_BOOKMARK , $ folder ->getId ());
346+ }, $ descendantFolders ));
347+ return $ descendants ;
348+ }
349+
350+ throw new \InvalidArgumentException ('Invalid type ' );
331351 }
332352
333353 /**
0 commit comments