Skip to content

Commit 6db0764

Browse files
committed
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 b6c15c7 commit 6db0764

Some content is hidden

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

56 files changed

+1656
-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);

0 commit comments

Comments
 (0)