Skip to content

Commit daef22c

Browse files
CarlSchwanCarl Schwan
authored andcommitted
refactor: Add more typing
- repairs job - database - redis And remove Helpertest which was unused outside of some tests. Signed-off-by: Carl Schwan <[email protected]>
1 parent cc3fc0a commit daef22c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+397
-1152
lines changed

apps/dav/tests/unit/Connector/LegacyPublicAuthTest.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@
1515
use OCP\Share\Exceptions\ShareNotFound;
1616
use OCP\Share\IManager;
1717
use OCP\Share\IShare;
18+
use PHPUnit\Framework\Attributes\Group;
1819
use PHPUnit\Framework\MockObject\MockObject;
20+
use Test\TestCase;
1921

20-
/**
21-
* Class LegacyPublicAuthTest
22-
*
23-
*
24-
* @package OCA\DAV\Tests\unit\Connector
25-
*/
26-
#[\PHPUnit\Framework\Attributes\Group('DB')]
27-
class LegacyPublicAuthTest extends \Test\TestCase {
22+
#[Group('DB')]
23+
class LegacyPublicAuthTest extends TestCase {
2824
private ISession&MockObject $session;
2925
private IRequest&MockObject $request;
3026
private IManager&MockObject $shareManager;
@@ -55,7 +51,7 @@ protected function tearDown(): void {
5551
\OC_User::setIncognitoMode(false);
5652

5753
// Set old user
58-
\OC_User::setUserId($this->oldUser);
54+
\OC_User::setUserId($this->oldUser ?: null);
5955
if ($this->oldUser !== false) {
6056
\OC_Util::setupFS($this->oldUser);
6157
}

apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function testGetPrincipalsByPrefixWithoutPrefix(): void {
7878
}
7979

8080
public function testGetPrincipalsByPrefixWithUsers(): void {
81-
$fooUser = $this->createMock(User::class);
81+
$fooUser = $this->createMock(IUser::class);
8282
$fooUser
8383
->expects($this->once())
8484
->method('getUID')
@@ -91,7 +91,7 @@ public function testGetPrincipalsByPrefixWithUsers(): void {
9191
->expects($this->once())
9292
->method('getSystemEMailAddress')
9393
->willReturn('');
94-
$barUser = $this->createMock(User::class);
94+
$barUser = $this->createMock(IUser::class);
9595
$barUser
9696
->expects($this->once())
9797
->method('getUID')
@@ -183,7 +183,7 @@ public function testGetPrincipalsByPrefixEmpty(): void {
183183
}
184184

185185
public function testGetPrincipalsByPathWithoutMail(): void {
186-
$fooUser = $this->createMock(User::class);
186+
$fooUser = $this->createMock(IUser::class);
187187
$fooUser
188188
->expects($this->once())
189189
->method('getUID')
@@ -211,7 +211,7 @@ public function testGetPrincipalsByPathWithoutMail(): void {
211211
}
212212

213213
public function testGetPrincipalsByPathWithMail(): void {
214-
$fooUser = $this->createMock(User::class);
214+
$fooUser = $this->createMock(IUser::class);
215215
$fooUser
216216
->expects($this->once())
217217
->method('getSystemEMailAddress')

apps/settings/lib/AppInfo/Application.php

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use OC\AppFramework\Utility\TimeFactory;
1212
use OC\Authentication\Events\AppPasswordCreatedEvent;
1313
use OC\Authentication\Token\IProvider;
14-
use OC\Server;
14+
use OC\Settings\Manager;
1515
use OCA\Settings\ConfigLexicon;
1616
use OCA\Settings\Hooks;
1717
use OCA\Settings\Listener\AppPasswordCreatedActivityListener;
@@ -84,25 +84,28 @@
8484
use OCP\AppFramework\Bootstrap\IBootContext;
8585
use OCP\AppFramework\Bootstrap\IBootstrap;
8686
use OCP\AppFramework\Bootstrap\IRegistrationContext;
87-
use OCP\AppFramework\IAppContainer;
8887
use OCP\Defaults;
8988
use OCP\Group\Events\GroupDeletedEvent;
9089
use OCP\Group\Events\UserAddedEvent;
9190
use OCP\Group\Events\UserRemovedEvent;
92-
use OCP\IServerContainer;
91+
use OCP\IConfig;
92+
use OCP\IURLGenerator;
93+
use OCP\L10N\IFactory;
94+
use OCP\Mail\IMailer;
95+
use OCP\Security\ICrypto;
96+
use OCP\Security\ISecureRandom;
97+
use OCP\Server;
9398
use OCP\Settings\Events\DeclarativeSettingsGetValueEvent;
9499
use OCP\Settings\Events\DeclarativeSettingsSetValueEvent;
95100
use OCP\Settings\IManager;
96101
use OCP\User\Events\PasswordUpdatedEvent;
97102
use OCP\User\Events\UserChangedEvent;
98103
use OCP\Util;
104+
use Psr\Container\ContainerInterface;
99105

100106
class Application extends App implements IBootstrap {
101107
public const APP_ID = 'settings';
102108

103-
/**
104-
* @param array $urlParams
105-
*/
106109
public function __construct(array $urlParams = []) {
107110
parent::__construct(self::APP_ID, $urlParams);
108111
}
@@ -139,32 +142,23 @@ public function register(IRegistrationContext $context): void {
139142
/**
140143
* Core class wrappers
141144
*/
142-
$context->registerService(IProvider::class, function (IAppContainer $appContainer) {
143-
/** @var IServerContainer $serverContainer */
144-
$serverContainer = $appContainer->query(IServerContainer::class);
145-
return $serverContainer->query(IProvider::class);
145+
$context->registerService(IProvider::class, function (): IProvider {
146+
return Server::get(IProvider::class);
146147
});
147-
$context->registerService(IManager::class, function (IAppContainer $appContainer) {
148-
/** @var IServerContainer $serverContainer */
149-
$serverContainer = $appContainer->query(IServerContainer::class);
150-
return $serverContainer->getSettingsManager();
148+
$context->registerService(IManager::class, function (): Manager {
149+
return Server::get(Manager::class);
151150
});
152151

153-
$context->registerService(NewUserMailHelper::class, function (IAppContainer $appContainer) {
154-
/** @var Server $server */
155-
$server = $appContainer->query(IServerContainer::class);
156-
/** @var Defaults $defaults */
157-
$defaults = $server->query(Defaults::class);
158-
152+
$context->registerService(NewUserMailHelper::class, function (ContainerInterface $appContainer) {
159153
return new NewUserMailHelper(
160-
$defaults,
161-
$server->getURLGenerator(),
162-
$server->getL10NFactory(),
163-
$server->getMailer(),
164-
$server->getSecureRandom(),
154+
Server::get(Defaults::class),
155+
$appContainer->get(IURLGenerator::class),
156+
$appContainer->get(IFactory::class),
157+
$appContainer->get(IMailer::class),
158+
$appContainer->get(ISecureRandom::class),
165159
new TimeFactory(),
166-
$server->getConfig(),
167-
$server->getCrypto(),
160+
$appContainer->get(IConfig::class),
161+
$appContainer->get(ICrypto::class),
168162
Util::getDefaultEmailAddress('no-reply')
169163
);
170164
});

apps/settings/lib/Middleware/SubadminMiddleware.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
use OCP\Group\ISubAdmin;
2020
use OCP\IL10N;
2121
use OCP\IUserSession;
22+
use Override;
2223

2324
/**
24-
* Verifies whether an user has at least subadmin rights.
25+
* Verifies whether a user has at least sub-admin rights.
2526
* To bypass use the `@NoSubAdminRequired` annotation
2627
*/
2728
class SubadminMiddleware extends Middleware {
@@ -41,29 +42,17 @@ private function isSubAdmin(): bool {
4142
return $this->subAdminManager->isSubAdmin($userObject);
4243
}
4344

44-
/**
45-
* Check if sharing is enabled before the controllers is executed
46-
* @param Controller $controller
47-
* @param string $methodName
48-
* @throws \Exception
49-
*/
50-
public function beforeController($controller, $methodName) {
45+
#[Override]
46+
public function beforeController(Controller $controller, string $methodName): void {
5147
if (!$this->reflector->hasAnnotation('NoSubAdminRequired') && !$this->reflector->hasAnnotation('AuthorizedAdminSetting')) {
5248
if (!$this->isSubAdmin()) {
5349
throw new NotAdminException($this->l10n->t('Logged in account must be a sub admin'));
5450
}
5551
}
5652
}
5753

58-
/**
59-
* Return 403 page in case of an exception
60-
* @param Controller $controller
61-
* @param string $methodName
62-
* @param \Exception $exception
63-
* @return TemplateResponse
64-
* @throws \Exception
65-
*/
66-
public function afterException($controller, $methodName, \Exception $exception) {
54+
#[Override]
55+
public function afterException(Controller $controller, string $methodName, \Exception $exception): TemplateResponse {
6756
if ($exception instanceof NotAdminException) {
6857
$response = new TemplateResponse('core', '403', [], 'guest');
6958
$response->setStatus(Http::STATUS_FORBIDDEN);

build/psalm-baseline.xml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,31 +2336,6 @@
23362336
<code><![CDATA[Response]]></code>
23372337
</InvalidReturnType>
23382338
</file>
2339-
<file src="apps/settings/lib/AppInfo/Application.php">
2340-
<DeprecatedInterface>
2341-
<code><![CDATA[$serverContainer]]></code>
2342-
<code><![CDATA[$serverContainer]]></code>
2343-
<code><![CDATA[IAppContainer]]></code>
2344-
<code><![CDATA[IAppContainer]]></code>
2345-
<code><![CDATA[IAppContainer]]></code>
2346-
</DeprecatedInterface>
2347-
<DeprecatedMethod>
2348-
<code><![CDATA[getConfig]]></code>
2349-
<code><![CDATA[getCrypto]]></code>
2350-
<code><![CDATA[getL10NFactory]]></code>
2351-
<code><![CDATA[getMailer]]></code>
2352-
<code><![CDATA[getSecureRandom]]></code>
2353-
<code><![CDATA[getURLGenerator]]></code>
2354-
<code><![CDATA[query]]></code>
2355-
<code><![CDATA[query]]></code>
2356-
<code><![CDATA[query]]></code>
2357-
<code><![CDATA[query]]></code>
2358-
<code><![CDATA[query]]></code>
2359-
</DeprecatedMethod>
2360-
<UndefinedInterfaceMethod>
2361-
<code><![CDATA[getSettingsManager]]></code>
2362-
</UndefinedInterfaceMethod>
2363-
</file>
23642339
<file src="apps/settings/lib/BackgroundJobs/VerifyUserData.php">
23652340
<DeprecatedConstant>
23662341
<code><![CDATA[IAccountManager::PROPERTY_TWITTER]]></code>
@@ -4069,16 +4044,6 @@
40694044
<code><![CDATA[array]]></code>
40704045
</ImplementedReturnTypeMismatch>
40714046
</file>
4072-
<file src="lib/private/Remote/Instance.php">
4073-
<InvalidScalarArgument>
4074-
<code><![CDATA[$response]]></code>
4075-
</InvalidScalarArgument>
4076-
</file>
4077-
<file src="lib/private/Repair/Owncloud/CleanPreviews.php">
4078-
<InvalidArgument>
4079-
<code><![CDATA[false]]></code>
4080-
</InvalidArgument>
4081-
</file>
40824047
<file src="lib/private/Repair/RemoveLinkShares.php">
40834048
<InvalidPropertyAssignmentValue>
40844049
<code><![CDATA[$this->userToNotify]]></code>

core/Command/Memcache/RedisCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4444
return 1;
4545
}
4646

47-
$redis->setOption(\Redis::OPT_REPLY_LITERAL, true);
47+
if ($redis instanceof \Redis) {
48+
$redis->setOption(\Redis::OPT_REPLY_LITERAL, true);
49+
}
4850
$result = $redis->rawCommand(...$command);
4951
if ($result === false) {
5052
$output->writeln('<error>Redis command failed</error>');

lib/composer/composer/autoload_classmap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,6 @@
21222122
'OC\\Share20\\UserDeletedListener' => $baseDir . '/lib/private/Share20/UserDeletedListener.php',
21232123
'OC\\Share20\\UserRemovedListener' => $baseDir . '/lib/private/Share20/UserRemovedListener.php',
21242124
'OC\\Share\\Constants' => $baseDir . '/lib/private/Share/Constants.php',
2125-
'OC\\Share\\Helper' => $baseDir . '/lib/private/Share/Helper.php',
21262125
'OC\\Share\\Share' => $baseDir . '/lib/private/Share/Share.php',
21272126
'OC\\Snowflake\\APCuSequence' => $baseDir . '/lib/private/Snowflake/APCuSequence.php',
21282127
'OC\\Snowflake\\Decoder' => $baseDir . '/lib/private/Snowflake/Decoder.php',

lib/composer/composer/autoload_static.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2163,7 +2163,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
21632163
'OC\\Share20\\UserDeletedListener' => __DIR__ . '/../../..' . '/lib/private/Share20/UserDeletedListener.php',
21642164
'OC\\Share20\\UserRemovedListener' => __DIR__ . '/../../..' . '/lib/private/Share20/UserRemovedListener.php',
21652165
'OC\\Share\\Constants' => __DIR__ . '/../../..' . '/lib/private/Share/Constants.php',
2166-
'OC\\Share\\Helper' => __DIR__ . '/../../..' . '/lib/private/Share/Helper.php',
21672166
'OC\\Share\\Share' => __DIR__ . '/../../..' . '/lib/private/Share/Share.php',
21682167
'OC\\Snowflake\\APCuSequence' => __DIR__ . '/../../..' . '/lib/private/Snowflake/APCuSequence.php',
21692168
'OC\\Snowflake\\Decoder' => __DIR__ . '/../../..' . '/lib/private/Snowflake/Decoder.php',

lib/private/NavigationManager.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@
2222
use Psr\Log\LoggerInterface;
2323

2424
/**
25-
* Manages the ownCloud navigation
25+
* Manages the Nextcloud navigation
2626
*/
27-
2827
class NavigationManager implements INavigationManager {
29-
protected $entries = [];
30-
protected $closureEntries = [];
28+
protected array $entries = [];
29+
protected array $closureEntries = [];
30+
/** @var string $activeEntry */
3131
protected $activeEntry;
32-
protected $unreadCounters = [];
33-
34-
/** @var bool */
35-
protected $init = false;
32+
protected array $unreadCounters = [];
33+
protected bool $init = false;
3634
/** User defined app order (cached for the `add` function) */
3735
private array $customAppOrder;
3836

lib/private/Preview/WatcherConnector.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use OCP\Server;
1717

1818
class WatcherConnector {
19+
private ?Watcher $watcher = null;
20+
1921
public function __construct(
2022
private IRootFolder $root,
2123
private SystemConfig $config,
@@ -24,7 +26,11 @@ public function __construct(
2426
}
2527

2628
private function getWatcher(): Watcher {
27-
return Server::get(Watcher::class);
29+
if ($this->watcher !== null) {
30+
return $this->watcher;
31+
}
32+
$this->watcher = Server::get(Watcher::class);
33+
return $this->watcher;
2834
}
2935

3036
public function connectWatcher(): void {

0 commit comments

Comments
 (0)