Skip to content

Commit c75f87a

Browse files
come-ncmax-nextcloud
authored andcommitted
fix: Fix newly spotted psalm issues, add exhaustive typed magic properties for LDAP classes
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 7ea4c49 commit c75f87a

File tree

9 files changed

+174
-109
lines changed

9 files changed

+174
-109
lines changed

apps/user_ldap/lib/Configuration.php

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,76 @@
3838
use Psr\Log\LoggerInterface;
3939

4040
/**
41-
* @property int ldapPagingSize holds an integer
42-
* @property string ldapUserAvatarRule
41+
* @property string $ldapHost
42+
* @property string $ldapPort
43+
* @property string $ldapBackupHost
44+
* @property string $ldapBackupPort
45+
* @property string $ldapBackgroundHost
46+
* @property string $ldapBackgroundPort
47+
* @property array|'' $ldapBase
48+
* @property array|'' $ldapBaseUsers
49+
* @property array|'' $ldapBaseGroups
50+
* @property string $ldapAgentName
51+
* @property string $ldapAgentPassword
52+
* @property string $ldapTLS
53+
* @property string $turnOffCertCheck
54+
* @property string $ldapIgnoreNamingRules
55+
* @property string $ldapUserDisplayName
56+
* @property string $ldapUserDisplayName2
57+
* @property string $ldapUserAvatarRule
58+
* @property string $ldapGidNumber
59+
* @property array|'' $ldapUserFilterObjectclass
60+
* @property array|'' $ldapUserFilterGroups
61+
* @property string $ldapUserFilter
62+
* @property string $ldapUserFilterMode
63+
* @property string $ldapGroupFilter
64+
* @property string $ldapGroupFilterMode
65+
* @property array|'' $ldapGroupFilterObjectclass
66+
* @property array|'' $ldapGroupFilterGroups
67+
* @property string $ldapGroupDisplayName
68+
* @property string $ldapGroupMemberAssocAttr
69+
* @property string $ldapLoginFilter
70+
* @property string $ldapLoginFilterMode
71+
* @property string $ldapLoginFilterEmail
72+
* @property string $ldapLoginFilterUsername
73+
* @property array|'' $ldapLoginFilterAttributes
74+
* @property string $ldapQuotaAttribute
75+
* @property string $ldapQuotaDefault
76+
* @property string $ldapEmailAttribute
77+
* @property string $ldapCacheTTL
78+
* @property string $ldapUuidUserAttribute
79+
* @property string $ldapUuidGroupAttribute
80+
* @property string $ldapOverrideMainServer
81+
* @property string $ldapConfigurationActive
82+
* @property array|'' $ldapAttributesForUserSearch
83+
* @property array|'' $ldapAttributesForGroupSearch
84+
* @property string $ldapExperiencedAdmin
85+
* @property string $homeFolderNamingRule
86+
* @property string $hasMemberOfFilterSupport
87+
* @property string $useMemberOfToDetectMembership
88+
* @property string $ldapExpertUsernameAttr
89+
* @property string $ldapExpertUUIDUserAttr
90+
* @property string $ldapExpertUUIDGroupAttr
91+
* @property string $markRemnantsAsDisabled
92+
* @property string $lastJpegPhotoLookup
93+
* @property string $ldapNestedGroups
94+
* @property string $ldapPagingSize
95+
* @property string $turnOnPasswordChange
96+
* @property string $ldapDynamicGroupMemberURL
97+
* @property string $ldapDefaultPPolicyDN
98+
* @property string $ldapExtStorageHomeAttribute
99+
* @property string $ldapMatchingRuleInChainState
100+
* @property string $ldapConnectionTimeout
101+
* @property string $ldapAttributePhone
102+
* @property string $ldapAttributeWebsite
103+
* @property string $ldapAttributeAddress
104+
* @property string $ldapAttributeTwitter
105+
* @property string $ldapAttributeFediverse
106+
* @property string $ldapAttributeOrganisation
107+
* @property string $ldapAttributeRole
108+
* @property string $ldapAttributeHeadline
109+
* @property string $ldapAttributeBiography
110+
* @property string $ldapAdminGroup
43111
*/
44112
class Configuration {
45113
public const AVATAR_PREFIX_DEFAULT = 'default';

apps/user_ldap/lib/Connection.php

Lines changed: 71 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -41,49 +41,79 @@
4141
use Psr\Log\LoggerInterface;
4242

4343
/**
44-
* magic properties (incomplete)
44+
* magic properties
4545
* responsible for LDAP connections in context with the provided configuration
4646
*
47-
* @property string ldapHost
48-
* @property string ldapPort holds the port number
49-
* @property string ldapUserFilter
50-
* @property string ldapUserDisplayName
51-
* @property string ldapUserDisplayName2
52-
* @property string ldapUserAvatarRule
53-
* @property boolean turnOnPasswordChange
54-
* @property string[] ldapBaseUsers
55-
* @property int|null ldapPagingSize holds an integer
56-
* @property bool|mixed|void ldapGroupMemberAssocAttr
57-
* @property string ldapUuidUserAttribute
58-
* @property string ldapUuidGroupAttribute
59-
* @property string ldapExpertUUIDUserAttr
60-
* @property string ldapExpertUUIDGroupAttr
61-
* @property string ldapQuotaAttribute
62-
* @property string ldapQuotaDefault
63-
* @property string ldapEmailAttribute
64-
* @property string ldapExtStorageHomeAttribute
65-
* @property string homeFolderNamingRule
66-
* @property bool|string markRemnantsAsDisabled
67-
* @property bool|string ldapNestedGroups
68-
* @property string[] ldapBaseGroups
69-
* @property string ldapGroupFilter
70-
* @property string ldapGroupDisplayName
71-
* @property string ldapLoginFilter
72-
* @property string ldapDynamicGroupMemberURL
73-
* @property string ldapGidNumber
74-
* @property int hasMemberOfFilterSupport
75-
* @property int useMemberOfToDetectMembership
76-
* @property string ldapMatchingRuleInChainState
77-
* @property string ldapAttributePhone
78-
* @property string ldapAttributeWebsite
79-
* @property string ldapAttributeAddress
80-
* @property string ldapAttributeTwitter
81-
* @property string ldapAttributeFediverse
82-
* @property string ldapAttributeOrganisation
83-
* @property string ldapAttributeRole
84-
* @property string ldapAttributeHeadline
85-
* @property string ldapAttributeBiography
86-
* @property string ldapAdminGroup
47+
* @property string $ldapHost
48+
* @property string $ldapPort
49+
* @property string $ldapBackupHost
50+
* @property string $ldapBackupPort
51+
* @property string $ldapBackgroundHost
52+
* @property string $ldapBackgroundPort
53+
* @property array|'' $ldapBase
54+
* @property array|'' $ldapBaseUsers
55+
* @property array|'' $ldapBaseGroups
56+
* @property string $ldapAgentName
57+
* @property string $ldapAgentPassword
58+
* @property string $ldapTLS
59+
* @property string $turnOffCertCheck
60+
* @property string $ldapIgnoreNamingRules
61+
* @property string $ldapUserDisplayName
62+
* @property string $ldapUserDisplayName2
63+
* @property string $ldapUserAvatarRule
64+
* @property string $ldapGidNumber
65+
* @property array|'' $ldapUserFilterObjectclass
66+
* @property array|'' $ldapUserFilterGroups
67+
* @property string $ldapUserFilter
68+
* @property string $ldapUserFilterMode
69+
* @property string $ldapGroupFilter
70+
* @property string $ldapGroupFilterMode
71+
* @property array|'' $ldapGroupFilterObjectclass
72+
* @property array|'' $ldapGroupFilterGroups
73+
* @property string $ldapGroupDisplayName
74+
* @property string $ldapGroupMemberAssocAttr
75+
* @property string $ldapLoginFilter
76+
* @property string $ldapLoginFilterMode
77+
* @property string $ldapLoginFilterEmail
78+
* @property string $ldapLoginFilterUsername
79+
* @property array|'' $ldapLoginFilterAttributes
80+
* @property string $ldapQuotaAttribute
81+
* @property string $ldapQuotaDefault
82+
* @property string $ldapEmailAttribute
83+
* @property string $ldapCacheTTL
84+
* @property string $ldapUuidUserAttribute
85+
* @property string $ldapUuidGroupAttribute
86+
* @property string $ldapOverrideMainServer
87+
* @property string $ldapConfigurationActive
88+
* @property array|'' $ldapAttributesForUserSearch
89+
* @property array|'' $ldapAttributesForGroupSearch
90+
* @property string $ldapExperiencedAdmin
91+
* @property string $homeFolderNamingRule
92+
* @property string $hasMemberOfFilterSupport
93+
* @property string $useMemberOfToDetectMembership
94+
* @property string $ldapExpertUsernameAttr
95+
* @property string $ldapExpertUUIDUserAttr
96+
* @property string $ldapExpertUUIDGroupAttr
97+
* @property string $markRemnantsAsDisabled
98+
* @property string $lastJpegPhotoLookup
99+
* @property string $ldapNestedGroups
100+
* @property string $ldapPagingSize
101+
* @property string $turnOnPasswordChange
102+
* @property string $ldapDynamicGroupMemberURL
103+
* @property string $ldapDefaultPPolicyDN
104+
* @property string $ldapExtStorageHomeAttribute
105+
* @property string $ldapMatchingRuleInChainState
106+
* @property string $ldapConnectionTimeout
107+
* @property string $ldapAttributePhone
108+
* @property string $ldapAttributeWebsite
109+
* @property string $ldapAttributeAddress
110+
* @property string $ldapAttributeTwitter
111+
* @property string $ldapAttributeFediverse
112+
* @property string $ldapAttributeOrganisation
113+
* @property string $ldapAttributeRole
114+
* @property string $ldapAttributeHeadline
115+
* @property string $ldapAttributeBiography
116+
* @property string $ldapAdminGroup
87117
*/
88118
class Connection extends LDAPUtility {
89119
/**

core/Command/Preview/Generate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ protected function configure() {
5757
protected function execute(InputInterface $input, OutputInterface $output): int {
5858
$fileInput = $input->getArgument("file");
5959
$sizes = $input->getOption("size");
60-
$sizes = array_map(function (string $size) use ($output, &$error) {
60+
$sizes = array_map(function (string $size) use ($output) {
6161
if (str_contains($size, 'x')) {
6262
$sizeParts = explode('x', $size, 2);
6363
} else {
6464
$sizeParts = [$size, $size];
6565
}
66-
if (!is_numeric($sizeParts[0]) || !is_numeric($sizeParts[1])) {
66+
if (!is_numeric($sizeParts[0]) || !is_numeric($sizeParts[1] ?? null)) {
6767
$output->writeln("<error>Invalid size $size</error>");
6868
return null;
6969
}

lib/private/AppFramework/Http/Request.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@
5757
* Class for accessing variables in the request.
5858
* This class provides an immutable object with request variables.
5959
*
60-
* @property mixed[] cookies
61-
* @property mixed[] env
62-
* @property mixed[] files
63-
* @property string method
64-
* @property mixed[] parameters
65-
* @property mixed[] server
60+
* @property mixed[] $cookies
61+
* @property mixed[] $env
62+
* @property mixed[] $files
63+
* @property string $method
64+
* @property mixed[] $parameters
65+
* @property mixed[] $server
6666
* @template-implements \ArrayAccess<string,mixed>
6767
*/
6868
class Request implements \ArrayAccess, \Countable, IRequest {

lib/private/AppFramework/Utility/SimpleContainer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ public function offsetGet($id) {
228228
/**
229229
* @deprecated 20.0.0 use \OCP\IContainer::registerService
230230
*/
231-
public function offsetSet($id, $service): void {
232-
$this->container->offsetSet($id, $service);
231+
public function offsetSet($offset, $value): void {
232+
$this->container->offsetSet($offset, $value);
233233
}
234234

235235
/**

lib/private/Files/Storage/Local.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ public function getSourcePath($path) {
526526
$realPath = realpath($pathToResolve);
527527
while ($realPath === false) { // for non existing files check the parent directory
528528
$currentPath = dirname($currentPath);
529+
/** @psalm-suppress TypeDoesNotContainType Let's be extra cautious and still check for empty string */
529530
if ($currentPath === '' || $currentPath === '.') {
530531
return $fullPath;
531532
}

lib/private/Group/Manager.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,15 @@ public function __construct(\OC\User\Manager $userManager,
101101
$this->logger = $logger;
102102
$this->displayNameCache = new DisplayNameCache($cacheFactory, $this);
103103

104-
$cachedGroups = &$this->cachedGroups;
105-
$cachedUserGroups = &$this->cachedUserGroups;
106-
$this->listen('\OC\Group', 'postDelete', function ($group) use (&$cachedGroups, &$cachedUserGroups) {
107-
/**
108-
* @var \OC\Group\Group $group
109-
*/
110-
unset($cachedGroups[$group->getGID()]);
111-
$cachedUserGroups = [];
104+
$this->listen('\OC\Group', 'postDelete', function (IGroup $group): void {
105+
unset($this->cachedGroups[$group->getGID()]);
106+
$this->cachedUserGroups = [];
112107
});
113-
$this->listen('\OC\Group', 'postAddUser', function ($group) use (&$cachedUserGroups) {
114-
/**
115-
* @var \OC\Group\Group $group
116-
*/
117-
$cachedUserGroups = [];
108+
$this->listen('\OC\Group', 'postAddUser', function (IGroup $group): void {
109+
$this->cachedUserGroups = [];
118110
});
119-
$this->listen('\OC\Group', 'postRemoveUser', function ($group) use (&$cachedUserGroups) {
120-
/**
121-
* @var \OC\Group\Group $group
122-
*/
123-
$cachedUserGroups = [];
111+
$this->listen('\OC\Group', 'postRemoveUser', function (IGroup $group): void {
112+
$this->cachedUserGroups = [];
124113
});
125114
}
126115

lib/private/Preview/MimeIconProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getMimeIconUrl(string $mime): null|string {
4747
$aliases = $this->mimetypeDetector->getAllAliases();
4848

4949
// Remove comments
50-
$aliases = array_filter($aliases, static function ($key) {
50+
$aliases = array_filter($aliases, static function (string $key) {
5151
return !($key === '' || $key[0] === '_');
5252
}, ARRAY_FILTER_USE_KEY);
5353

lib/private/User/Manager.php

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,27 @@ class Manager extends PublicEmitter implements IUserManager {
7979
/**
8080
* @var \OCP\UserInterface[] $backends
8181
*/
82-
private $backends = [];
82+
private array $backends = [];
8383

8484
/**
85-
* @var \OC\User\User[] $cachedUsers
85+
* @var array<string,\OC\User\User> $cachedUsers
8686
*/
87-
private $cachedUsers = [];
87+
private array $cachedUsers = [];
8888

89-
/** @var IConfig */
90-
private $config;
91-
92-
/** @var ICache */
93-
private $cache;
94-
95-
/** @var IEventDispatcher */
96-
private $eventDispatcher;
89+
private ICache $cache;
9790

9891
private DisplayNameCache $displayNameCache;
9992

100-
public function __construct(IConfig $config,
93+
public function __construct(
94+
private IConfig $config,
10195
ICacheFactory $cacheFactory,
102-
IEventDispatcher $eventDispatcher,
103-
private LoggerInterface $logger) {
104-
$this->config = $config;
96+
private IEventDispatcher $eventDispatcher,
97+
private LoggerInterface $logger,
98+
) {
10599
$this->cache = new WithLocalCache($cacheFactory->createDistributed('user_backend_map'));
106-
$cachedUsers = &$this->cachedUsers;
107-
$this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) {
108-
/** @var \OC\User\User $user */
109-
unset($cachedUsers[$user->getUID()]);
100+
$this->listen('\OC\User', 'postDelete', function (IUser $user): void {
101+
unset($this->cachedUsers[$user->getUID()]);
110102
});
111-
$this->eventDispatcher = $eventDispatcher;
112103
$this->displayNameCache = new DisplayNameCache($cacheFactory, $this);
113104
}
114105

@@ -237,7 +228,7 @@ public function checkPassword($loginName, $password) {
237228
$result = $this->checkPasswordNoLogging($loginName, $password);
238229

239230
if ($result === false) {
240-
$this->logger->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->getRequest()->getRemoteAddress(). '\')', ['app' => 'core']);
231+
\OCP\Server::get(LoggerInterface::class)->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->getRequest()->getRemoteAddress(). '\')', ['app' => 'core']);
241232
}
242233

243234
return $result;
@@ -343,7 +334,7 @@ public function searchDisplayName($pattern, $limit = null, $offset = null) {
343334
/**
344335
* @return IUser[]
345336
*/
346-
public function getDisabledUsers(?int $limit = null, int $offset = 0, string $search = ''): array {
337+
public function getDisabledUsers(?int $limit = null, int $offset = 0): array {
347338
$users = $this->config->getUsersForUserValue('core', 'enabled', 'false');
348339
$users = array_combine(
349340
$users,
@@ -352,28 +343,14 @@ public function getDisabledUsers(?int $limit = null, int $offset = 0, string $se
352343
$users
353344
)
354345
);
355-
if ($search !== '') {
356-
$users = array_filter(
357-
$users,
358-
function (IUser $user) use ($search): bool {
359-
try {
360-
return mb_stripos($user->getUID(), $search) !== false ||
361-
mb_stripos($user->getDisplayName(), $search) !== false ||
362-
mb_stripos($user->getEMailAddress() ?? '', $search) !== false;
363-
} catch (NoUserException $ex) {
364-
$this->logger->error('Error while filtering disabled users', ['exception' => $ex, 'userUID' => $user->getUID()]);
365-
return false;
366-
}
367-
});
368-
}
369346

370347
$tempLimit = ($limit === null ? null : $limit + $offset);
371348
foreach ($this->backends as $backend) {
372349
if (($tempLimit !== null) && (count($users) >= $tempLimit)) {
373350
break;
374351
}
375352
if ($backend instanceof IProvideEnabledStateBackend) {
376-
$backendUsers = $backend->getDisabledUserList(($tempLimit === null ? null : $tempLimit - count($users)), 0, $search);
353+
$backendUsers = $backend->getDisabledUserList(($tempLimit === null ? null : $tempLimit - count($users)));
377354
foreach ($backendUsers as $uid) {
378355
$users[$uid] = new LazyUser($uid, $this, null, $backend);
379356
}

0 commit comments

Comments
 (0)