Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: Fix newly spotted psalm issues, add exhaustive typed magic prope…
…rties for LDAP classes

Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Apr 30, 2024
commit 672923f0a6ab5a692273326250fe1394b4e41bd9
72 changes: 70 additions & 2 deletions apps/user_ldap/lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,76 @@
use Psr\Log\LoggerInterface;

/**
* @property int ldapPagingSize holds an integer
* @property string ldapUserAvatarRule
* @property string $ldapHost
* @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 {
public const AVATAR_PREFIX_DEFAULT = 'default';
Expand Down
112 changes: 71 additions & 41 deletions apps/user_ldap/lib/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,49 +41,79 @@
use Psr\Log\LoggerInterface;

/**
* magic properties (incomplete)
* magic properties
* responsible for LDAP connections in context with the provided configuration
*
* @property string ldapHost
* @property string ldapPort holds the port number
* @property string ldapUserFilter
* @property string ldapUserDisplayName
* @property string ldapUserDisplayName2
* @property string ldapUserAvatarRule
* @property boolean turnOnPasswordChange
* @property string[] ldapBaseUsers
* @property int|null ldapPagingSize holds an integer
* @property bool|mixed|void ldapGroupMemberAssocAttr
* @property string ldapUuidUserAttribute
* @property string ldapUuidGroupAttribute
* @property string ldapExpertUUIDUserAttr
* @property string ldapExpertUUIDGroupAttr
* @property string ldapQuotaAttribute
* @property string ldapQuotaDefault
* @property string ldapEmailAttribute
* @property string ldapExtStorageHomeAttribute
* @property string homeFolderNamingRule
* @property bool|string markRemnantsAsDisabled
* @property bool|string ldapNestedGroups
* @property string[] ldapBaseGroups
* @property string ldapGroupFilter
* @property string ldapGroupDisplayName
* @property string ldapLoginFilter
* @property string ldapDynamicGroupMemberURL
* @property string ldapGidNumber
* @property int hasMemberOfFilterSupport
* @property int useMemberOfToDetectMembership
* @property string ldapMatchingRuleInChainState
* @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
* @property string $ldapHost
* @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 Connection extends LDAPUtility {
private ?\LDAP\Connection $ldapConnectionRes = null;
Expand Down
4 changes: 2 additions & 2 deletions core/Command/Preview/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ protected function configure() {
protected function execute(InputInterface $input, OutputInterface $output): int {
$fileInput = $input->getArgument("file");
$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')) {
$sizeParts = explode('x', $size, 2);
} else {
$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>");
return null;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
* Class for accessing variables in the request.
* This class provides an immutable object with request variables.
*
* @property mixed[] cookies
* @property mixed[] env
* @property mixed[] files
* @property string method
* @property mixed[] parameters
* @property mixed[] server
* @property mixed[] $cookies
* @property mixed[] $env
* @property mixed[] $files
* @property string $method
* @property mixed[] $parameters
* @property mixed[] $server
* @template-implements \ArrayAccess<string,mixed>
*/
class Request implements \ArrayAccess, \Countable, IRequest {
Expand Down
4 changes: 2 additions & 2 deletions lib/private/AppFramework/Utility/SimpleContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ public function offsetGet($id) {
/**
* @deprecated 20.0.0 use \OCP\IContainer::registerService
*/
public function offsetSet($id, $service): void {
$this->container->offsetSet($id, $service);
public function offsetSet($offset, $value): void {
$this->container->offsetSet($offset, $value);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ public function getSourcePath($path) {
$realPath = realpath($pathToResolve);
while ($realPath === false) { // for non existing files check the parent directory
$currentPath = dirname($currentPath);
/** @psalm-suppress TypeDoesNotContainType Let's be extra cautious and still check for empty string */
if ($currentPath === '' || $currentPath === '.') {
return $fullPath;
}
Expand Down
25 changes: 7 additions & 18 deletions lib/private/Group/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,15 @@ public function __construct(\OC\User\Manager $userManager,
$this->logger = $logger;
$this->displayNameCache = new DisplayNameCache($cacheFactory, $this);

$cachedGroups = &$this->cachedGroups;
$cachedUserGroups = &$this->cachedUserGroups;
$this->listen('\OC\Group', 'postDelete', function ($group) use (&$cachedGroups, &$cachedUserGroups) {
/**
* @var \OC\Group\Group $group
*/
unset($cachedGroups[$group->getGID()]);
$cachedUserGroups = [];
$this->listen('\OC\Group', 'postDelete', function (IGroup $group): void {
unset($this->cachedGroups[$group->getGID()]);
$this->cachedUserGroups = [];
});
$this->listen('\OC\Group', 'postAddUser', function ($group) use (&$cachedUserGroups) {
/**
* @var \OC\Group\Group $group
*/
$cachedUserGroups = [];
$this->listen('\OC\Group', 'postAddUser', function (IGroup $group): void {
$this->cachedUserGroups = [];
});
$this->listen('\OC\Group', 'postRemoveUser', function ($group) use (&$cachedUserGroups) {
/**
* @var \OC\Group\Group $group
*/
$cachedUserGroups = [];
$this->listen('\OC\Group', 'postRemoveUser', function (IGroup $group): void {
$this->cachedUserGroups = [];
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Preview/MimeIconProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getMimeIconUrl(string $mime): null|string {
$aliases = $this->mimetypeDetector->getAllAliases();

// Remove comments
$aliases = array_filter($aliases, static function ($key) {
$aliases = array_filter($aliases, static function (string $key) {
return !($key === '' || $key[0] === '_');
}, ARRAY_FILTER_USE_KEY);

Expand Down
29 changes: 10 additions & 19 deletions lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,26 @@ class Manager extends PublicEmitter implements IUserManager {
/**
* @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 $config;

/** @var ICache */
private $cache;

/** @var IEventDispatcher */
private $eventDispatcher;
private ICache $cache;

private DisplayNameCache $displayNameCache;

public function __construct(IConfig $config,
public function __construct(
private IConfig $config,
ICacheFactory $cacheFactory,
IEventDispatcher $eventDispatcher) {
$this->config = $config;
private IEventDispatcher $eventDispatcher,
) {
$this->cache = new WithLocalCache($cacheFactory->createDistributed('user_backend_map'));
$cachedUsers = &$this->cachedUsers;
$this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) {
/** @var \OC\User\User $user */
unset($cachedUsers[$user->getUID()]);
$this->listen('\OC\User', 'postDelete', function (IUser $user): void {
unset($this->cachedUsers[$user->getUID()]);
});
$this->eventDispatcher = $eventDispatcher;
$this->displayNameCache = new DisplayNameCache($cacheFactory, $this);
}

Expand Down