diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-10-10 12:40:31 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-10-15 10:40:25 +0200 |
commit | 1580c8612b01bfa780d1a7372080a27d182fb7dd (patch) | |
tree | b2776d0cd254ac9d6e54828978ce18b702f550d5 /apps/user_ldap | |
parent | 4ff9b3e0ce53227e2be47c4c2dcb1fdc3e540b5f (diff) | |
download | nextcloud-server-1580c8612b01bfa780d1a7372080a27d182fb7dd.tar.gz nextcloud-server-1580c8612b01bfa780d1a7372080a27d182fb7dd.zip |
chore(apps): Apply new rector configuration to autouse classes
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/user_ldap')
35 files changed, 133 insertions, 88 deletions
diff --git a/apps/user_ldap/ajax/clearMappings.php b/apps/user_ldap/ajax/clearMappings.php index bd866769cc8..7df622f5e37 100644 --- a/apps/user_ldap/ajax/clearMappings.php +++ b/apps/user_ldap/ajax/clearMappings.php @@ -5,13 +5,13 @@ * SPDX-FileCopyrightText: 2016 ownCloud, Inc. * SPDX-License-Identifier: AGPL-3.0-only */ - use OCA\User_LDAP\Mapping\GroupMapping; use OCA\User_LDAP\Mapping\UserMapping; use OCP\EventDispatcher\IEventDispatcher; use OCP\Server; use OCP\User\Events\BeforeUserIdUnassignedEvent; use OCP\User\Events\UserIdUnassignedEvent; +use OCP\Util; // Check user and app status \OC_JSON::checkAdminUser(); @@ -41,7 +41,7 @@ try { } if ($mapping === null || !$result) { - $l = \OCP\Util::getL10N('user_ldap'); + $l = Util::getL10N('user_ldap'); throw new \Exception($l->t('Failed to clear the mappings.')); } \OC_JSON::success(); diff --git a/apps/user_ldap/ajax/deleteConfiguration.php b/apps/user_ldap/ajax/deleteConfiguration.php index b8e9a09dc1c..09899a7c6c6 100644 --- a/apps/user_ldap/ajax/deleteConfiguration.php +++ b/apps/user_ldap/ajax/deleteConfiguration.php @@ -1,5 +1,8 @@ <?php +use OCA\User_LDAP\Helper; +use OCP\Util; + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -11,10 +14,10 @@ \OC_JSON::callCheck(); $prefix = (string)$_POST['ldap_serverconfig_chooser']; -$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); +$helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); if ($helper->deleteServerConfiguration($prefix)) { \OC_JSON::success(); } else { - $l = \OCP\Util::getL10N('user_ldap'); + $l = Util::getL10N('user_ldap'); \OC_JSON::error(['message' => $l->t('Failed to delete the server configuration')]); } diff --git a/apps/user_ldap/ajax/getConfiguration.php b/apps/user_ldap/ajax/getConfiguration.php index 31372e89c20..79a7372813c 100644 --- a/apps/user_ldap/ajax/getConfiguration.php +++ b/apps/user_ldap/ajax/getConfiguration.php @@ -1,5 +1,7 @@ <?php +use OCA\User_LDAP\LDAP; + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -11,7 +13,7 @@ \OC_JSON::callCheck(); $prefix = (string)$_POST['ldap_serverconfig_chooser']; -$ldapWrapper = new OCA\User_LDAP\LDAP(); +$ldapWrapper = new LDAP(); $connection = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix); $configuration = $connection->getConfiguration(); if (isset($configuration['ldap_agent_password']) && $configuration['ldap_agent_password'] !== '') { diff --git a/apps/user_ldap/ajax/getNewServerConfigPrefix.php b/apps/user_ldap/ajax/getNewServerConfigPrefix.php index ccd96250d52..9ee225ddaa0 100644 --- a/apps/user_ldap/ajax/getNewServerConfigPrefix.php +++ b/apps/user_ldap/ajax/getNewServerConfigPrefix.php @@ -1,5 +1,8 @@ <?php +use OCA\User_LDAP\Configuration; +use OCA\User_LDAP\Helper; + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -10,7 +13,7 @@ \OC_JSON::checkAppEnabled('user_ldap'); \OC_JSON::callCheck(); -$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); +$helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); $serverConnections = $helper->getServerConfigurationPrefixes(); sort($serverConnections); $lk = array_pop($serverConnections); @@ -19,12 +22,12 @@ $nk = 's' . str_pad($ln + 1, 2, '0', STR_PAD_LEFT); $resultData = ['configPrefix' => $nk]; -$newConfig = new \OCA\User_LDAP\Configuration($nk, false); +$newConfig = new Configuration($nk, false); if (isset($_POST['copyConfig'])) { - $originalConfig = new \OCA\User_LDAP\Configuration($_POST['copyConfig']); + $originalConfig = new Configuration($_POST['copyConfig']); $newConfig->setConfiguration($originalConfig->getConfiguration()); } else { - $configuration = new \OCA\User_LDAP\Configuration($nk, false); + $configuration = new Configuration($nk, false); $newConfig->setConfiguration($configuration->getDefaults()); $resultData['defaults'] = $configuration->getDefaults(); } diff --git a/apps/user_ldap/ajax/setConfiguration.php b/apps/user_ldap/ajax/setConfiguration.php index afa3b551899..815ef040257 100644 --- a/apps/user_ldap/ajax/setConfiguration.php +++ b/apps/user_ldap/ajax/setConfiguration.php @@ -1,5 +1,7 @@ <?php +use OCA\User_LDAP\LDAP; + /** * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -23,7 +25,7 @@ foreach ($chkboxes as $boxid) { } } -$ldapWrapper = new OCA\User_LDAP\LDAP(); +$ldapWrapper = new LDAP(); $connection = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix); $connection->setConfiguration($_POST); $connection->saveConfiguration(); diff --git a/apps/user_ldap/ajax/testConfiguration.php b/apps/user_ldap/ajax/testConfiguration.php index 93e4813d8b0..16f0c583ae0 100644 --- a/apps/user_ldap/ajax/testConfiguration.php +++ b/apps/user_ldap/ajax/testConfiguration.php @@ -1,5 +1,8 @@ <?php +use OCA\User_LDAP\LDAP; +use OCP\Util; + /** * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -10,9 +13,9 @@ \OC_JSON::checkAppEnabled('user_ldap'); \OC_JSON::callCheck(); -$l = \OCP\Util::getL10N('user_ldap'); +$l = Util::getL10N('user_ldap'); -$ldapWrapper = new OCA\User_LDAP\LDAP(); +$ldapWrapper = new LDAP(); $connection = new \OCA\User_LDAP\Connection($ldapWrapper, $_POST['ldap_serverconfig_chooser']); diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php index f1778677327..fa6ed9d3a5a 100644 --- a/apps/user_ldap/ajax/wizard.php +++ b/apps/user_ldap/ajax/wizard.php @@ -1,5 +1,11 @@ <?php +use OCA\User_LDAP\AccessFactory; +use OCA\User_LDAP\Configuration; +use OCA\User_LDAP\LDAP; +use OCA\User_LDAP\Wizard; +use OCP\Util; + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -10,7 +16,7 @@ \OC_JSON::checkAppEnabled('user_ldap'); \OC_JSON::callCheck(); -$l = \OCP\Util::getL10N('user_ldap'); +$l = Util::getL10N('user_ldap'); if (!isset($_POST['action'])) { \OC_JSON::error(['message' => $l->t('No action specified')]); @@ -22,18 +28,18 @@ if (!isset($_POST['ldap_serverconfig_chooser'])) { } $prefix = (string)$_POST['ldap_serverconfig_chooser']; -$ldapWrapper = new \OCA\User_LDAP\LDAP(); -$configuration = new \OCA\User_LDAP\Configuration($prefix); +$ldapWrapper = new LDAP(); +$configuration = new Configuration($prefix); $con = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix, null); $con->setConfiguration($configuration->getConfiguration()); $con->ldapConfigurationActive = (string)true; $con->setIgnoreValidation(true); -$factory = \OC::$server->get(\OCA\User_LDAP\AccessFactory::class); +$factory = \OC::$server->get(AccessFactory::class); $access = $factory->get($con); -$wizard = new \OCA\User_LDAP\Wizard($configuration, $ldapWrapper, $access); +$wizard = new Wizard($configuration, $ldapWrapper, $access); switch ($action) { case 'guessPortAndTLS': diff --git a/apps/user_ldap/appinfo/routes.php b/apps/user_ldap/appinfo/routes.php index fae78b8982e..fb49c6f54d5 100644 --- a/apps/user_ldap/appinfo/routes.php +++ b/apps/user_ldap/appinfo/routes.php @@ -2,6 +2,9 @@ declare(strict_types=1); +use OCA\User_LDAP\AppInfo\Application; +use OCP\AppFramework\App; + /** * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -22,7 +25,7 @@ $this->create('user_ldap_ajax_testConfiguration', 'apps/user_ldap/ajax/testConfi $this->create('user_ldap_ajax_wizard', 'apps/user_ldap/ajax/wizard.php') ->actionInclude('user_ldap/ajax/wizard.php'); -$application = new \OCP\AppFramework\App('user_ldap'); +$application = new App('user_ldap'); $application->registerRoutes($this, [ 'ocs' => [ ['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'], @@ -32,8 +35,8 @@ $application->registerRoutes($this, [ ] ]); -/** @var \OCA\User_LDAP\AppInfo\Application $application */ -$application = \OC::$server->query(\OCA\User_LDAP\AppInfo\Application::class); +/** @var Application $application */ +$application = \OC::$server->query(Application::class); $application->registerRoutes($this, [ 'routes' => [ ['name' => 'renewPassword#tryRenewPassword', 'url' => '/renewpassword', 'verb' => 'POST'], diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index e0c396a2cad..ba62239138d 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -21,6 +21,7 @@ use OCP\IAppConfig; use OCP\IConfig; use OCP\IUserManager; use OCP\User\Events\UserIdAssignedEvent; +use OCP\Util; use Psr\Log\LoggerInterface; use function strlen; use function substr; @@ -260,7 +261,7 @@ class Access extends LDAPUtility { return false; } //LDAP attributes are not case sensitive - $result = \OCP\Util::mb_array_change_key_case( + $result = Util::mb_array_change_key_case( $this->invokeLDAPMethod('getAttributes', $er), MB_CASE_LOWER, 'UTF-8'); return $result; @@ -341,7 +342,7 @@ class Access extends LDAPUtility { return @$this->invokeLDAPMethod('exopPasswd', $userDN, '', $password) || @$this->invokeLDAPMethod('modReplace', $userDN, $password); } catch (ConstraintViolationException $e) { - throw new HintException('Password change rejected.', \OCP\Util::getL10N('user_ldap')->t('Password change rejected. Hint: ') . $e->getMessage(), (int)$e->getCode()); + throw new HintException('Password change rejected.', Util::getL10N('user_ldap')->t('Password change rejected. Hint: ') . $e->getMessage(), (int)$e->getCode()); } } @@ -1329,7 +1330,7 @@ class Access extends LDAPUtility { if (!is_array($item)) { continue; } - $item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8'); + $item = Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8'); foreach ($attr as $key) { if (isset($item[$key])) { if (is_array($item[$key]) && isset($item[$key]['count'])) { diff --git a/apps/user_ldap/lib/AppInfo/Application.php b/apps/user_ldap/lib/AppInfo/Application.php index ae6092ae101..3c1cb5daa12 100644 --- a/apps/user_ldap/lib/AppInfo/Application.php +++ b/apps/user_ldap/lib/AppInfo/Application.php @@ -40,6 +40,7 @@ use OCP\IUserManager; use OCP\Notification\IManager as INotificationManager; use OCP\Share\IManager as IShareManager; use OCP\User\Events\PostLoginEvent; +use OCP\Util; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -129,7 +130,7 @@ class Application extends App implements IBootstrap { $context->injectFn(Closure::fromCallable([$this, 'registerBackendDependents'])); - \OCP\Util::connectHook( + Util::connectHook( '\OCA\Files_Sharing\API\Server2Server', 'preLoginNameUsedAsUserName', '\OCA\User_LDAP\Helper', diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php index 989d0bd3929..658ade62f5d 100644 --- a/apps/user_ldap/lib/Configuration.php +++ b/apps/user_ldap/lib/Configuration.php @@ -7,6 +7,7 @@ */ namespace OCA\User_LDAP; +use OCP\Server; use Psr\Log\LoggerInterface; /** @@ -673,7 +674,7 @@ class Configuration { return [strtolower($attribute)]; } if ($value !== self::AVATAR_PREFIX_DEFAULT) { - \OCP\Server::get(LoggerInterface::class)->warning('Invalid config value to ldapUserAvatarRule; falling back to default.'); + Server::get(LoggerInterface::class)->warning('Invalid config value to ldapUserAvatarRule; falling back to default.'); } return $defaultAttributes; } diff --git a/apps/user_ldap/lib/FilesystemHelper.php b/apps/user_ldap/lib/FilesystemHelper.php index 2a17282361a..eea7ec62ad8 100644 --- a/apps/user_ldap/lib/FilesystemHelper.php +++ b/apps/user_ldap/lib/FilesystemHelper.php @@ -7,6 +7,8 @@ */ namespace OCA\User_LDAP; +use OC\Files\Filesystem; + /** * @brief wraps around static Nextcloud core methods */ @@ -17,7 +19,7 @@ class FilesystemHelper { * @return bool */ public function isLoaded() { - return \OC\Files\Filesystem::$loaded; + return Filesystem::$loaded; } /** diff --git a/apps/user_ldap/lib/GroupPluginManager.php b/apps/user_ldap/lib/GroupPluginManager.php index 37622a53480..6bdb5559a02 100644 --- a/apps/user_ldap/lib/GroupPluginManager.php +++ b/apps/user_ldap/lib/GroupPluginManager.php @@ -6,6 +6,7 @@ namespace OCA\User_LDAP; use OCP\GroupInterface; +use OCP\Server; use Psr\Log\LoggerInterface; class GroupPluginManager { @@ -41,7 +42,7 @@ class GroupPluginManager { foreach ($this->which as $action => $v) { if ((bool)($respondToActions & $action)) { $this->which[$action] = $plugin; - \OCP\Server::get(LoggerInterface::class)->debug('Registered action ' . $action . ' to plugin ' . get_class($plugin), ['app' => 'user_ldap']); + Server::get(LoggerInterface::class)->debug('Registered action ' . $action . ' to plugin ' . get_class($plugin), ['app' => 'user_ldap']); } } } diff --git a/apps/user_ldap/lib/Group_Proxy.php b/apps/user_ldap/lib/Group_Proxy.php index 1a78a65e61e..931ad7d181a 100644 --- a/apps/user_ldap/lib/Group_Proxy.php +++ b/apps/user_ldap/lib/Group_Proxy.php @@ -18,7 +18,7 @@ use OCP\GroupInterface; use OCP\IConfig; use OCP\IUserManager; -class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend, IDeleteGroupBackend, IBatchMethodsBackend, IIsAdminBackend { +class Group_Proxy extends Proxy implements GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend, IDeleteGroupBackend, IBatchMethodsBackend, IIsAdminBackend { private $backends = []; private ?Group_LDAP $refBackend = null; private Helper $helper; diff --git a/apps/user_ldap/lib/Jobs/CleanUp.php b/apps/user_ldap/lib/Jobs/CleanUp.php index 088a563dc27..12dcc1673d6 100644 --- a/apps/user_ldap/lib/Jobs/CleanUp.php +++ b/apps/user_ldap/lib/Jobs/CleanUp.php @@ -14,6 +14,7 @@ use OCA\User_LDAP\User_LDAP; use OCA\User_LDAP\User_Proxy; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; +use OCP\Server; /** * Class CleanUp @@ -95,7 +96,7 @@ class CleanUp extends TimedJob { if (isset($arguments['mapping'])) { $this->mapping = $arguments['mapping']; } else { - $this->mapping = \OCP\Server::get(UserMapping::class); + $this->mapping = Server::get(UserMapping::class); } if (isset($arguments['deletedUsersIndex'])) { diff --git a/apps/user_ldap/lib/LDAP.php b/apps/user_ldap/lib/LDAP.php index b57cae72436..5e801dec720 100644 --- a/apps/user_ldap/lib/LDAP.php +++ b/apps/user_ldap/lib/LDAP.php @@ -12,6 +12,7 @@ use OCA\User_LDAP\DataCollector\LdapDataCollector; use OCA\User_LDAP\Exceptions\ConstraintViolationException; use OCP\IConfig; use OCP\Profiler\IProfiler; +use OCP\Server; use Psr\Log\LoggerInterface; class LDAP implements ILDAPWrapper { @@ -31,7 +32,7 @@ class LDAP implements ILDAPWrapper { $profiler->add($this->dataCollector); } - $this->logger = \OCP\Server::get(LoggerInterface::class); + $this->logger = Server::get(LoggerInterface::class); } /** diff --git a/apps/user_ldap/lib/Mapping/AbstractMapping.php b/apps/user_ldap/lib/Mapping/AbstractMapping.php index 94ac3c985ca..a8f0cf84d76 100644 --- a/apps/user_ldap/lib/Mapping/AbstractMapping.php +++ b/apps/user_ldap/lib/Mapping/AbstractMapping.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Exception; use OCP\DB\IPreparedStatement; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; +use OCP\Server; use Psr\Log\LoggerInterface; /** @@ -34,7 +35,7 @@ abstract class AbstractMapping { /** * @param \OCP\IDBConnection $dbc */ - public function __construct(\OCP\IDBConnection $dbc) { + public function __construct(IDBConnection $dbc) { $this->dbc = $dbc; } @@ -333,7 +334,7 @@ abstract class AbstractMapping { */ public function map($fdn, $name, $uuid) { if (mb_strlen($fdn) > 4000) { - \OCP\Server::get(LoggerInterface::class)->error( + Server::get(LoggerInterface::class)->error( 'Cannot map, because the DN exceeds 4000 characters: {dn}', [ 'app' => 'user_ldap', diff --git a/apps/user_ldap/lib/Notification/Notifier.php b/apps/user_ldap/lib/Notification/Notifier.php index 23ad77f75f2..8858bc33f80 100644 --- a/apps/user_ldap/lib/Notification/Notifier.php +++ b/apps/user_ldap/lib/Notification/Notifier.php @@ -18,7 +18,7 @@ class Notifier implements INotifier { /** * @param IFactory $l10nFactory */ - public function __construct(\OCP\L10N\IFactory $l10nFactory) { + public function __construct(IFactory $l10nFactory) { $this->l10nFactory = $l10nFactory; } diff --git a/apps/user_ldap/lib/User/Manager.php b/apps/user_ldap/lib/User/Manager.php index 5d5ad8b2658..7b03483200d 100644 --- a/apps/user_ldap/lib/User/Manager.php +++ b/apps/user_ldap/lib/User/Manager.php @@ -77,7 +77,7 @@ class Manager { * property array * @param string $dn the DN of the user * @param string $uid the internal (owncloud) username - * @return \OCA\User_LDAP\User\User + * @return User */ private function createAndCache($dn, $uid) { $this->checkAccess(); @@ -188,7 +188,7 @@ class Manager { /** * creates and returns an instance of OfflineUser for the specified user * @param string $id - * @return \OCA\User_LDAP\User\OfflineUser + * @return OfflineUser */ public function getDeletedUser($id) { return new OfflineUser( @@ -202,7 +202,7 @@ class Manager { /** * @brief returns a User object by its Nextcloud username * @param string $id the DN or username of the user - * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null + * @return User|OfflineUser|null */ protected function createInstancyByUserName($id) { //most likely a uid. Check whether it is a deleted user @@ -219,7 +219,7 @@ class Manager { /** * @brief returns a User object by its DN or Nextcloud username * @param string $id the DN or username of the user - * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null + * @return User|OfflineUser|null * @throws \Exception when connection could not be established */ public function get($id) { diff --git a/apps/user_ldap/lib/User/OfflineUser.php b/apps/user_ldap/lib/User/OfflineUser.php index eed715ccc1c..873bd597df8 100644 --- a/apps/user_ldap/lib/User/OfflineUser.php +++ b/apps/user_ldap/lib/User/OfflineUser.php @@ -60,7 +60,7 @@ class OfflineUser { */ protected $db; /** - * @var \OCA\User_LDAP\Mapping\UserMapping + * @var UserMapping */ protected $mapping; /** @var IManager */ diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index 4a5f2442c9b..0a310f57012 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -23,6 +23,7 @@ use OCP\IUser; use OCP\IUserManager; use OCP\Notification\IManager as INotificationManager; use OCP\Server; +use OCP\Util; use Psr\Log\LoggerInterface; /** @@ -121,7 +122,7 @@ class User { $this->notificationManager = $notificationManager; $this->birthdateParser = new BirthdateParserService(); - \OCP\Util::connectHook('OC_User', 'post_login', $this, 'handlePasswordExpiry'); + Util::connectHook('OC_User', 'post_login', $this, 'handlePasswordExpiry'); } /** @@ -228,7 +229,7 @@ class User { //User Profile Field - Phone number $attr = strtolower($this->connection->ldapAttributePhone); if (!empty($attr)) { // attribute configured - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_PHONE] + $profileValues[IAccountManager::PROPERTY_PHONE] = $ldapEntry[$attr][0] ?? ''; } //User Profile Field - website @@ -237,57 +238,57 @@ class User { $cutPosition = strpos($ldapEntry[$attr][0], ' '); if ($cutPosition) { // drop appended label - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_WEBSITE] + $profileValues[IAccountManager::PROPERTY_WEBSITE] = substr($ldapEntry[$attr][0], 0, $cutPosition); } else { - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_WEBSITE] + $profileValues[IAccountManager::PROPERTY_WEBSITE] = $ldapEntry[$attr][0]; } } elseif (!empty($attr)) { // configured, but not defined - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_WEBSITE] = ''; + $profileValues[IAccountManager::PROPERTY_WEBSITE] = ''; } //User Profile Field - Address $attr = strtolower($this->connection->ldapAttributeAddress); if (isset($ldapEntry[$attr])) { if (str_contains($ldapEntry[$attr][0], '$')) { // basic format conversion from postalAddress syntax to commata delimited - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_ADDRESS] + $profileValues[IAccountManager::PROPERTY_ADDRESS] = str_replace('$', ', ', $ldapEntry[$attr][0]); } else { - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_ADDRESS] + $profileValues[IAccountManager::PROPERTY_ADDRESS] = $ldapEntry[$attr][0]; } } elseif (!empty($attr)) { // configured, but not defined - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_ADDRESS] = ''; + $profileValues[IAccountManager::PROPERTY_ADDRESS] = ''; } //User Profile Field - Twitter $attr = strtolower($this->connection->ldapAttributeTwitter); if (!empty($attr)) { - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_TWITTER] + $profileValues[IAccountManager::PROPERTY_TWITTER] = $ldapEntry[$attr][0] ?? ''; } //User Profile Field - fediverse $attr = strtolower($this->connection->ldapAttributeFediverse); if (!empty($attr)) { - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_FEDIVERSE] + $profileValues[IAccountManager::PROPERTY_FEDIVERSE] = $ldapEntry[$attr][0] ?? ''; } //User Profile Field - organisation $attr = strtolower($this->connection->ldapAttributeOrganisation); if (!empty($attr)) { - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_ORGANISATION] + $profileValues[IAccountManager::PROPERTY_ORGANISATION] = $ldapEntry[$attr][0] ?? ''; } //User Profile Field - role $attr = strtolower($this->connection->ldapAttributeRole); if (!empty($attr)) { - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_ROLE] + $profileValues[IAccountManager::PROPERTY_ROLE] = $ldapEntry[$attr][0] ?? ''; } //User Profile Field - headline $attr = strtolower($this->connection->ldapAttributeHeadline); if (!empty($attr)) { - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_HEADLINE] + $profileValues[IAccountManager::PROPERTY_HEADLINE] = $ldapEntry[$attr][0] ?? ''; } //User Profile Field - biography @@ -295,14 +296,14 @@ class User { if (isset($ldapEntry[$attr])) { if (str_contains($ldapEntry[$attr][0], '\r')) { // convert line endings - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_BIOGRAPHY] + $profileValues[IAccountManager::PROPERTY_BIOGRAPHY] = str_replace(["\r\n","\r"], "\n", $ldapEntry[$attr][0]); } else { - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_BIOGRAPHY] + $profileValues[IAccountManager::PROPERTY_BIOGRAPHY] = $ldapEntry[$attr][0]; } } elseif (!empty($attr)) { // configured, but not defined - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_BIOGRAPHY] = ''; + $profileValues[IAccountManager::PROPERTY_BIOGRAPHY] = ''; } //User Profile Field - birthday $attr = strtolower($this->connection->ldapAttributeBirthDate); @@ -310,7 +311,7 @@ class User { $value = $ldapEntry[$attr][0]; try { $birthdate = $this->birthdateParser->parseBirthdate($value); - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_BIRTHDATE] + $profileValues[IAccountManager::PROPERTY_BIRTHDATE] = $birthdate->format('Y-m-d'); } catch (InvalidArgumentException $e) { // Invalid date -> just skip the property @@ -323,7 +324,7 @@ class User { //User Profile Field - pronouns $attr = strtolower($this->connection->ldapAttributePronouns); if (!empty($attr)) { - $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_PRONOUNS] + $profileValues[IAccountManager::PROPERTY_PRONOUNS] = $ldapEntry[$attr][0] ?? ''; } // check for changed data and cache just for TTL checking @@ -354,7 +355,7 @@ class User { // system must be postponed after the login. It is to ensure // external mounts are mounted properly (e.g. with login // credentials from the session). - \OCP\Util::connectHook('OC_User', 'post_login', $this, 'updateAvatarPostLogin'); + Util::connectHook('OC_User', 'post_login', $this, 'updateAvatarPostLogin'); break; } } diff --git a/apps/user_ldap/lib/UserPluginManager.php b/apps/user_ldap/lib/UserPluginManager.php index 7c51dc70f83..bbcf4157016 100644 --- a/apps/user_ldap/lib/UserPluginManager.php +++ b/apps/user_ldap/lib/UserPluginManager.php @@ -6,6 +6,7 @@ namespace OCA\User_LDAP; use OC\User\Backend; +use OCP\Server; use Psr\Log\LoggerInterface; class UserPluginManager { @@ -43,12 +44,12 @@ class UserPluginManager { foreach ($this->which as $action => $v) { if (is_int($action) && (bool)($respondToActions & $action)) { $this->which[$action] = $plugin; - \OCP\Server::get(LoggerInterface::class)->debug('Registered action ' . $action . ' to plugin ' . get_class($plugin), ['app' => 'user_ldap']); + Server::get(LoggerInterface::class)->debug('Registered action ' . $action . ' to plugin ' . get_class($plugin), ['app' => 'user_ldap']); } } if (method_exists($plugin, 'deleteUser')) { $this->which['deleteUser'] = $plugin; - \OCP\Server::get(LoggerInterface::class)->debug('Registered action deleteUser to plugin ' . get_class($plugin), ['app' => 'user_ldap']); + Server::get(LoggerInterface::class)->debug('Registered action deleteUser to plugin ' . get_class($plugin), ['app' => 'user_ldap']); } } diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php index bd1a65f4d42..85ed69195b6 100644 --- a/apps/user_ldap/lib/User_LDAP.php +++ b/apps/user_ldap/lib/User_LDAP.php @@ -258,8 +258,8 @@ class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, I /** * checks whether a user is still available on LDAP * - * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user - * name or an instance of that user + * @param string|User $user either the Nextcloud user + * name or an instance of that user * @throws \Exception * @throws \OC\ServerNotAvailableException */ diff --git a/apps/user_ldap/lib/User_Proxy.php b/apps/user_ldap/lib/User_Proxy.php index 0c00771aa67..3abaae741d8 100644 --- a/apps/user_ldap/lib/User_Proxy.php +++ b/apps/user_ldap/lib/User_Proxy.php @@ -220,8 +220,8 @@ class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP /** * check if a user exists on LDAP * - * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user - * name or an instance of that user + * @param string|User $user either the Nextcloud user + * name or an instance of that user */ public function userExistsOnLDAP($user, bool $ignoreCache = false): bool { $id = ($user instanceof User) ? $user->getUsername() : $user; diff --git a/apps/user_ldap/lib/Wizard.php b/apps/user_ldap/lib/Wizard.php index 87f0d04f497..262777c5022 100644 --- a/apps/user_ldap/lib/Wizard.php +++ b/apps/user_ldap/lib/Wizard.php @@ -11,6 +11,7 @@ namespace OCA\User_LDAP; use OC\ServerNotAvailableException; use OCP\IL10N; use OCP\L10N\IFactory as IL10NFactory; +use OCP\Util; use Psr\Log\LoggerInterface; class Wizard extends LDAPUtility { @@ -1253,7 +1254,7 @@ class Wizard extends LDAPUtility { } // strtolower on all keys for proper comparison - $result = \OCP\Util::mb_array_change_key_case($result); + $result = Util::mb_array_change_key_case($result); $attribute = strtolower($attribute); if (isset($result[$attribute])) { foreach ($result[$attribute] as $key => $val) { diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php index 6deaad763f1..5bb4a4657cb 100644 --- a/apps/user_ldap/tests/AccessTest.php +++ b/apps/user_ldap/tests/AccessTest.php @@ -6,6 +6,7 @@ */ namespace OCA\User_LDAP\Tests; +use OC\ServerNotAvailableException; use OCA\User_LDAP\Access; use OCA\User_LDAP\Connection; use OCA\User_LDAP\Exceptions\ConstraintViolationException; @@ -19,6 +20,7 @@ use OCA\User_LDAP\User\Manager; use OCA\User_LDAP\User\OfflineUser; use OCA\User_LDAP\User\User; use OCP\EventDispatcher\IEventDispatcher; +use OCP\HintException; use OCP\IAppConfig; use OCP\IAvatarManager; use OCP\IConfig; @@ -470,19 +472,19 @@ class AccessTest extends TestCase { $this->connection ->expects($this->once()) ->method('getConnectionResource') - ->willThrowException(new \OC\ServerNotAvailableException('Connection to LDAP server could not be established')); + ->willThrowException(new ServerNotAvailableException('Connection to LDAP server could not be established')); $this->ldap ->expects($this->never()) ->method('isResource'); - $this->expectException(\OC\ServerNotAvailableException::class); + $this->expectException(ServerNotAvailableException::class); $this->expectExceptionMessage('Connection to LDAP server could not be established'); $this->access->setPassword('CN=foo', 'MyPassword'); } public function testSetPasswordWithRejectedChange(): void { - $this->expectException(\OCP\HintException::class); + $this->expectException(HintException::class); $this->expectExceptionMessage('Password change rejected.'); $this->connection diff --git a/apps/user_ldap/tests/ConnectionTest.php b/apps/user_ldap/tests/ConnectionTest.php index bc65de39f94..9cb19891b3d 100644 --- a/apps/user_ldap/tests/ConnectionTest.php +++ b/apps/user_ldap/tests/ConnectionTest.php @@ -7,6 +7,7 @@ */ namespace OCA\User_LDAP\Tests; +use OC\ServerNotAvailableException; use OCA\User_LDAP\Connection; use OCA\User_LDAP\ILDAPWrapper; @@ -18,7 +19,7 @@ use OCA\User_LDAP\ILDAPWrapper; * @package OCA\User_LDAP\Tests */ class ConnectionTest extends \Test\TestCase { - /** @var \OCA\User_LDAP\ILDAPWrapper|\PHPUnit\Framework\MockObject\MockObject */ + /** @var ILDAPWrapper|\PHPUnit\Framework\MockObject\MockObject */ protected $ldap; /** @var Connection */ @@ -114,7 +115,7 @@ class ConnectionTest extends \Test\TestCase { ->willReturnCallback(function () use (&$isThrown) { if (!$isThrown) { $isThrown = true; - throw new \OC\ServerNotAvailableException(); + throw new ServerNotAvailableException(); } return true; }); @@ -212,7 +213,7 @@ class ConnectionTest extends \Test\TestCase { try { $this->assertFalse($this->connection->bind(), 'Connection::bind() should not return true with invalid credentials.'); - } catch (\OC\ServerNotAvailableException $e) { + } catch (ServerNotAvailableException $e) { $this->fail('Failed asserting that exception of type "OC\ServerNotAvailableException" is not thrown.'); } } @@ -260,7 +261,7 @@ class ConnectionTest extends \Test\TestCase { ->method('startTls') ->willReturn(false); - $this->expectException(\OC\ServerNotAvailableException::class); + $this->expectException(ServerNotAvailableException::class); $this->expectExceptionMessage('Start TLS failed, when connecting to LDAP host ' . $host . '.'); $this->connection->init(); diff --git a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php index fd24fe8a891..30b3e573cd4 100644 --- a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php +++ b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php @@ -16,6 +16,8 @@ use OCA\User_LDAP\LDAP; use OCA\User_LDAP\User\Manager; use OCA\User_LDAP\UserPluginManager; use OCP\IAvatarManager; +use OCP\Image; +use OCP\Server; use OCP\Share\IManager; use Psr\Log\LoggerInterface; @@ -57,10 +59,10 @@ abstract class AbstractIntegrationTest { */ public function init() { \OC::$server->registerService(UserPluginManager::class, function () { - return new \OCA\User_LDAP\UserPluginManager(); + return new UserPluginManager(); }); \OC::$server->registerService(GroupPluginManager::class, function () { - return new \OCA\User_LDAP\GroupPluginManager(); + return new GroupPluginManager(); }); $this->initLDAPWrapper(); @@ -106,7 +108,7 @@ abstract class AbstractIntegrationTest { new FilesystemHelper(), \OC::$server->get(LoggerInterface::class), \OC::$server->get(IAvatarManager::class), - new \OCP\Image(), + new Image(), \OC::$server->getUserManager(), \OC::$server->getNotificationManager(), \OC::$server->get(IManager::class) @@ -124,7 +126,7 @@ abstract class AbstractIntegrationTest { * initializes the Access test instance */ protected function initAccess() { - $this->access = new Access($this->connection, $this->ldap, $this->userManager, $this->helper, \OC::$server->getConfig(), \OCP\Server::get(LoggerInterface::class)); + $this->access = new Access($this->connection, $this->ldap, $this->userManager, $this->helper, \OC::$server->getConfig(), Server::get(LoggerInterface::class)); } /** diff --git a/apps/user_ldap/tests/Integration/ExceptionOnLostConnection.php b/apps/user_ldap/tests/Integration/ExceptionOnLostConnection.php index 4618179f8ab..2beab95b71f 100644 --- a/apps/user_ldap/tests/Integration/ExceptionOnLostConnection.php +++ b/apps/user_ldap/tests/Integration/ExceptionOnLostConnection.php @@ -39,7 +39,7 @@ class ExceptionOnLostConnection { /** @var string */ private $ldapHost; - /** @var \OCA\User_LDAP\LDAP */ + /** @var LDAP */ private $ldap; /** @var bool */ diff --git a/apps/user_ldap/tests/LDAPProviderTest.php b/apps/user_ldap/tests/LDAPProviderTest.php index e96b7b59a94..5888c6624f3 100644 --- a/apps/user_ldap/tests/LDAPProviderTest.php +++ b/apps/user_ldap/tests/LDAPProviderTest.php @@ -5,12 +5,15 @@ */ namespace OCA\User_LDAP\Tests; +use OC\Config; use OC\User\Manager; use OCA\User_LDAP\Access; use OCA\User_LDAP\Connection; use OCA\User_LDAP\Group_LDAP; +use OCA\User_LDAP\Helper; use OCA\User_LDAP\IGroupLDAP; use OCA\User_LDAP\IUserLDAP; +use OCA\User_LDAP\LDAPProviderFactory; use OCA\User_LDAP\User_LDAP; use OCP\EventDispatcher\IEventDispatcher; use OCP\ICacheFactory; @@ -33,7 +36,7 @@ class LDAPProviderTest extends \Test\TestCase { private function getServerMock(IUserLDAP $userBackend, IGroupLDAP $groupBackend) { $server = $this->getMockBuilder('OC\Server') ->setMethods(['getUserManager', 'getBackends', 'getGroupManager']) - ->setConstructorArgs(['', new \OC\Config(\OC::$configDir)]) + ->setConstructorArgs(['', new Config(\OC::$configDir)]) ->getMock(); $server->expects($this->any()) ->method('getUserManager') @@ -84,7 +87,7 @@ class LDAPProviderTest extends \Test\TestCase { } private function getLDAPProvider(IServerContainer $serverContainer) { - $factory = new \OCA\User_LDAP\LDAPProviderFactory($serverContainer); + $factory = new LDAPProviderFactory($serverContainer); return $factory->getLDAPProvider(); } @@ -201,7 +204,7 @@ class LDAPProviderTest extends \Test\TestCase { $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); + $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); $ldapProvider = $this->getLDAPProvider($server); $this->assertEquals( @@ -217,7 +220,7 @@ class LDAPProviderTest extends \Test\TestCase { $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); + $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); $ldapProvider = $this->getLDAPProvider($server); $this->assertEquals( diff --git a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php b/apps/user_ldap/tests/Mapping/AbstractMappingTest.php index 84703e09616..b95856a0f4c 100644 --- a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php +++ b/apps/user_ldap/tests/Mapping/AbstractMappingTest.php @@ -11,7 +11,7 @@ use OCA\User_LDAP\Mapping\AbstractMapping; use OCP\IDBConnection; abstract class AbstractMappingTest extends \Test\TestCase { - abstract public function getMapper(\OCP\IDBConnection $dbMock); + abstract public function getMapper(IDBConnection $dbMock); /** * kiss test on isColNameValid @@ -52,7 +52,7 @@ abstract class AbstractMappingTest extends \Test\TestCase { /** * calls map() on the given mapper and asserts result for true - * @param \OCA\User_LDAP\Mapping\AbstractMapping $mapper + * @param AbstractMapping $mapper * @param array $data */ protected function mapEntries($mapper, $data) { diff --git a/apps/user_ldap/tests/Mapping/GroupMappingTest.php b/apps/user_ldap/tests/Mapping/GroupMappingTest.php index 0d407577e1b..efa42e47863 100644 --- a/apps/user_ldap/tests/Mapping/GroupMappingTest.php +++ b/apps/user_ldap/tests/Mapping/GroupMappingTest.php @@ -8,6 +8,7 @@ namespace OCA\User_LDAP\Tests\Mapping; use OCA\User_LDAP\Mapping\GroupMapping; +use OCP\IDBConnection; /** * Class GroupMappingTest @@ -17,7 +18,7 @@ use OCA\User_LDAP\Mapping\GroupMapping; * @package OCA\User_LDAP\Tests\Mapping */ class GroupMappingTest extends AbstractMappingTest { - public function getMapper(\OCP\IDBConnection $dbMock) { + public function getMapper(IDBConnection $dbMock) { return new GroupMapping($dbMock); } } diff --git a/apps/user_ldap/tests/Mapping/UserMappingTest.php b/apps/user_ldap/tests/Mapping/UserMappingTest.php index 1792a4124be..07980ba470c 100644 --- a/apps/user_ldap/tests/Mapping/UserMappingTest.php +++ b/apps/user_ldap/tests/Mapping/UserMappingTest.php @@ -8,6 +8,7 @@ namespace OCA\User_LDAP\Tests\Mapping; use OCA\User_LDAP\Mapping\UserMapping; +use OCP\IDBConnection; use OCP\Support\Subscription\IAssertion; /** @@ -18,7 +19,7 @@ use OCP\Support\Subscription\IAssertion; * @package OCA\User_LDAP\Tests\Mapping */ class UserMappingTest extends AbstractMappingTest { - public function getMapper(\OCP\IDBConnection $dbMock) { + public function getMapper(IDBConnection $dbMock) { return new UserMapping($dbMock, $this->createMock(IAssertion::class)); } } diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php index d596402d322..3939c41c4ca 100644 --- a/apps/user_ldap/tests/User/UserTest.php +++ b/apps/user_ldap/tests/User/UserTest.php @@ -19,6 +19,7 @@ use OCP\IUser; use OCP\IUserManager; use OCP\Notification\IManager as INotificationManager; use OCP\Notification\INotification; +use OCP\Util; use Psr\Log\LoggerInterface; /** @@ -1149,7 +1150,7 @@ class UserTest extends \Test\TestCase { ->method('notify'); \OC_Hook::clear();//disconnect irrelevant hooks - \OCP\Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry'); + Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry'); /** @noinspection PhpUnhandledExceptionInspection */ \OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]); } @@ -1213,7 +1214,7 @@ class UserTest extends \Test\TestCase { ->method('notify'); \OC_Hook::clear();//disconnect irrelevant hooks - \OCP\Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry'); + Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry'); /** @noinspection PhpUnhandledExceptionInspection */ \OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]); } diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index f766c7f583a..5b01b25109f 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -1238,7 +1238,7 @@ class User_LDAPTest extends TestCase { public function testSetPasswordInvalid(): void { - $this->expectException(\OCP\HintException::class); + $this->expectException(HintException::class); $this->expectExceptionMessage('Password fails quality checking policy'); $this->prepareAccessForSetPassword($this->access); @@ -1383,7 +1383,7 @@ class User_LDAPTest extends TestCase { public function testSetDisplayNameErrorWithPlugin(): void { - $this->expectException(\OCP\HintException::class); + $this->expectException(HintException::class); $newDisplayName = 'J. Baker'; $this->pluginManager->expects($this->once()) |