Skip to content

Commit bc9098b

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 1ea4c49 commit bc9098b

Some content is hidden

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

44 files changed

+306
-724
lines changed

apps/settings/lib/AppInfo/Application.php

Lines changed: 20 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,27 @@
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;
9397
use OCP\Settings\Events\DeclarativeSettingsGetValueEvent;
9498
use OCP\Settings\Events\DeclarativeSettingsSetValueEvent;
9599
use OCP\Settings\IManager;
96100
use OCP\User\Events\PasswordUpdatedEvent;
97101
use OCP\User\Events\UserChangedEvent;
98102
use OCP\Util;
103+
use Psr\Container\ContainerInterface;
99104

100105
class Application extends App implements IBootstrap {
101106
public const APP_ID = 'settings';
102107

103-
/**
104-
* @param array $urlParams
105-
*/
106108
public function __construct(array $urlParams = []) {
107109
parent::__construct(self::APP_ID, $urlParams);
108110
}
@@ -139,32 +141,23 @@ public function register(IRegistrationContext $context): void {
139141
/**
140142
* Core class wrappers
141143
*/
142-
$context->registerService(IProvider::class, function (IAppContainer $appContainer) {
143-
/** @var IServerContainer $serverContainer */
144-
$serverContainer = $appContainer->query(IServerContainer::class);
145-
return $serverContainer->query(IProvider::class);
144+
$context->registerService(IProvider::class, function (ContainerInterface $appContainer) {
145+
return $appContainer->get(IProvider::class);
146146
});
147-
$context->registerService(IManager::class, function (IAppContainer $appContainer) {
148-
/** @var IServerContainer $serverContainer */
149-
$serverContainer = $appContainer->query(IServerContainer::class);
150-
return $serverContainer->getSettingsManager();
147+
$context->registerService(IManager::class, function (ContainerInterface $appContainer) {
148+
return $appContainer->get(Manager::class);
151149
});
152150

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-
151+
$context->registerService(NewUserMailHelper::class, function (ContainerInterface $appContainer) {
159152
return new NewUserMailHelper(
160-
$defaults,
161-
$server->getURLGenerator(),
162-
$server->getL10NFactory(),
163-
$server->getMailer(),
164-
$server->getSecureRandom(),
153+
$appContainer->get(Defaults::class),
154+
$appContainer->get(IURlGenerator::class),
155+
$appContainer->get(IFactory::class),
156+
$appContainer->get(IMailer::class),
157+
$appContainer->get(ISecureRandom::class),
165158
new TimeFactory(),
166-
$server->getConfig(),
167-
$server->getCrypto(),
159+
$appContainer->get(IConfig::class),
160+
$appContainer->get(ICrypto::class),
168161
Util::getDefaultEmailAddress('no-reply')
169162
);
170163
});

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
@@ -2265,33 +2265,6 @@
22652265
<code><![CDATA[Response]]></code>
22662266
</InvalidReturnType>
22672267
</file>
2268-
<file src="apps/settings/lib/AppInfo/Application.php">
2269-
<DeprecatedInterface>
2270-
<code><![CDATA[$serverContainer]]></code>
2271-
<code><![CDATA[$serverContainer]]></code>
2272-
<code><![CDATA[IAppContainer]]></code>
2273-
<code><![CDATA[IAppContainer]]></code>
2274-
<code><![CDATA[IAppContainer]]></code>
2275-
</DeprecatedInterface>
2276-
<DeprecatedMethod>
2277-
<code><![CDATA[getConfig]]></code>
2278-
<code><![CDATA[getCrypto]]></code>
2279-
<code><![CDATA[getL10NFactory]]></code>
2280-
<code><![CDATA[getMailer]]></code>
2281-
<code><![CDATA[getSecureRandom]]></code>
2282-
<code><![CDATA[getURLGenerator]]></code>
2283-
<code><![CDATA[query]]></code>
2284-
<code><![CDATA[query]]></code>
2285-
<code><![CDATA[query]]></code>
2286-
<code><![CDATA[query]]></code>
2287-
<code><![CDATA[query]]></code>
2288-
<code><![CDATA[query]]></code>
2289-
<code><![CDATA[query]]></code>
2290-
</DeprecatedMethod>
2291-
<UndefinedInterfaceMethod>
2292-
<code><![CDATA[getSettingsManager]]></code>
2293-
</UndefinedInterfaceMethod>
2294-
</file>
22952268
<file src="apps/settings/lib/BackgroundJobs/VerifyUserData.php">
22962269
<DeprecatedConstant>
22972270
<code><![CDATA[IAccountManager::PROPERTY_TWITTER]]></code>
@@ -3935,16 +3908,6 @@
39353908
<code><![CDATA[array]]></code>
39363909
</ImplementedReturnTypeMismatch>
39373910
</file>
3938-
<file src="lib/private/Remote/Instance.php">
3939-
<InvalidScalarArgument>
3940-
<code><![CDATA[$response]]></code>
3941-
</InvalidScalarArgument>
3942-
</file>
3943-
<file src="lib/private/Repair/Owncloud/CleanPreviews.php">
3944-
<InvalidArgument>
3945-
<code><![CDATA[false]]></code>
3946-
</InvalidArgument>
3947-
</file>
39483911
<file src="lib/private/Repair/RemoveLinkShares.php">
39493912
<InvalidPropertyAssignmentValue>
39503913
<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/private/NavigationManager.php

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

2424
/**
25-
* Manages the ownCloud navigation
25+
* Manages the nextcloud navigation
2626
*/
2727

2828
class NavigationManager implements INavigationManager {
29-
protected $entries = [];
30-
protected $closureEntries = [];
29+
protected array $entries = [];
30+
protected array $closureEntries = [];
31+
/** @var string $activeEntry */
3132
protected $activeEntry;
32-
protected $unreadCounters = [];
33-
34-
/** @var bool */
35-
protected $init = false;
33+
protected array $unreadCounters = [];
34+
protected bool $init = false;
3635
/** User defined app order (cached for the `add` function) */
3736
private array $customAppOrder;
3837

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 {

lib/private/RedisFactory.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,15 @@ class RedisFactory {
1313
public const REDIS_MINIMAL_VERSION = '4.0.0';
1414
public const REDIS_EXTRA_PARAMETERS_MINIMAL_VERSION = '5.3.0';
1515

16-
/** @var \Redis|\RedisCluster */
17-
private $instance;
16+
private \Redis|\RedisCluster|null $instance = null;
1817

19-
/**
20-
* RedisFactory constructor.
21-
*
22-
* @param SystemConfig $config
23-
*/
2418
public function __construct(
2519
private SystemConfig $config,
2620
private IEventLogger $eventLogger,
2721
) {
2822
}
2923

30-
private function create() {
24+
private function create(): void {
3125
$isCluster = in_array('redis.cluster', $this->config->getKeys(), true);
3226
$config = $isCluster
3327
? $this->config->getValue('redis.cluster', [])
@@ -121,10 +115,9 @@ private function create() {
121115
* Get the ssl context config
122116
*
123117
* @param array $config the current config
124-
* @return array|null
125118
* @throws \UnexpectedValueException
126119
*/
127-
private function getSslContext($config) {
120+
private function getSslContext(array $config): ?array {
128121
if (isset($config['ssl_context'])) {
129122
if (!$this->isConnectionParametersSupported()) {
130123
throw new \UnexpectedValueException(\sprintf(
@@ -137,14 +130,18 @@ private function getSslContext($config) {
137130
return null;
138131
}
139132

140-
public function getInstance() {
133+
public function getInstance(): \Redis|\RedisCluster {
141134
if (!$this->isAvailable()) {
142135
throw new \Exception('Redis support is not available');
143136
}
144-
if (!$this->instance instanceof \Redis) {
137+
if ($this->instance === null) {
145138
$this->create();
146139
}
147140

141+
if ($this->instance === null) {
142+
throw new \Exception('Redis support is not available');
143+
}
144+
148145
return $this->instance;
149146
}
150147

lib/private/Remote/Instance.php

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,77 +10,54 @@
1010
use OCP\Http\Client\IClientService;
1111
use OCP\ICache;
1212
use OCP\Remote\IInstance;
13+
use Override;
1314

1415
/**
1516
* Provides some basic info about a remote Nextcloud instance
1617
*/
1718
class Instance implements IInstance {
18-
/** @var string */
19-
private $url;
19+
private string $url;
20+
private ?array $status = null;
2021

21-
/** @var array|null */
22-
private $status;
23-
24-
/**
25-
* @param string $url
26-
* @param ICache $cache
27-
* @param IClientService $clientService
28-
*/
2922
public function __construct(
30-
$url,
23+
string $url,
3124
private ICache $cache,
3225
private IClientService $clientService,
3326
) {
3427
$url = str_replace('https://', '', $url);
3528
$this->url = str_replace('http://', '', $url);
3629
}
3730

38-
/**
39-
* @return string The url of the remote server without protocol
40-
*/
41-
public function getUrl() {
31+
#[Override]
32+
public function getUrl(): string {
4233
return $this->url;
4334
}
4435

45-
/**
46-
* @return string The of the remote server with protocol
47-
*/
48-
public function getFullUrl() {
36+
#[Override]
37+
public function getFullUrl(): string {
4938
return $this->getProtocol() . '://' . $this->getUrl();
5039
}
5140

52-
/**
53-
* @return string The full version string in '13.1.2.3' format
54-
*/
55-
public function getVersion() {
41+
#[Override]
42+
public function getVersion(): string {
5643
$status = $this->getStatus();
5744
return $status['version'];
5845
}
5946

60-
/**
61-
* @return string 'http' or 'https'
62-
*/
63-
public function getProtocol() {
47+
#[Override]
48+
public function getProtocol(): string {
6449
$status = $this->getStatus();
6550
return $status['protocol'];
6651
}
6752

68-
/**
69-
* Check that the remote server is installed and not in maintenance mode
70-
*
71-
* @return bool
72-
*/
73-
public function isActive() {
53+
#[Override]
54+
public function isActive(): bool {
7455
$status = $this->getStatus();
7556
return $status['installed'] && !$status['maintenance'];
7657
}
7758

78-
/**
79-
* @return array
80-
* @throws NotFoundException
81-
* @throws \Exception
82-
*/
83-
private function getStatus() {
59+
#[Override]
60+
private function getStatus(): array {
8461
if ($this->status) {
8562
return $this->status;
8663
}
@@ -113,11 +90,7 @@ private function getStatus() {
11390
return $status;
11491
}
11592

116-
/**
117-
* @param string $url
118-
* @return bool|string
119-
*/
120-
private function downloadStatus($url) {
93+
private function downloadStatus(string $url): false|string {
12194
try {
12295
$request = $this->clientService->newClient()->get($url);
12396
$content = $request->getBody();
@@ -127,7 +100,7 @@ private function downloadStatus($url) {
127100
assert(is_string($content));
128101

129102
return $content;
130-
} catch (\Exception $e) {
103+
} catch (\Exception) {
131104
return false;
132105
}
133106
}

0 commit comments

Comments
 (0)