fix: Fix newly spotted psalm issues, add exhaustive typed magic properties for LDAP classes

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/44533/head
Côme Chilliet 1 month ago
parent ce2d6cd81e
commit 672923f0a6
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A

@ -38,8 +38,76 @@ namespace OCA\User_LDAP;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
/** /**
* @property int ldapPagingSize holds an integer * @property string $ldapHost
* @property string ldapUserAvatarRule * @property string $ldapPort
* @property string $ldapBackupHost
* @property string $ldapBackupPort
* @property string $ldapBackgroundHost
* @property string $ldapBackgroundPort
* @property array|'' $ldapBase
* @property array|'' $ldapBaseUsers
* @property array|'' $ldapBaseGroups
* @property string $ldapAgentName
* @property string $ldapAgentPassword
* @property string $ldapTLS
* @property string $turnOffCertCheck
* @property string $ldapIgnoreNamingRules
* @property string $ldapUserDisplayName
* @property string $ldapUserDisplayName2
* @property string $ldapUserAvatarRule
* @property string $ldapGidNumber
* @property array|'' $ldapUserFilterObjectclass
* @property array|'' $ldapUserFilterGroups
* @property string $ldapUserFilter
* @property string $ldapUserFilterMode
* @property string $ldapGroupFilter
* @property string $ldapGroupFilterMode
* @property array|'' $ldapGroupFilterObjectclass
* @property array|'' $ldapGroupFilterGroups
* @property string $ldapGroupDisplayName
* @property string $ldapGroupMemberAssocAttr
* @property string $ldapLoginFilter
* @property string $ldapLoginFilterMode
* @property string $ldapLoginFilterEmail
* @property string $ldapLoginFilterUsername
* @property array|'' $ldapLoginFilterAttributes
* @property string $ldapQuotaAttribute
* @property string $ldapQuotaDefault
* @property string $ldapEmailAttribute
* @property string $ldapCacheTTL
* @property string $ldapUuidUserAttribute
* @property string $ldapUuidGroupAttribute
* @property string $ldapOverrideMainServer
* @property string $ldapConfigurationActive
* @property array|'' $ldapAttributesForUserSearch
* @property array|'' $ldapAttributesForGroupSearch
* @property string $ldapExperiencedAdmin
* @property string $homeFolderNamingRule
* @property string $hasMemberOfFilterSupport
* @property string $useMemberOfToDetectMembership
* @property string $ldapExpertUsernameAttr
* @property string $ldapExpertUUIDUserAttr
* @property string $ldapExpertUUIDGroupAttr
* @property string $markRemnantsAsDisabled
* @property string $lastJpegPhotoLookup
* @property string $ldapNestedGroups
* @property string $ldapPagingSize
* @property string $turnOnPasswordChange
* @property string $ldapDynamicGroupMemberURL
* @property string $ldapDefaultPPolicyDN
* @property string $ldapExtStorageHomeAttribute
* @property string $ldapMatchingRuleInChainState
* @property string $ldapConnectionTimeout
* @property string $ldapAttributePhone
* @property string $ldapAttributeWebsite
* @property string $ldapAttributeAddress
* @property string $ldapAttributeTwitter
* @property string $ldapAttributeFediverse
* @property string $ldapAttributeOrganisation
* @property string $ldapAttributeRole
* @property string $ldapAttributeHeadline
* @property string $ldapAttributeBiography
* @property string $ldapAdminGroup
*/ */
class Configuration { class Configuration {
public const AVATAR_PREFIX_DEFAULT = 'default'; public const AVATAR_PREFIX_DEFAULT = 'default';

@ -41,49 +41,79 @@ use OC\ServerNotAvailableException;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
/** /**
* magic properties (incomplete) * magic properties
* responsible for LDAP connections in context with the provided configuration * responsible for LDAP connections in context with the provided configuration
* *
* @property string ldapHost * @property string $ldapHost
* @property string ldapPort holds the port number * @property string $ldapPort
* @property string ldapUserFilter * @property string $ldapBackupHost
* @property string ldapUserDisplayName * @property string $ldapBackupPort
* @property string ldapUserDisplayName2 * @property string $ldapBackgroundHost
* @property string ldapUserAvatarRule * @property string $ldapBackgroundPort
* @property boolean turnOnPasswordChange * @property array|'' $ldapBase
* @property string[] ldapBaseUsers * @property array|'' $ldapBaseUsers
* @property int|null ldapPagingSize holds an integer * @property array|'' $ldapBaseGroups
* @property bool|mixed|void ldapGroupMemberAssocAttr * @property string $ldapAgentName
* @property string ldapUuidUserAttribute * @property string $ldapAgentPassword
* @property string ldapUuidGroupAttribute * @property string $ldapTLS
* @property string ldapExpertUUIDUserAttr * @property string $turnOffCertCheck
* @property string ldapExpertUUIDGroupAttr * @property string $ldapIgnoreNamingRules
* @property string ldapQuotaAttribute * @property string $ldapUserDisplayName
* @property string ldapQuotaDefault * @property string $ldapUserDisplayName2
* @property string ldapEmailAttribute * @property string $ldapUserAvatarRule
* @property string ldapExtStorageHomeAttribute * @property string $ldapGidNumber
* @property string homeFolderNamingRule * @property array|'' $ldapUserFilterObjectclass
* @property bool|string markRemnantsAsDisabled * @property array|'' $ldapUserFilterGroups
* @property bool|string ldapNestedGroups * @property string $ldapUserFilter
* @property string[] ldapBaseGroups * @property string $ldapUserFilterMode
* @property string ldapGroupFilter * @property string $ldapGroupFilter
* @property string ldapGroupDisplayName * @property string $ldapGroupFilterMode
* @property string ldapLoginFilter * @property array|'' $ldapGroupFilterObjectclass
* @property string ldapDynamicGroupMemberURL * @property array|'' $ldapGroupFilterGroups
* @property string ldapGidNumber * @property string $ldapGroupDisplayName
* @property int hasMemberOfFilterSupport * @property string $ldapGroupMemberAssocAttr
* @property int useMemberOfToDetectMembership * @property string $ldapLoginFilter
* @property string ldapMatchingRuleInChainState * @property string $ldapLoginFilterMode
* @property string ldapAttributePhone * @property string $ldapLoginFilterEmail
* @property string ldapAttributeWebsite * @property string $ldapLoginFilterUsername
* @property string ldapAttributeAddress * @property array|'' $ldapLoginFilterAttributes
* @property string ldapAttributeTwitter * @property string $ldapQuotaAttribute
* @property string ldapAttributeFediverse * @property string $ldapQuotaDefault
* @property string ldapAttributeOrganisation * @property string $ldapEmailAttribute
* @property string ldapAttributeRole * @property string $ldapCacheTTL
* @property string ldapAttributeHeadline * @property string $ldapUuidUserAttribute
* @property string ldapAttributeBiography * @property string $ldapUuidGroupAttribute
* @property string ldapAdminGroup * @property string $ldapOverrideMainServer
* @property string $ldapConfigurationActive
* @property array|'' $ldapAttributesForUserSearch
* @property array|'' $ldapAttributesForGroupSearch
* @property string $ldapExperiencedAdmin
* @property string $homeFolderNamingRule
* @property string $hasMemberOfFilterSupport
* @property string $useMemberOfToDetectMembership
* @property string $ldapExpertUsernameAttr
* @property string $ldapExpertUUIDUserAttr
* @property string $ldapExpertUUIDGroupAttr
* @property string $markRemnantsAsDisabled
* @property string $lastJpegPhotoLookup
* @property string $ldapNestedGroups
* @property string $ldapPagingSize
* @property string $turnOnPasswordChange
* @property string $ldapDynamicGroupMemberURL
* @property string $ldapDefaultPPolicyDN
* @property string $ldapExtStorageHomeAttribute
* @property string $ldapMatchingRuleInChainState
* @property string $ldapConnectionTimeout
* @property string $ldapAttributePhone
* @property string $ldapAttributeWebsite
* @property string $ldapAttributeAddress
* @property string $ldapAttributeTwitter
* @property string $ldapAttributeFediverse
* @property string $ldapAttributeOrganisation
* @property string $ldapAttributeRole
* @property string $ldapAttributeHeadline
* @property string $ldapAttributeBiography
* @property string $ldapAdminGroup
*/ */
class Connection extends LDAPUtility { class Connection extends LDAPUtility {
private ?\LDAP\Connection $ldapConnectionRes = null; private ?\LDAP\Connection $ldapConnectionRes = null;

@ -57,13 +57,13 @@ class Generate extends Command {
protected function execute(InputInterface $input, OutputInterface $output): int { protected function execute(InputInterface $input, OutputInterface $output): int {
$fileInput = $input->getArgument("file"); $fileInput = $input->getArgument("file");
$sizes = $input->getOption("size"); $sizes = $input->getOption("size");
$sizes = array_map(function (string $size) use ($output, &$error) { $sizes = array_map(function (string $size) use ($output) {
if (str_contains($size, 'x')) { if (str_contains($size, 'x')) {
$sizeParts = explode('x', $size, 2); $sizeParts = explode('x', $size, 2);
} else { } else {
$sizeParts = [$size, $size]; $sizeParts = [$size, $size];
} }
if (!is_numeric($sizeParts[0]) || !is_numeric($sizeParts[1])) { if (!is_numeric($sizeParts[0]) || !is_numeric($sizeParts[1] ?? null)) {
$output->writeln("<error>Invalid size $size</error>"); $output->writeln("<error>Invalid size $size</error>");
return null; return null;
} }

@ -57,12 +57,12 @@ use Symfony\Component\HttpFoundation\IpUtils;
* Class for accessing variables in the request. * Class for accessing variables in the request.
* This class provides an immutable object with request variables. * This class provides an immutable object with request variables.
* *
* @property mixed[] cookies * @property mixed[] $cookies
* @property mixed[] env * @property mixed[] $env
* @property mixed[] files * @property mixed[] $files
* @property string method * @property string $method
* @property mixed[] parameters * @property mixed[] $parameters
* @property mixed[] server * @property mixed[] $server
* @template-implements \ArrayAccess<string,mixed> * @template-implements \ArrayAccess<string,mixed>
*/ */
class Request implements \ArrayAccess, \Countable, IRequest { class Request implements \ArrayAccess, \Countable, IRequest {

@ -228,8 +228,8 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer {
/** /**
* @deprecated 20.0.0 use \OCP\IContainer::registerService * @deprecated 20.0.0 use \OCP\IContainer::registerService
*/ */
public function offsetSet($id, $service): void { public function offsetSet($offset, $value): void {
$this->container->offsetSet($id, $service); $this->container->offsetSet($offset, $value);
} }
/** /**

@ -524,6 +524,7 @@ class Local extends \OC\Files\Storage\Common {
$realPath = realpath($pathToResolve); $realPath = realpath($pathToResolve);
while ($realPath === false) { // for non existing files check the parent directory while ($realPath === false) { // for non existing files check the parent directory
$currentPath = dirname($currentPath); $currentPath = dirname($currentPath);
/** @psalm-suppress TypeDoesNotContainType Let's be extra cautious and still check for empty string */
if ($currentPath === '' || $currentPath === '.') { if ($currentPath === '' || $currentPath === '.') {
return $fullPath; return $fullPath;
} }

@ -98,26 +98,15 @@ class Manager extends PublicEmitter implements IGroupManager {
$this->logger = $logger; $this->logger = $logger;
$this->displayNameCache = new DisplayNameCache($cacheFactory, $this); $this->displayNameCache = new DisplayNameCache($cacheFactory, $this);
$cachedGroups = &$this->cachedGroups; $this->listen('\OC\Group', 'postDelete', function (IGroup $group): void {
$cachedUserGroups = &$this->cachedUserGroups; unset($this->cachedGroups[$group->getGID()]);
$this->listen('\OC\Group', 'postDelete', function ($group) use (&$cachedGroups, &$cachedUserGroups) { $this->cachedUserGroups = [];
/**
* @var \OC\Group\Group $group
*/
unset($cachedGroups[$group->getGID()]);
$cachedUserGroups = [];
}); });
$this->listen('\OC\Group', 'postAddUser', function ($group) use (&$cachedUserGroups) { $this->listen('\OC\Group', 'postAddUser', function (IGroup $group): void {
/** $this->cachedUserGroups = [];
* @var \OC\Group\Group $group
*/
$cachedUserGroups = [];
}); });
$this->listen('\OC\Group', 'postRemoveUser', function ($group) use (&$cachedUserGroups) { $this->listen('\OC\Group', 'postRemoveUser', function (IGroup $group): void {
/** $this->cachedUserGroups = [];
* @var \OC\Group\Group $group
*/
$cachedUserGroups = [];
}); });
} }

@ -47,7 +47,7 @@ class MimeIconProvider implements IMimeIconProvider {
$aliases = $this->mimetypeDetector->getAllAliases(); $aliases = $this->mimetypeDetector->getAllAliases();
// Remove comments // Remove comments
$aliases = array_filter($aliases, static function ($key) { $aliases = array_filter($aliases, static function (string $key) {
return !($key === '' || $key[0] === '_'); return !($key === '' || $key[0] === '_');
}, ARRAY_FILTER_USE_KEY); }, ARRAY_FILTER_USE_KEY);

@ -79,35 +79,26 @@ class Manager extends PublicEmitter implements IUserManager {
/** /**
* @var \OCP\UserInterface[] $backends * @var \OCP\UserInterface[] $backends
*/ */
private $backends = []; private array $backends = [];
/** /**
* @var \OC\User\User[] $cachedUsers * @var array<string,\OC\User\User> $cachedUsers
*/ */
private $cachedUsers = []; private array $cachedUsers = [];
/** @var IConfig */ private ICache $cache;
private $config;
/** @var ICache */
private $cache;
/** @var IEventDispatcher */
private $eventDispatcher;
private DisplayNameCache $displayNameCache; private DisplayNameCache $displayNameCache;
public function __construct(IConfig $config, public function __construct(
private IConfig $config,
ICacheFactory $cacheFactory, ICacheFactory $cacheFactory,
IEventDispatcher $eventDispatcher) { private IEventDispatcher $eventDispatcher,
$this->config = $config; ) {
$this->cache = new WithLocalCache($cacheFactory->createDistributed('user_backend_map')); $this->cache = new WithLocalCache($cacheFactory->createDistributed('user_backend_map'));
$cachedUsers = &$this->cachedUsers; $this->listen('\OC\User', 'postDelete', function (IUser $user): void {
$this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) { unset($this->cachedUsers[$user->getUID()]);
/** @var \OC\User\User $user */
unset($cachedUsers[$user->getUID()]);
}); });
$this->eventDispatcher = $eventDispatcher;
$this->displayNameCache = new DisplayNameCache($cacheFactory, $this); $this->displayNameCache = new DisplayNameCache($cacheFactory, $this);
} }

Loading…
Cancel
Save