Skip to content

Commit 48febc5

Browse files
committed
chore: update composer to fix psalm
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 36148d3 commit 48febc5

18 files changed

Lines changed: 365 additions & 288 deletions

composer.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
{
22
"name": "nextcloud/guests",
33
"config": {
4-
"optimize-autoloader": true,
5-
"classmap-authoritative": true,
64
"platform": {
7-
"php": "8.1.0"
5+
"php": "8.1"
6+
},
7+
"sort-packages": true,
8+
"allow-plugins": {
9+
"bamarni/composer-bin-plugin": true
810
},
9-
"sort-packages": true
11+
"optimize-autoloader": true,
12+
"autoloader-suffix": "Guests"
1013
},
11-
"autoload-dev": {
14+
"autoload": {
1215
"psr-4": {
13-
"OCP\\": "vendor/nextcloud/ocp/OCP"
16+
"OCA\\Guests\\": "lib/"
1417
}
1518
},
1619
"scripts": {
@@ -20,14 +23,17 @@
2023
"psalm": "psalm --threads=1",
2124
"psalm:update-baseline": "psalm --threads=1 --update-baseline",
2225
"psalm:clear": "psalm --clear-cache && psalm --clear-global-cache",
23-
"psalm:fix": "psalm --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
26+
"psalm:fix": "psalm --alter --issues=InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType,MismatchingDocblockReturnType,MissingParamType,InvalidFalsableReturnType",
2427
"test:unit": "vendor/bin/phpunit -c phpunit.xml"
2528
},
29+
"require": {
30+
"php": ">=8.1 <=8.4"
31+
},
2632
"require-dev": {
2733
"nextcloud/coding-standard": "^1.3.2",
2834
"nextcloud/ocp": "dev-master",
2935
"php-parallel-lint/php-parallel-lint": "^1.2",
3036
"phpunit/phpunit": "^9",
31-
"vimeo/psalm": "^5.14"
37+
"vimeo/psalm": "^5.26.1"
3238
}
3339
}

composer.lock

Lines changed: 197 additions & 126 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/AppConfigOverwrite.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ public function setOverwrite(array $overwrite): void {
1919
$this->overWrite = $overwrite;
2020
}
2121

22-
/**
23-
* @psalm-suppress MethodSignatureMustProvideReturnType
24-
*/
25-
public function getValue($app, $key, $default = null) {
22+
public function getValue(string $app, string $key, ?string $default = null): string {
2623
if (isset($this->overWrite[$app]) && isset($this->overWrite[$app][$key])) {
2724
return $this->overWrite[$app][$key];
2825
}

lib/AppInfo/Application.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
use OCP\AppFramework\Bootstrap\IBootstrap;
2626
use OCP\AppFramework\Bootstrap\IRegistrationContext;
2727
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
28-
use OCP\AppFramework\IAppContainer;
2928
use OCP\EventDispatcher\IEventDispatcher;
3029
use OCP\IGroupManager;
31-
use OCP\IServerContainer;
3230
use OCP\IUserManager;
31+
use OCP\IUserSession;
3332
use OCP\Notification\IManager as INotificationManager;
3433
use OCP\Share\Events\ShareCreatedEvent;
3534
use OCP\User\Events\UserChangedEvent;
3635
use OCP\User\Events\UserFirstTimeLoggedInEvent;
36+
use Psr\Container\ContainerInterface;
3737

3838
class Application extends App implements IBootstrap {
3939
public const APP_ID = 'guests';
@@ -55,26 +55,27 @@ public function register(IRegistrationContext $context): void {
5555
public function boot(IBootContext $context): void {
5656
// need to cheat here since there's no way to register these in IRegistrationContext
5757
$container = $context->getServerContainer();
58-
$container->get(IUserManager::class)->registerBackend($container->query(UserBackend::class));
59-
$container->get(IGroupManager::class)->addBackend($container->query(GroupBackend::class));
58+
$container->get(IUserManager::class)->registerBackend($container->get(UserBackend::class));
59+
$container->get(IGroupManager::class)->addBackend($container->get(GroupBackend::class));
6060

6161
$this->setupGuestManagement($context->getAppContainer(), $context->getServerContainer());
6262
$this->setupGuestRestrictions($context->getAppContainer(), $context->getServerContainer());
6363
$this->setupNotifications($context->getAppContainer());
64-
$context->getAppContainer()->query(RestrictionManager::class)->lateSetupRestrictions();
64+
$context->getAppContainer()->get(RestrictionManager::class)->lateSetupRestrictions();
6565
}
6666

67-
private function setupGuestManagement(IAppContainer $container, IServerContainer $server): void {
68-
$hookManager = $container->query(Hooks::class);
67+
private function setupGuestManagement(ContainerInterface $container, ContainerInterface $server): void {
68+
$hookManager = $container->get(Hooks::class);
6969
$server->get(IEventDispatcher::class)->addListener(ShareCreatedEvent::class, [$hookManager, 'handlePostShare']);
7070
$server->get(IEventDispatcher::class)->addListener(UserFirstTimeLoggedInEvent::class, [$hookManager, 'handleFirstLogin']);
7171
}
7272

73-
private function setupGuestRestrictions(IAppContainer $container, IServerContainer $server): void {
74-
$userSession = $server->getUserSession();
73+
private function setupGuestRestrictions(ContainerInterface $container, ContainerInterface $server): void {
74+
/** @var IUserSession $userSession */
75+
$userSession = $server->get(IUserSession::class);
7576
$user = $userSession->getUser();
7677
/** @var RestrictionManager $restrictionManager */
77-
$restrictionManager = $container->query(RestrictionManager::class);
78+
$restrictionManager = $container->get(RestrictionManager::class);
7879

7980
if ($user) {
8081
$restrictionManager->verifyAccess();
@@ -87,8 +88,8 @@ private function setupGuestRestrictions(IAppContainer $container, IServerContain
8788
}
8889
}
8990

90-
private function setupNotifications(IAppContainer $container): void {
91-
$notificationManager = $container->query(INotificationManager::class);
91+
private function setupNotifications(ContainerInterface $container): void {
92+
$notificationManager = $container->get(INotificationManager::class);
9293
$notificationManager->registerNotifierService(Notifier::class);
9394
}
9495
}

lib/AppWhitelist.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(
5151
$this->baseUrlLength = strlen($this->baseUrl);
5252
}
5353

54-
public function isAppWhitelisted($appId): bool {
54+
public function isAppWhitelisted(string $appId): bool {
5555
$whitelist = $this->config->getAppWhitelist();
5656
$alwaysEnabled = explode(',', self::WHITELIST_ALWAYS);
5757

@@ -62,7 +62,10 @@ public function isWhitelistEnabled(): bool {
6262
return $this->config->useWhitelist();
6363
}
6464

65-
public function isUrlAllowed(IUser $user, $url): bool {
65+
/**
66+
* @param false|string $url
67+
*/
68+
public function isUrlAllowed(IUser $user, string|false $url): bool {
6669
if ($this->guestManager->isGuest($user) && $this->isWhitelistEnabled()) {
6770
$app = $this->getRequestedApp($url);
6871

@@ -95,8 +98,10 @@ public function verifyAccess(IUser $user, IRequest $request): void {
9598
/**
9699
* Core has \OC::$REQUESTEDAPP but it isn't set until the routes are matched
97100
* taken from \OC\Route\Router::match()
101+
*
102+
* @param false|string $url
98103
*/
99-
private function getRequestedApp($url): string {
104+
private function getRequestedApp(string|false $url): string {
100105
if (substr($url, 0, $this->baseUrlLength) === $this->baseUrl) {
101106
$url = substr($url, $this->baseUrlLength);
102107
}

lib/Config.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function allowExternalStorage(): bool {
3131
/**
3232
* @param string|bool $allow
3333
*/
34-
public function setAllowExternalStorage($allow) {
34+
public function setAllowExternalStorage($allow): void {
3535
$this->appConfig->setAppValueBool('allow_external_storage', $allow === true || $allow === 'true') ;
3636
}
3737

@@ -57,7 +57,7 @@ public function useWhitelist(): bool {
5757
/**
5858
* @param string|bool $use
5959
*/
60-
public function setUseWhitelist($use) {
60+
public function setUseWhitelist($use): void {
6161
$this->appConfig->setAppValueBool('usewhitelist', $use === true || $use === 'true') ;
6262
}
6363

@@ -94,7 +94,7 @@ public function canCreateGuests(): bool {
9494
|| $this->subAdmin->isSubAdmin($user)) {
9595
return true;
9696
}
97-
97+
9898
// Check if we have a group restriction
9999
// and if the user belong to that group
100100
$groupRestriction = $this->getCreateRestrictedToGroup();

lib/FilteredSettingsManager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ private function isSettingAllowed(string $setting): bool {
2828
return $this->appWhitelist->isAppWhitelisted($appId);
2929
}
3030

31+
/**
32+
* @return void
33+
*/
3134
public function registerSection(string $type, string $section) {
3235
$this->manager->registerSection($type, $section);
3336
}
3437

38+
/**
39+
* @return void
40+
*/
3541
public function registerSetting(string $type, string $setting) {
3642
if (!$this->isSettingAllowed($setting)) {
3743
return;

lib/GroupBackend.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function inGroup($uid, $gid): bool {
7373
* Get all groups a user belongs to
7474
*
7575
* @param string $uid Name of the user
76-
* @return array an array of group names
76+
* @return list<string> an array of group names
7777
* @since 4.5.0
7878
*
7979
* This function fetches all groups a user belongs to. It does not check
@@ -120,7 +120,7 @@ public function groupExists($gid): bool {
120120
* @param string $search
121121
* @param int $limit
122122
* @param int $offset
123-
* @return array an array of user ids
123+
* @return array<int, string> an array of user ids
124124
* @since 4.5.0
125125
*/
126126
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0): array {

lib/GuestManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public function createGuest(?IUser $createdBy, string $userId, string $email, st
8484
// generate token for lost password so that a link can be sent by email
8585
$token = $this->secureRandom->generate(
8686
21,
87-
ISecureRandom::CHAR_DIGITS .
88-
ISecureRandom::CHAR_LOWER .
89-
ISecureRandom::CHAR_UPPER);
87+
ISecureRandom::CHAR_DIGITS
88+
. ISecureRandom::CHAR_LOWER
89+
. ISecureRandom::CHAR_UPPER);
9090

9191
$endOfTime = PHP_INT_MAX - 50000;
9292
$token = sprintf('%s:%s', $endOfTime, $token);
@@ -149,7 +149,7 @@ private function getShareCountForUsers(array $guests): array {
149149
return $data;
150150
}
151151

152-
public function getGuestInfo($userId): array {
152+
public function getGuestInfo(string $userId): array {
153153
$shares = array_merge(
154154
$this->shareManager->getSharedWith($userId, IShare::TYPE_USER, null, -1, 0),
155155
$this->shareManager->getSharedWith($userId, IShare::TYPE_GROUP, null, -1, 0),

lib/Listener/BeforeUserManagementRenderedListener.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
* @template-implements IEventListener<BeforeTemplateRenderedEvent>
1919
*/
2020
class BeforeUserManagementRenderedListener implements IEventListener {
21+
/**
22+
* @param Event $event
23+
*/
2124
public function handle(Event $event): void {
2225
if (!($event instanceof BeforeTemplateRenderedEvent)) {
2326
return;

0 commit comments

Comments
 (0)