Skip to content

Commit c2541a5

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 7190c30 commit c2541a5

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

+398
-1155
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);

apps/user_ldap/lib/User/OfflineUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function getOCName() {
101101
* getter for LDAP uid
102102
* @return string
103103
*/
104-
public function getUID() {
104+
public function getUID(): string {
105105
if ($this->uid === null) {
106106
$this->fetchDetails();
107107
}

build/psalm-baseline.xml

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,33 +2259,6 @@
22592259
<code><![CDATA[Response]]></code>
22602260
</InvalidReturnType>
22612261
</file>
2262-
<file src="apps/settings/lib/AppInfo/Application.php">
2263-
<DeprecatedInterface>
2264-
<code><![CDATA[$serverContainer]]></code>
2265-
<code><![CDATA[$serverContainer]]></code>
2266-
<code><![CDATA[IAppContainer]]></code>
2267-
<code><![CDATA[IAppContainer]]></code>
2268-
<code><![CDATA[IAppContainer]]></code>
2269-
</DeprecatedInterface>
2270-
<DeprecatedMethod>
2271-
<code><![CDATA[getConfig]]></code>
2272-
<code><![CDATA[getCrypto]]></code>
2273-
<code><![CDATA[getL10NFactory]]></code>
2274-
<code><![CDATA[getMailer]]></code>
2275-
<code><![CDATA[getSecureRandom]]></code>
2276-
<code><![CDATA[getURLGenerator]]></code>
2277-
<code><![CDATA[query]]></code>
2278-
<code><![CDATA[query]]></code>
2279-
<code><![CDATA[query]]></code>
2280-
<code><![CDATA[query]]></code>
2281-
<code><![CDATA[query]]></code>
2282-
<code><![CDATA[query]]></code>
2283-
<code><![CDATA[query]]></code>
2284-
</DeprecatedMethod>
2285-
<UndefinedInterfaceMethod>
2286-
<code><![CDATA[getSettingsManager]]></code>
2287-
</UndefinedInterfaceMethod>
2288-
</file>
22892262
<file src="apps/settings/lib/BackgroundJobs/VerifyUserData.php">
22902263
<DeprecatedConstant>
22912264
<code><![CDATA[IAccountManager::PROPERTY_TWITTER]]></code>
@@ -3924,16 +3897,6 @@
39243897
<code><![CDATA[array]]></code>
39253898
</ImplementedReturnTypeMismatch>
39263899
</file>
3927-
<file src="lib/private/Remote/Instance.php">
3928-
<InvalidScalarArgument>
3929-
<code><![CDATA[$response]]></code>
3930-
</InvalidScalarArgument>
3931-
</file>
3932-
<file src="lib/private/Repair/Owncloud/CleanPreviews.php">
3933-
<InvalidArgument>
3934-
<code><![CDATA[false]]></code>
3935-
</InvalidArgument>
3936-
</file>
39373900
<file src="lib/private/Repair/RemoveLinkShares.php">
39383901
<InvalidPropertyAssignmentValue>
39393902
<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
@@ -2119,7 +2119,6 @@
21192119
'OC\\Share20\\UserDeletedListener' => $baseDir . '/lib/private/Share20/UserDeletedListener.php',
21202120
'OC\\Share20\\UserRemovedListener' => $baseDir . '/lib/private/Share20/UserRemovedListener.php',
21212121
'OC\\Share\\Constants' => $baseDir . '/lib/private/Share/Constants.php',
2122-
'OC\\Share\\Helper' => $baseDir . '/lib/private/Share/Helper.php',
21232122
'OC\\Share\\Share' => $baseDir . '/lib/private/Share/Share.php',
21242123
'OC\\Snowflake\\APCuSequence' => $baseDir . '/lib/private/Snowflake/APCuSequence.php',
21252124
'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
@@ -2160,7 +2160,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
21602160
'OC\\Share20\\UserDeletedListener' => __DIR__ . '/../../..' . '/lib/private/Share20/UserDeletedListener.php',
21612161
'OC\\Share20\\UserRemovedListener' => __DIR__ . '/../../..' . '/lib/private/Share20/UserRemovedListener.php',
21622162
'OC\\Share\\Constants' => __DIR__ . '/../../..' . '/lib/private/Share/Constants.php',
2163-
'OC\\Share\\Helper' => __DIR__ . '/../../..' . '/lib/private/Share/Helper.php',
21642163
'OC\\Share\\Share' => __DIR__ . '/../../..' . '/lib/private/Share/Share.php',
21652164
'OC\\Snowflake\\APCuSequence' => __DIR__ . '/../../..' . '/lib/private/Snowflake/APCuSequence.php',
21662165
'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

0 commit comments

Comments
 (0)