1919use OCP \IUserSession ;
2020use OCP \L10N \IFactory ;
2121use OCP \Navigation \Events \LoadAdditionalEntriesEvent ;
22+ use Override ;
2223use Psr \Log \LoggerInterface ;
2324
2425/**
2526 * Manages the Nextcloud navigation
27+ * @psalm-import-type NavigationEntry from INavigationManager
28+ * @psalm-import-type NavigationEntryOutput from INavigationManager
2629 */
2730class NavigationManager implements INavigationManager {
31+ /** @var array<string, NavigationEntryOutput> */
2832 protected array $ entries = [];
33+ /** @var list<callable(): NavigationEntry> */
2934 protected array $ closureEntries = [];
30- /** @var string $activeEntry */
31- protected $ activeEntry ;
35+ protected ?string $ activeEntry = null ;
3236 protected array $ unreadCounters = [];
3337 protected bool $ init = false ;
3438 /** User defined app order (cached for the `add` function) */
@@ -46,10 +50,8 @@ public function __construct(
4650 ) {
4751 }
4852
49- /**
50- * @inheritDoc
51- */
52- public function add ($ entry ) {
53+ #[Override]
54+ public function add (array |callable $ entry ): void {
5355 if ($ entry instanceof \Closure) {
5456 $ this ->closureEntries [] = $ entry ;
5557 return ;
@@ -86,7 +88,7 @@ public function add($entry) {
8688 $ this ->updateDefaultEntries ();
8789 }
8890
89- private function updateDefaultEntries () {
91+ private function updateDefaultEntries (): void {
9092 $ defaultEntryId = $ this ->getDefaultEntryIdForUser ($ this ->userSession ->getUser (), false );
9193 foreach ($ this ->entries as $ id => $ entry ) {
9294 if ($ entry ['type ' ] === 'link ' ) {
@@ -95,9 +97,7 @@ private function updateDefaultEntries() {
9597 }
9698 }
9799
98- /**
99- * @inheritDoc
100- */
100+ #[Override]
101101 public function getAll (string $ type = 'link ' ): array {
102102 $ this ->init ();
103103
@@ -114,8 +114,8 @@ public function getAll(string $type = 'link'): array {
114114 /**
115115 * Sort navigation entries default app is always sorted first, then by order, name and set active flag
116116 *
117- * @param array $list
118- * @return array
117+ * @param array<string, NavigationEntryOutput> $list
118+ * @return array<string, NavigationEntryOutput>
119119 */
120120 private function proceedNavigation (array $ list , string $ type ): array {
121121 uasort ($ list , function ($ a , $ b ) {
@@ -136,7 +136,7 @@ private function proceedNavigation(array $list, string $type): array {
136136
137137 if ($ type === 'all ' || $ type === 'link ' ) {
138138 // There might be the case that no default app was set, in this case the first app is the default app.
139- // Otherwise the default app is already the ordered first, so setting the default prop will make no difference.
139+ // Otherwise, the default app is already the ordered first, so setting the default prop will make no difference.
140140 foreach ($ list as $ index => &$ navEntry ) {
141141 if ($ navEntry ['type ' ] === 'link ' ) {
142142 $ navEntry ['default ' ] = true ;
@@ -165,23 +165,19 @@ private function proceedNavigation(array $list, string $type): array {
165165 /**
166166 * removes all the entries
167167 */
168- public function clear ($ loadDefaultLinks = true ) {
168+ public function clear (bool $ loadDefaultLinks = true ): void {
169169 $ this ->entries = [];
170170 $ this ->closureEntries = [];
171171 $ this ->init = !$ loadDefaultLinks ;
172172 }
173173
174- /**
175- * @inheritDoc
176- */
177- public function setActiveEntry ($ appId ) {
174+ #[Override]
175+ public function setActiveEntry (string $ appId ): void {
178176 $ this ->activeEntry = $ appId ;
179177 }
180178
181- /**
182- * @inheritDoc
183- */
184- public function getActiveEntry () {
179+ #[Override]
180+ public function getActiveEntry (): ?string {
185181 return $ this ->activeEntry ;
186182 }
187183
@@ -377,31 +373,34 @@ private function init(bool $resolveClosures = true): void {
377373 }
378374 }
379375
380- private function isAdmin () {
376+ private function isAdmin (): bool {
381377 $ user = $ this ->userSession ->getUser ();
382378 if ($ user !== null ) {
383379 return $ this ->groupManager ->isAdmin ($ user ->getUID ());
384380 }
385381 return false ;
386382 }
387383
388- private function isSubadmin () {
384+ private function isSubadmin (): bool {
389385 $ user = $ this ->userSession ->getUser ();
390386 if ($ user !== null && $ this ->groupManager instanceof Manager) {
391387 return $ this ->groupManager ->getSubAdmin ()->isSubAdmin ($ user );
392388 }
393389 return false ;
394390 }
395391
392+ #[Override]
396393 public function setUnreadCounter (string $ id , int $ unreadCounter ): void {
397394 $ this ->unreadCounters [$ id ] = $ unreadCounter ;
398395 }
399396
397+ #[Override]
400398 public function get (string $ id ): ?array {
401399 $ this ->init ();
402400 return $ this ->entries [$ id ];
403401 }
404402
403+ #[Override]
405404 public function getDefaultEntryIdForUser (?IUser $ user = null , bool $ withFallbacks = true ): string {
406405 $ this ->init ();
407406 // Disable fallbacks here, as we need to override them with the user defaults if none are configured.
@@ -443,6 +442,7 @@ public function getDefaultEntryIdForUser(?IUser $user = null, bool $withFallback
443442 return $ withFallbacks ? 'files ' : '' ;
444443 }
445444
445+ #[Override]
446446 public function getDefaultEntryIds (bool $ withFallbacks = true ): array {
447447 $ this ->init ();
448448 $ storedIds = explode (', ' , $ this ->config ->getSystemValueString ('defaultapp ' , $ withFallbacks ? 'dashboard,files ' : '' ));
@@ -457,6 +457,7 @@ public function getDefaultEntryIds(bool $withFallbacks = true): array {
457457 return array_filter ($ ids );
458458 }
459459
460+ #[Override]
460461 public function setDefaultEntryIds (array $ ids ): void {
461462 $ this ->init ();
462463 $ entryIds = array_keys ($ this ->entries );
0 commit comments