Skip to content

Commit 01daace

Browse files
committed
fix: As much strong type as possible
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 6ba09ba commit 01daace

9 files changed

Lines changed: 36 additions & 60 deletions

lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22

33
declare(strict_types=1);
4+
45
/**
56
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
67
* SPDX-License-Identifier: AGPL-3.0-or-later
78
*/
9+
810
namespace OCA\LdapWriteSupport\AppInfo;
911

1012
use OCA\LdapWriteSupport\Listener\GroupBackendRegisteredListener;

lib/Command/GroupAdminsToLdap.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
57
* SPDX-FileCopyrightText: 2019 Cooperativa EITA <eita.org.br>
@@ -38,7 +40,7 @@ public function __construct(
3840
}
3941

4042
#[\Override]
41-
protected function configure() {
43+
protected function configure(): void {
4244
$this
4345
->setName('ldap-ext:sync-group-admins')
4446
->setDescription('syncs group admin informations to ldap')

lib/LDAPConnect.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
57
* SPDX-FileCopyrightText: 2017 Cooperativa EITA <eita.org.br>

lib/LDAPGroupManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
57
* SPDX-FileCopyrightText: 2017-2019 Cooperativa EITA <eita.org.br>

lib/LDAPUserManager.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
57
* SPDX-FileCopyrightText: 2017-2019 Cooperativa EITA <eita.org.br>
@@ -48,7 +50,7 @@ public function __construct(
4850
* @return int bitwise-or'ed actions
4951
*/
5052
#[\Override]
51-
public function respondToActions() {
53+
public function respondToActions(): int {
5254
$setPassword = $this->canSetPassword() && !$this->ldapConnect->hasPasswordPolicy()
5355
? Backend::SET_PASSWORD
5456
: 0;
@@ -63,12 +65,11 @@ public function respondToActions() {
6365
*
6466
* @param string $uid user ID of the user
6567
* @param string $displayName new user's display name
66-
* @return string
6768
* @throws HintException
6869
* @throws ServerNotAvailableException
6970
*/
7071
#[\Override]
71-
public function setDisplayName($uid, $displayName) {
72+
public function setDisplayName($uid, $displayName): string {
7273
$userDN = $this->getUserDN($uid);
7374

7475
$connection = $this->ldapProvider->getLDAPConnection($uid);
@@ -106,10 +107,9 @@ public function setDisplayName($uid, $displayName) {
106107
* checks whether the user is allowed to change his avatar in Nextcloud
107108
*
108109
* @param string $uid the Nextcloud user name
109-
* @return bool either the user can or cannot
110110
*/
111111
#[\Override]
112-
public function canChangeAvatar($uid) {
112+
public function canChangeAvatar($uid): bool {
113113
return $this->configuration->hasAvatarPermission();
114114
}
115115

@@ -158,11 +158,10 @@ public function changeEmail(IUser $user, string $newEmail): void {
158158
*
159159
* @param string $uid The username of the user to create
160160
* @param string $password The password of the new user
161-
* @return bool|string the created user of false
162161
* @throws Exception
163162
*/
164163
#[\Override]
165-
public function createUser($uid, $password) {
164+
public function createUser($uid, $password): string|false {
166165
$adminUser = $this->userSession->getUser();
167166
$requireActorFromLDAP = $this->configuration->isLdapActorRequired();
168167
if ($requireActorFromLDAP && !$adminUser instanceof IUser) {
@@ -230,7 +229,7 @@ public function ensureAttribute(array &$ldif, string $attribute, string $fallbac
230229
}
231230
}
232231

233-
public function buildNewEntry($username, $password, $base): array {
232+
private function buildNewEntry(string $username, string $password, string $base): array {
234233
// Make sure the parameters don't fool the following algorithm
235234
if (str_contains($username, PHP_EOL)) {
236235
throw new Exception('Username contains a new line');
@@ -268,10 +267,6 @@ public function buildNewEntry($username, $password, $base): array {
268267
return [$dn, $entry];
269268
}
270269

271-
/**
272-
* @param $uid
273-
* @return bool
274-
*/
275270
public function deleteUser($uid): bool {
276271
$connection = $this->ldapProvider->getLDAPConnection($uid);
277272
$userDN = $this->getUserDN($uid);
@@ -318,12 +313,11 @@ public function canSetPassword(): bool {
318313
*
319314
* @param string $uid The username
320315
* @param string $password The new password
321-
* @return bool
322316
*
323317
* Change the password of a user
324318
*/
325319
#[\Override]
326-
public function setPassword($uid, $password) {
320+
public function setPassword($uid, $password): bool {
327321
$connection = $this->ldapProvider->getLDAPConnection($uid);
328322
$userDN = $this->getUserDN($uid);
329323

@@ -334,10 +328,9 @@ public function setPassword($uid, $password) {
334328
* get the user's home directory
335329
*
336330
* @param string $uid the username
337-
* @return bool
338331
*/
339332
#[\Override]
340-
public function getHome($uid) {
333+
public function getHome($uid): bool {
341334
// Not implemented
342335
return false;
343336
}
@@ -346,21 +339,18 @@ public function getHome($uid) {
346339
* get display name of the user
347340
*
348341
* @param string $uid user ID of the user
349-
* @return string display name
350342
*/
351343
#[\Override]
352-
public function getDisplayName($uid) {
344+
public function getDisplayName($uid): string {
353345
// Not implemented
354346
return $uid;
355347
}
356348

357349
/**
358350
* Count the number of users
359-
*
360-
* @return int|bool
361351
*/
362352
#[\Override]
363-
public function countUsers() {
353+
public function countUsers(): false {
364354
// Not implemented
365355
return false;
366356
}
@@ -398,7 +388,7 @@ public function changeUserHook(IUser $user, string $feature, $attr1, $attr2): vo
398388
}
399389
}
400390

401-
private function getUserDN($uid): string {
391+
private function getUserDN(string $uid): string {
402392
return $this->ldapProvider->getUserDN($uid);
403393
}
404394

lib/Listener/GroupBackendRegisteredListener.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4+
45
/**
56
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
67
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -18,14 +19,10 @@
1819
* @template-implements IEventListener<GroupBackendRegistered>
1920
*/
2021
class GroupBackendRegisteredListener implements IEventListener {
21-
/** @var IAppManager */
22-
private $appManager;
23-
2422
public function __construct(
25-
IAppManager $appManager,
23+
private IAppManager $appManager,
2624
private LDAPGroupManager $ldapGroupManager,
2725
) {
28-
$this->appManager = $appManager;
2926
}
3027

3128
/**

lib/Listener/UserBackendRegisteredListener.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4+
45
/**
56
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
67
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -18,14 +19,10 @@
1819
* @template-implements IEventListener<UserBackendRegistered>
1920
*/
2021
class UserBackendRegisteredListener implements IEventListener {
21-
/** @var IAppManager */
22-
private $appManager;
23-
2422
public function __construct(
25-
IAppManager $appManager,
23+
private IAppManager $appManager,
2624
private LDAPUserManager $ldapUserManager,
2725
) {
28-
$this->appManager = $appManager;
2926
}
3027

3128
/**

lib/Service/Configuration.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4+
45
/**
56
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
67
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -12,11 +13,9 @@
1213
use OCP\IConfig;
1314

1415
class Configuration {
15-
/** @var IConfig */
16-
private $config;
17-
18-
public function __construct(IConfig $config) {
19-
$this->config = $config;
16+
public function __construct(
17+
private IConfig $config,
18+
) {
2019
}
2120

2221
public function isLdapActorRequired(): bool {
@@ -39,15 +38,15 @@ public function useUnicodePassword(): bool {
3938
return $this->config->getAppValue('ldap_write_support', 'useUnicodePassword', '0') === '1';
4039
}
4140

42-
public function getUserTemplate() {
41+
public function getUserTemplate(): string {
4342
return $this->config->getAppValue(
4443
Application::APP_ID,
4544
'template.user',
4645
$this->getUserTemplateDefault()
4746
);
4847
}
4948

50-
public function getUserTemplateDefault() {
49+
public function getUserTemplateDefault(): string {
5150
return
5251
'dn: uid={UID},{BASE}' . PHP_EOL
5352
. 'objectClass: inetOrgPerson' . PHP_EOL

lib/Settings/Admin.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4+
45
/**
56
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
67
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -16,22 +17,18 @@
1617
use OCP\Util;
1718

1819
class Admin implements ISettings {
19-
/** @var IInitialState */
20-
private $initialStateService;
21-
2220
public function __construct(
23-
IInitialState $initialStateService,
21+
private IInitialState $initialStateService,
2422
private Configuration $config,
2523
) {
26-
$this->initialStateService = $initialStateService;
2724
}
2825

2926
/**
3027
* @return TemplateResponse returns the instance with all parameters set, ready to be rendered
3128
* @since 9.1
3229
*/
3330
#[\Override]
34-
public function getForm() {
31+
public function getForm(): TemplateResponse {
3532
$this->initialStateService->provideInitialState(
3633
'templates',
3734
[
@@ -58,25 +55,13 @@ public function getForm() {
5855
return new TemplateResponse(Application::APP_ID, 'settings-admin');
5956
}
6057

61-
/**
62-
* @return string the section ID, e.g. 'sharing'
63-
* @since 9.1
64-
*/
6558
#[\Override]
66-
public function getSection() {
59+
public function getSection(): string {
6760
return 'ldap';
6861
}
6962

70-
/**
71-
* @return int whether the form should be rather on the top or bottom of
72-
* the admin section. The forms are arranged in ascending order of the
73-
* priority values. It is required to return a value between 0 and 100.
74-
*
75-
* E.g.: 70
76-
* @since 9.1
77-
*/
7863
#[\Override]
79-
public function getPriority() {
64+
public function getPriority(): int {
8065
return 35;
8166
}
8267
}

0 commit comments

Comments
 (0)