diff options
Diffstat (limited to 'apps/user_ldap')
43 files changed, 719 insertions, 721 deletions
diff --git a/apps/user_ldap/ajax/clearMappings.php b/apps/user_ldap/ajax/clearMappings.php index 3e98162904c..f847b818db0 100644 --- a/apps/user_ldap/ajax/clearMappings.php +++ b/apps/user_ldap/ajax/clearMappings.php @@ -56,5 +56,5 @@ try { } \OC_JSON::success(); } catch (\Exception $e) { - \OC_JSON::error(array('message' => $e->getMessage())); + \OC_JSON::error(['message' => $e->getMessage()]); } diff --git a/apps/user_ldap/ajax/deleteConfiguration.php b/apps/user_ldap/ajax/deleteConfiguration.php index d6bce7439f7..c2bf4f265d0 100644 --- a/apps/user_ldap/ajax/deleteConfiguration.php +++ b/apps/user_ldap/ajax/deleteConfiguration.php @@ -36,5 +36,5 @@ if($helper->deleteServerConfiguration($prefix)) { \OC_JSON::success(); } else { $l = \OC::$server->getL10N('user_ldap'); - \OC_JSON::error(array('message' => $l->t('Failed to delete the server configuration'))); + \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 b8ed917de6e..8c9a3a6c3f6 100644 --- a/apps/user_ldap/ajax/getConfiguration.php +++ b/apps/user_ldap/ajax/getConfiguration.php @@ -38,4 +38,4 @@ if (isset($configuration['ldap_agent_password']) && $configuration['ldap_agent_p // hide password $configuration['ldap_agent_password'] = '**PASSWORD SET**'; } -\OC_JSON::success(array('configuration' => $configuration)); +\OC_JSON::success(['configuration' => $configuration]); diff --git a/apps/user_ldap/ajax/getNewServerConfigPrefix.php b/apps/user_ldap/ajax/getNewServerConfigPrefix.php index 9c6f63fc3de..9d93b2b8971 100644 --- a/apps/user_ldap/ajax/getNewServerConfigPrefix.php +++ b/apps/user_ldap/ajax/getNewServerConfigPrefix.php @@ -35,7 +35,7 @@ $lk = array_pop($serverConnections); $ln = (int)str_replace('s', '', $lk); $nk = 's'.str_pad($ln+1, 2, '0', STR_PAD_LEFT); -$resultData = array('configPrefix' => $nk); +$resultData = ['configPrefix' => $nk]; $newConfig = new \OCA\User_LDAP\Configuration($nk, false); if(isset($_POST['copyConfig'])) { diff --git a/apps/user_ldap/ajax/setConfiguration.php b/apps/user_ldap/ajax/setConfiguration.php index 31aa80d0945..fd8a2b0c1b5 100644 --- a/apps/user_ldap/ajax/setConfiguration.php +++ b/apps/user_ldap/ajax/setConfiguration.php @@ -35,8 +35,8 @@ $prefix = (string)$_POST['ldap_serverconfig_chooser']; // Checkboxes are not submitted, when they are unchecked. Set them manually. // only legacy checkboxes (Advanced and Expert tab) need to be handled here, // the Wizard-like tabs handle it on their own -$chkboxes = array('ldap_configuration_active', 'ldap_override_main_server', - 'ldap_turn_off_cert_check'); +$chkboxes = ['ldap_configuration_active', 'ldap_override_main_server', + 'ldap_turn_off_cert_check']; foreach($chkboxes as $boxid) { if(!isset($_POST[$boxid])) { $_POST[$boxid] = 0; diff --git a/apps/user_ldap/ajax/testConfiguration.php b/apps/user_ldap/ajax/testConfiguration.php index 00393ff66e3..a21cb407558 100644 --- a/apps/user_ldap/ajax/testConfiguration.php +++ b/apps/user_ldap/ajax/testConfiguration.php @@ -66,23 +66,23 @@ try { * pass (like e.g. expected syntax error). */ try { - $ldapWrapper->read($connection->getConnectionResource(), '', 'objectClass=*', array('dn')); + $ldapWrapper->read($connection->getConnectionResource(), '', 'objectClass=*', ['dn']); } catch (\Exception $e) { if($e->getCode() === 1) { - \OC_JSON::error(array('message' => $l->t('Invalid configuration: Anonymous binding is not allowed.'))); + \OC_JSON::error(['message' => $l->t('Invalid configuration: Anonymous binding is not allowed.')]); exit; } } - \OC_JSON::success(array('message' - => $l->t('Valid configuration, connection established!'))); + \OC_JSON::success(['message' + => $l->t('Valid configuration, connection established!')]); } else { - \OC_JSON::error(array('message' - => $l->t('Valid configuration, but binding failed. Please check the server settings and credentials.'))); + \OC_JSON::error(['message' + => $l->t('Valid configuration, but binding failed. Please check the server settings and credentials.')]); } } else { - \OC_JSON::error(array('message' - => $l->t('Invalid configuration. Please have a look at the logs for further details.'))); + \OC_JSON::error(['message' + => $l->t('Invalid configuration. Please have a look at the logs for further details.')]); } } catch (\Exception $e) { - \OC_JSON::error(array('message' => $e->getMessage())); + \OC_JSON::error(['message' => $e->getMessage()]); } diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php index 3cce732f070..1756e978de2 100644 --- a/apps/user_ldap/ajax/wizard.php +++ b/apps/user_ldap/ajax/wizard.php @@ -36,13 +36,13 @@ $l = \OC::$server->getL10N('user_ldap'); if(!isset($_POST['action'])) { - \OC_JSON::error(array('message' => $l->t('No action specified'))); + \OC_JSON::error(['message' => $l->t('No action specified')]); } $action = (string)$_POST['action']; if(!isset($_POST['ldap_serverconfig_chooser'])) { - \OC_JSON::error(array('message' => $l->t('No configuration specified'))); + \OC_JSON::error(['message' => $l->t('No configuration specified')]); } $prefix = (string)$_POST['ldap_serverconfig_chooser']; @@ -99,7 +99,7 @@ switch($action) { exit; } } catch (\Exception $e) { - \OC_JSON::error(array('message' => $e->getMessage(), 'code' => $e->getCode())); + \OC_JSON::error(['message' => $e->getMessage(), 'code' => $e->getCode()]); exit; } \OC_JSON::error(); @@ -115,7 +115,7 @@ switch($action) { exit; } } catch (\Exception $e) { - \OC_JSON::error(array('message' => $e->getMessage())); + \OC_JSON::error(['message' => $e->getMessage()]); exit; } \OC_JSON::error(); @@ -127,15 +127,15 @@ switch($action) { $key = isset($_POST['cfgkey']) ? $_POST['cfgkey'] : false; $val = isset($_POST['cfgval']) ? $_POST['cfgval'] : null; if($key === false || is_null($val)) { - \OC_JSON::error(array('message' => $l->t('No data specified'))); + \OC_JSON::error(['message' => $l->t('No data specified')]); exit; } - $cfg = array($key => $val); - $setParameters = array(); + $cfg = [$key => $val]; + $setParameters = []; $configuration->setConfiguration($cfg, $setParameters); if(!in_array($key, $setParameters)) { - \OC_JSON::error(array('message' => $l->t($key. - ' Could not set configuration %s', $setParameters[0]))); + \OC_JSON::error(['message' => $l->t($key. + ' Could not set configuration %s', $setParameters[0])]); exit; } $configuration->saveConfiguration(); @@ -145,6 +145,6 @@ switch($action) { \OC_JSON::success(); break; default: - \OC_JSON::error(array('message' => $l->t('Action does not exist'))); + \OC_JSON::error(['message' => $l->t('Action does not exist')]); break; } diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index a16e8f04cb2..6f6e3648e30 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -75,7 +75,7 @@ class Access extends LDAPUtility { /** * @var string[] $cookies an array of returned Paged Result cookies */ - protected $cookies = array(); + protected $cookies = []; /** * @var string $lastCookie the last cookie returned from a Paged Results @@ -268,9 +268,9 @@ class Access extends LDAPUtility { * @throws ServerNotAvailableException */ public function executeRead($cr, $dn, $attribute, $filter, $maxResults) { - $this->initPagedSearch($filter, array($dn), array($attribute), $maxResults, 0); + $this->initPagedSearch($filter, [$dn], [$attribute], $maxResults, 0); $dn = $this->helper->DNasBaseParameter($dn); - $rr = @$this->invokeLDAPMethod('read', $cr, $dn, $filter, array($attribute)); + $rr = @$this->invokeLDAPMethod('read', $cr, $dn, $filter, [$attribute]); if (!$this->ldap->isResource($rr)) { if ($attribute !== '') { //do not throw this message on userExists check, irritates @@ -384,13 +384,13 @@ class Access extends LDAPUtility { * @return boolean if so true, otherwise false */ private function resemblesDN($attr) { - $resemblingAttributes = array( + $resemblingAttributes = [ 'dn', 'uniquemember', 'member', // memberOf is an "operational" attribute, without a definition in any RFC 'memberof' - ); + ]; return in_array($attr, $resemblingAttributes); } @@ -419,7 +419,7 @@ class Access extends LDAPUtility { //not a valid DN return ''; } - $domainParts = array(); + $domainParts = []; $dcFound = false; foreach($allParts as $part) { if(!$dcFound && strpos($part, 'dc=') === 0) { @@ -865,13 +865,13 @@ class Access extends LDAPUtility { */ private function createAltInternalOwnCloudName($name, $isUser) { $originalTTL = $this->connection->ldapCacheTTL; - $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); + $this->connection->setConfiguration(['ldapCacheTTL' => 0]); if($isUser) { $altName = $this->_createAltInternalOwnCloudNameForUsers($name); } else { $altName = $this->_createAltInternalOwnCloudNameForGroups($name); } - $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); + $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]); return $altName; } @@ -884,7 +884,7 @@ class Access extends LDAPUtility { * @param array $attributes optional, list of attributes to read * @return array */ - public function fetchUsersByLoginName($loginName, $attributes = array('dn')) { + public function fetchUsersByLoginName($loginName, $attributes = ['dn']) { $loginName = $this->escapeFilterPart($loginName); $filter = str_replace('%uid', $loginName, $this->connection->ldapLoginFilter); return $this->fetchListOfUsers($filter, $attributes); @@ -996,13 +996,13 @@ class Access extends LDAPUtility { $attribute = array_keys($item)[0]; $carry[] = $item[$attribute][0]; return $carry; - }, array()); + }, []); return array_unique($list, SORT_LOCALE_STRING); } } //error cause actually, maybe throw an exception in future. - return array(); + return []; } /** @@ -1033,7 +1033,7 @@ class Access extends LDAPUtility { * @return false|int * @throws ServerNotAvailableException */ - public function countUsers($filter, $attr = array('dn'), $limit = null, $offset = null) { + public function countUsers($filter, $attr = ['dn'], $limit = null, $offset = null) { $result = false; foreach($this->connection->ldapBaseUsers as $base) { $count = $this->count($filter, [$base], $attr, $limit, $offset); @@ -1072,7 +1072,7 @@ class Access extends LDAPUtility { * @return int|bool * @throws ServerNotAvailableException */ - public function countGroups($filter, $attr = array('dn'), $limit = null, $offset = null) { + public function countGroups($filter, $attr = ['dn'], $limit = null, $offset = null) { $result = false; foreach($this->connection->ldapBaseGroups as $base) { $count = $this->count($filter, [$base], $attr, $limit, $offset); @@ -1122,7 +1122,7 @@ class Access extends LDAPUtility { if ($command == 'controlPagedResultResponse') { throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.'); } else { - return call_user_func_array(array($this->ldap, $command), $arguments); + return call_user_func_array([$this->ldap, $command], $arguments); } }; try { @@ -1162,7 +1162,7 @@ class Access extends LDAPUtility { */ private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) { if(!is_null($attr) && !is_array($attr)) { - $attr = array(mb_strtolower($attr, 'UTF-8')); + $attr = [mb_strtolower($attr, 'UTF-8')]; } // See if we have a resource, in case not cancel with message @@ -1177,7 +1177,7 @@ class Access extends LDAPUtility { //check whether paged search should be attempted $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, $offset); - $linkResources = array_pad(array(), count($base), $cr); + $linkResources = array_pad([], count($base), $cr); $sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr); // cannot use $cr anymore, might have changed in the previous call! $error = $this->ldap->errno($this->connection->getConnectionResource()); @@ -1186,7 +1186,7 @@ class Access extends LDAPUtility { return false; } - return array($sr, $pagedSearchOK); + return [$sr, $pagedSearchOK]; } /** @@ -1349,7 +1349,7 @@ class Access extends LDAPUtility { $this->processPagedSearchStatus($sr, $filter, $base, 1, $limitPerPage, $offset, $pagedSearchOK, $skipHandling); - return array(); + return []; } $iFoundItems = 0; @@ -1370,7 +1370,7 @@ class Access extends LDAPUtility { // if we're here, probably no connection resource is returned. // to make Nextcloud behave nicely, we simply give back an empty array. if(is_null($findings)) { - return array(); + return []; } if(!is_null($attr)) { @@ -1463,8 +1463,8 @@ class Access extends LDAPUtility { $asterisk = '*'; $input = mb_substr($input, 1, null, 'UTF-8'); } - $search = array('*', '\\', '(', ')'); - $replace = array('\\*', '\\\\', '\\(', '\\)'); + $search = ['*', '\\', '(', ')']; + $replace = ['\\*', '\\\\', '\\(', '\\)']; return $asterisk . str_replace($search, $replace, $input); } @@ -1541,11 +1541,11 @@ class Access extends LDAPUtility { throw new \Exception('searchAttributes must be an array with at least two string'); } $searchWords = explode(' ', trim($search)); - $wordFilters = array(); + $wordFilters = []; foreach($searchWords as $word) { $word = $this->prepareSearchTerm($word); //every word needs to appear at least once - $wordMatchOneAttrFilters = array(); + $wordMatchOneAttrFilters = []; foreach($searchAttributes as $attr) { $wordMatchOneAttrFilters[] = $attr . '=' . $word; } @@ -1563,7 +1563,7 @@ class Access extends LDAPUtility { * @return string the final filter part to use in LDAP searches */ private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) { - $filter = array(); + $filter = []; $haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0); if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { try { @@ -1619,10 +1619,10 @@ class Access extends LDAPUtility { * @return string */ public function getFilterForUserCount() { - $filter = $this->combineFilterWithAnd(array( + $filter = $this->combineFilterWithAnd([ $this->connection->ldapUserFilter, $this->connection->ldapUserDisplayName . '=*' - )); + ]); return $filter; } @@ -1635,10 +1635,10 @@ class Access extends LDAPUtility { public function areCredentialsValid($name, $password) { $name = $this->helper->DNasBaseParameter($name); $testConnection = clone $this->connection; - $credentials = array( + $credentials = [ 'ldapAgentName' => $name, 'ldapAgentPassword' => $password - ); + ]; if(!$testConnection->setConfiguration($credentials)) { return false; } @@ -1919,7 +1919,7 @@ class Access extends LDAPUtility { // precision (see https://gist.github.com/bantu/886ac680b0aef5812f71) $iav = number_format(hexdec(bin2hex(substr($sid, 2, 6))), 0, '', ''); - $subIDs = array(); + $subIDs = []; for ($i = 0; $i < $numberSubID; $i++) { $subID = unpack('V', substr($sid, $subIdStart + $subIdLength * $i, $subIdLength)); $subIDs[] = sprintf('%u', $subID[1]); @@ -2065,7 +2065,7 @@ class Access extends LDAPUtility { // to start from 0 to come to the desired page. cookie value // of '0' is valid, because 389ds $reOffset = ($offset - $limit) < 0 ? 0 : $offset - $limit; - $this->search($filter, array($base), $attr, $limit, $reOffset, true); + $this->search($filter, [$base], $attr, $limit, $reOffset, true); $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset); //still no cookie? obviously, the server does not like us. Let's skip paging efforts. // '0' is valid, because 389ds diff --git a/apps/user_ldap/lib/Command/ShowConfig.php b/apps/user_ldap/lib/Command/ShowConfig.php index fd33a0bc0df..46d08986617 100644 --- a/apps/user_ldap/lib/Command/ShowConfig.php +++ b/apps/user_ldap/lib/Command/ShowConfig.php @@ -94,8 +94,8 @@ class ShowConfig extends Command { ksort($configuration); $table = new Table($output); - $table->setHeaders(array('Configuration', $id)); - $rows = array(); + $table->setHeaders(['Configuration', $id]); + $rows = []; foreach($configuration as $key => $value) { if($key === 'ldapAgentPassword' && !$withPassword) { $value = '***'; @@ -103,7 +103,7 @@ class ShowConfig extends Command { if(is_array($value)) { $value = implode(';', $value); } - $rows[] = array($key, $value); + $rows[] = [$key, $value]; } $table->setRows($rows); $table->render($output); diff --git a/apps/user_ldap/lib/Command/TestConfig.php b/apps/user_ldap/lib/Command/TestConfig.php index 67ff73d4e91..b38d2e972a2 100644 --- a/apps/user_ldap/lib/Command/TestConfig.php +++ b/apps/user_ldap/lib/Command/TestConfig.php @@ -80,9 +80,9 @@ class TestConfig extends Command { //ensure validation is run before we attempt the bind $connection->getConfiguration(); - if(!$connection->setConfiguration(array( + if(!$connection->setConfiguration([ 'ldap_configuration_active' => 1, - ))) { + ])) { return 1; } if($connection->bind()) { diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php index 724f240847a..9fa386a8215 100644 --- a/apps/user_ldap/lib/Configuration.php +++ b/apps/user_ldap/lib/Configuration.php @@ -53,7 +53,7 @@ class Configuration { protected $unsavedChanges = ['ldapConfigurationActive' => 'ldapConfigurationActive']; //settings - protected $config = array( + protected $config = [ 'ldapHost' => null, 'ldapPort' => null, 'ldapBackupHost' => null, @@ -109,7 +109,7 @@ class Configuration { 'ldapDynamicGroupMemberURL' => null, 'ldapDefaultPPolicyDN' => null, 'ldapExtStorageHomeAttribute' => null, - ); + ]; /** * @param string $configPrefix @@ -138,7 +138,7 @@ class Configuration { * @param mixed $value */ public function __set($name, $value) { - $this->setConfiguration(array($name => $value)); + $this->setConfiguration([$name => $value]); } /** @@ -426,7 +426,7 @@ class Configuration { * to config-value entries in the database table */ public function getDefaults() { - return array( + return [ 'ldap_host' => '', 'ldap_port' => '', 'ldap_backup_host' => '', @@ -481,7 +481,7 @@ class Configuration { 'ldap_default_ppolicy_dn' => '', 'ldap_user_avatar_rule' => 'default', 'ldap_ext_storage_home_attribute' => '', - ); + ]; } /** @@ -489,7 +489,7 @@ class Configuration { */ public function getConfigTranslationArray() { //TODO: merge them into one representation - static $array = array( + static $array = [ 'ldap_host' => 'ldapHost', 'ldap_port' => 'ldapPort', 'ldap_backup_host' => 'ldapBackupHost', @@ -543,7 +543,7 @@ class Configuration { 'ldap_default_ppolicy_dn' => 'ldapDefaultPPolicyDN', 'ldap_ext_storage_home_attribute' => 'ldapExtStorageHomeAttribute', 'ldapIgnoreNamingRules' => 'ldapIgnoreNamingRules', // sysconfig - ); + ]; return $array; } diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php index 8d499a4ee1c..5e2d7fb8583 100644 --- a/apps/user_ldap/lib/Connection.php +++ b/apps/user_ldap/lib/Connection.php @@ -298,7 +298,7 @@ class Connection extends LDAPUtility { */ public function setConfiguration($config, &$setParameters = null) { if(is_null($setParameters)) { - $setParameters = array(); + $setParameters = []; } $this->doNotValidate = false; $this->configuration->setConfiguration($config, $setParameters); @@ -328,7 +328,7 @@ class Connection extends LDAPUtility { $this->readConfiguration(); $config = $this->configuration->getConfiguration(); $cta = $this->configuration->getConfigTranslationArray(); - $result = array(); + $result = []; foreach($cta as $dbkey => $configkey) { switch($configkey) { case 'homeFolderNamingRule': @@ -356,15 +356,15 @@ class Connection extends LDAPUtility { private function doSoftValidation() { //if User or Group Base are not set, take over Base DN setting - foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { + foreach(['ldapBaseUsers', 'ldapBaseGroups'] as $keyBase) { $val = $this->configuration->$keyBase; if(empty($val)) { $this->configuration->$keyBase = $this->configuration->ldapBase; } } - foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', - 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') + foreach(['ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', + 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute'] as $expertSetting => $effectiveSetting) { $uuidOverride = $this->configuration->$expertSetting; if(!empty($uuidOverride)) { @@ -392,12 +392,12 @@ class Connection extends LDAPUtility { } //make sure empty search attributes are saved as simple, empty array - $saKeys = array('ldapAttributesForUserSearch', - 'ldapAttributesForGroupSearch'); + $saKeys = ['ldapAttributesForUserSearch', + 'ldapAttributesForGroupSearch']; foreach($saKeys as $key) { $val = $this->configuration->$key; if(is_array($val) && count($val) === 1 && empty($val[0])) { - $this->configuration->$key = array(); + $this->configuration->$key = []; } } @@ -421,8 +421,8 @@ class Connection extends LDAPUtility { (string)$this->configPrefix .'): '; //options that shall not be empty - $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', - 'ldapGroupDisplayName', 'ldapLoginFilter'); + $options = ['ldapHost', 'ldapPort', 'ldapUserDisplayName', + 'ldapGroupDisplayName', 'ldapLoginFilter']; foreach($options as $key) { $val = $this->configuration->$key; if(empty($val)) { diff --git a/apps/user_ldap/lib/GroupPluginManager.php b/apps/user_ldap/lib/GroupPluginManager.php index 115cc8d3fdb..f1b36923ada 100644 --- a/apps/user_ldap/lib/GroupPluginManager.php +++ b/apps/user_ldap/lib/GroupPluginManager.php @@ -29,14 +29,14 @@ class GroupPluginManager { private $respondToActions = 0; - private $which = array( + private $which = [ GroupInterface::CREATE_GROUP => null, GroupInterface::DELETE_GROUP => null, GroupInterface::ADD_TO_GROUP => null, GroupInterface::REMOVE_FROM_GROUP => null, GroupInterface::COUNT_USERS => null, GroupInterface::GROUP_DETAILS => null - ); + ]; /** * @return int All implemented actions diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php index 40b8bcf16c9..c19f6ac4ed6 100644 --- a/apps/user_ldap/lib/Group_LDAP.php +++ b/apps/user_ldap/lib/Group_LDAP.php @@ -138,8 +138,8 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD //extra work if we don't get back user DNs if(strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { - $dns = array(); - $filterParts = array(); + $dns = []; + $filterParts = []; $bytes = 0; foreach($members as $mid) { $filter = str_replace('%uid', $mid, $this->access->connection->ldapLoginFilter); @@ -150,7 +150,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD // to take even the chance to exceed it $filter = $this->access->combineFilterWithOr($filterParts); $bytes = 0; - $filterParts = array(); + $filterParts = []; $users = $this->access->fetchListOfUsers($filter, 'dn', count($filterParts)); $dns = array_merge($dns, $users); } @@ -182,10 +182,10 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD $dynamicGroupMemberURL = strtolower($this->access->connection->ldapDynamicGroupMemberURL); if (empty($dynamicGroupMemberURL)) { - return array(); + return []; } - $dynamicMembers = array(); + $dynamicMembers = []; $memberURLs = $this->access->readAttribute( $dnGroup, $dynamicGroupMemberURL, @@ -199,7 +199,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD if ($pos !== false) { $memberUrlFilter = substr($memberURLs[0], $pos); $foundMembers = $this->access->searchUsers($memberUrlFilter,'dn'); - $dynamicMembers = array(); + $dynamicMembers = []; foreach($foundMembers as $value) { $dynamicMembers[$value['dn'][0]] = 1; } @@ -335,7 +335,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD 'objectClass=posixGroup', $this->access->connection->ldapGidNumber . '=' . $gid ]); - $result = $this->access->searchGroups($filter, array('dn'), 1); + $result = $this->access->searchGroups($filter, ['dn'], 1); if(empty($result)) { return false; } @@ -493,11 +493,11 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD } //we need to get the DN from LDAP - $filter = $this->access->combineFilterWithAnd(array( + $filter = $this->access->combineFilterWithAnd([ $this->access->connection->ldapGroupFilter, 'objectsid=' . $domainObjectSid . '-' . $gid - )); - $result = $this->access->searchGroups($filter, array('dn'), 1); + ]); + $result = $this->access->searchGroups($filter, ['dn'], 1); if(empty($result)) { return false; } @@ -590,13 +590,13 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD $filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search); $users = $this->access->fetchListOfUsers( $filter, - array($this->access->connection->ldapUserDisplayName, 'dn'), + [$this->access->connection->ldapUserDisplayName, 'dn'], $limit, $offset ); return $this->access->nextcloudUserNames($users); } catch (\Exception $e) { - return array(); + return []; } } @@ -612,7 +612,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD public function countUsersInPrimaryGroup($groupDN, $search = '', $limit = -1, $offset = 0) { try { $filter = $this->prepareFilterForUsersInPrimaryGroup($groupDN, $search); - $users = $this->access->countUsers($filter, array('dn'), $limit, $offset); + $users = $this->access->countUsers($filter, ['dn'], $limit, $offset); return (int)$users; } catch (\Exception $e) { return 0; @@ -648,7 +648,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD */ public function getUserGroups($uid) { if(!$this->enabled) { - return array(); + return []; } $cacheKey = 'getUserGroups'.$uid; $userGroups = $this->access->connection->getFromCache($cacheKey); @@ -657,8 +657,8 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD } $userDN = $this->access->username2dn($uid); if(!$userDN) { - $this->access->connection->writeToCache($cacheKey, array()); - return array(); + $this->access->connection->writeToCache($cacheKey, []); + return []; } $groups = []; @@ -670,7 +670,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD if (!empty($dynamicGroupMemberURL)) { // look through dynamic groups to add them to the result array if needed $groupsToMatch = $this->access->fetchListOfGroups( - $this->access->connection->ldapGroupFilter,array('dn',$dynamicGroupMemberURL)); + $this->access->connection->ldapGroupFilter,['dn',$dynamicGroupMemberURL]); foreach($groupsToMatch as $dynamicGroup) { if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) { continue; @@ -816,10 +816,10 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD */ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { if(!$this->enabled) { - return array(); + return []; } if(!$this->groupExists($gid)) { - return array(); + return []; } $search = $this->access->escapeFilterPart($search, true); $cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset; @@ -843,8 +843,8 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD $groupDN = $this->access->groupname2dn($gid); if(!$groupDN) { // group couldn't be found, return empty resultset - $this->access->connection->writeToCache($cacheKey, array()); - return array(); + $this->access->connection->writeToCache($cacheKey, []); + return []; } $primaryUsers = $this->getUsersInPrimaryGroup($groupDN, $search, $limit, $offset); @@ -856,19 +856,19 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD return []; } - $groupUsers = array(); + $groupUsers = []; $isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid'); $attrs = $this->access->userManager->getAttributes(true); foreach($members as $member) { if($isMemberUid) { //we got uids, need to get their DNs to 'translate' them to user names - $filter = $this->access->combineFilterWithAnd(array( + $filter = $this->access->combineFilterWithAnd([ str_replace('%uid', trim($member), $this->access->connection->ldapLoginFilter), $this->access->combineFilterWithAnd([ $this->access->getFilterPartForUserSearch($search), $this->access->connection->ldapUserFilter ]) - )); + ]); $ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1); if(count($ldap_users) < 1) { continue; @@ -968,14 +968,14 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD // and let it count. //For now this is not important, because the only use of this method //does not supply a search string - $groupUsers = array(); + $groupUsers = []; foreach($members as $member) { if($isMemberUid) { //we got uids, need to get their DNs to 'translate' them to user names - $filter = $this->access->combineFilterWithAnd(array( + $filter = $this->access->combineFilterWithAnd([ str_replace('%uid', $member, $this->access->connection->ldapLoginFilter), $this->access->getFilterPartForUserSearch($search) - )); + ]); $ldap_users = $this->access->fetchListOfUsers($filter, 'dn', 1); if(count($ldap_users) < 1) { continue; @@ -1013,7 +1013,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD */ protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) { if(!$this->enabled) { - return array(); + return []; } $cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset; @@ -1029,13 +1029,13 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD if($limit <= 0) { $limit = null; } - $filter = $this->access->combineFilterWithAnd(array( + $filter = $this->access->combineFilterWithAnd([ $this->access->connection->ldapGroupFilter, $this->access->getFilterPartForGroupSearch($search) - )); + ]); \OCP\Util::writeLog('user_ldap', 'getGroups Filter '.$filter, ILogger::DEBUG); $ldap_groups = $this->access->fetchListOfGroups($filter, - array($this->access->connection->ldapGroupDisplayName, 'dn'), + [$this->access->connection->ldapGroupDisplayName, 'dn'], $limit, $offset); $ldap_groups = $this->access->nextcloudGroupNames($ldap_groups); @@ -1059,7 +1059,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD */ public function getGroups($search = '', $limit = -1, $offset = 0) { if(!$this->enabled) { - return array(); + return []; } $search = $this->access->escapeFilterPart($search, true); $pagingSize = (int)$this->access->connection->ldapPagingSize; @@ -1073,7 +1073,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD $overallLimit = $maxGroups; } $chunkOffset = $offset; - $allGroups = array(); + $allGroups = []; while ($chunkOffset < $overallLimit) { $chunkLimit = min($pagingSize, $overallLimit - $chunkOffset); $ldapGroups = $this->getGroupsChunk($search, $chunkLimit, $chunkOffset); diff --git a/apps/user_ldap/lib/Group_Proxy.php b/apps/user_ldap/lib/Group_Proxy.php index 3b39d4398c7..441bf141a38 100644 --- a/apps/user_ldap/lib/Group_Proxy.php +++ b/apps/user_ldap/lib/Group_Proxy.php @@ -30,7 +30,7 @@ namespace OCA\User_LDAP; use OCP\Group\Backend\IGetDisplayNameBackend; class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGetDisplayNameBackend { - private $backends = array(); + private $backends = []; private $refBackend = null; /** @@ -58,7 +58,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet protected function walkBackends($gid, $method, $parameters) { $cacheKey = $this->getGroupCacheKey($gid); foreach($this->backends as $configPrefix => $backend) { - if($result = call_user_func_array(array($backend, $method), $parameters)) { + if($result = call_user_func_array([$backend, $method], $parameters)) { $this->writeToCache($cacheKey, $configPrefix); return $result; } @@ -80,13 +80,13 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet //in case the uid has been found in the past, try this stored connection first if(!is_null($prefix)) { if(isset($this->backends[$prefix])) { - $result = call_user_func_array(array($this->backends[$prefix], $method), $parameters); + $result = call_user_func_array([$this->backends[$prefix], $method], $parameters); if($result === $passOnWhen) { //not found here, reset cache to null if group vanished //because sometimes methods return false with a reason $groupExists = call_user_func_array( - array($this->backends[$prefix], 'groupExists'), - array($gid) + [$this->backends[$prefix], 'groupExists'], + [$gid] ); if(!$groupExists) { $this->writeToCache($cacheKey, null); @@ -107,7 +107,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet * Checks whether the user is member of a group or not. */ public function inGroup($uid, $gid) { - return $this->handleRequest($gid, 'inGroup', array($uid, $gid)); + return $this->handleRequest($gid, 'inGroup', [$uid, $gid]); } /** @@ -119,7 +119,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet * if the user exists at all. */ public function getUserGroups($uid) { - $groups = array(); + $groups = []; foreach($this->backends as $backend) { $backendGroups = $backend->getUserGroups($uid); @@ -136,7 +136,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet * @return string[] with user ids */ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { - $users = array(); + $users = []; foreach($this->backends as $backend) { $backendUsers = $backend->usersInGroup($gid, $search, $limit, $offset); @@ -154,7 +154,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet */ public function createGroup($gid) { return $this->handleRequest( - $gid, 'createGroup', array($gid)); + $gid, 'createGroup', [$gid]); } /** @@ -164,7 +164,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet */ public function deleteGroup($gid) { return $this->handleRequest( - $gid, 'deleteGroup', array($gid)); + $gid, 'deleteGroup', [$gid]); } /** @@ -177,7 +177,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet */ public function addToGroup($uid, $gid) { return $this->handleRequest( - $gid, 'addToGroup', array($uid, $gid)); + $gid, 'addToGroup', [$uid, $gid]); } /** @@ -190,7 +190,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet */ public function removeFromGroup($uid, $gid) { return $this->handleRequest( - $gid, 'removeFromGroup', array($uid, $gid)); + $gid, 'removeFromGroup', [$uid, $gid]); } /** @@ -201,7 +201,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet */ public function countUsersInGroup($gid, $search = '') { return $this->handleRequest( - $gid, 'countUsersInGroup', array($gid, $search)); + $gid, 'countUsersInGroup', [$gid, $search]); } /** @@ -211,7 +211,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet */ public function getGroupDetails($gid) { return $this->handleRequest( - $gid, 'getGroupDetails', array($gid)); + $gid, 'getGroupDetails', [$gid]); } /** @@ -221,7 +221,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet * Returns a list with all groups */ public function getGroups($search = '', $limit = -1, $offset = 0) { - $groups = array(); + $groups = []; foreach($this->backends as $backend) { $backendGroups = $backend->getGroups($search, $limit, $offset); @@ -239,7 +239,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet * @return bool */ public function groupExists($gid) { - return $this->handleRequest($gid, 'groupExists', array($gid)); + return $this->handleRequest($gid, 'groupExists', [$gid]); } /** @@ -271,7 +271,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet * @return resource of the LDAP connection */ public function getNewLDAPConnection($gid) { - return $this->handleRequest($gid, 'getNewLDAPConnection', array($gid)); + return $this->handleRequest($gid, 'getNewLDAPConnection', [$gid]); } public function getDisplayName(string $gid): string { diff --git a/apps/user_ldap/lib/Helper.php b/apps/user_ldap/lib/Helper.php index 4279ea72c71..6962a3cb978 100644 --- a/apps/user_ldap/lib/Helper.php +++ b/apps/user_ldap/lib/Helper.php @@ -99,7 +99,7 @@ class Helper { $keys = $this->getServersConfig($referenceConfigkey); - $result = array(); + $result = []; foreach($keys as $key) { $len = strlen($key) - strlen($referenceConfigkey); $prefix = substr($key, 0, $len); @@ -164,7 +164,7 @@ class Helper { AND `appid` = \'user_ldap\' AND `configkey` NOT IN (\'enabled\', \'installed_version\', \'types\', \'bgjUpdateGroupsLastRun\') '); - $delRows = $query->execute(array($prefix.'%')); + $delRows = $query->execute([$prefix.'%']); if($delRows === null) { return false; @@ -234,7 +234,7 @@ class Helper { public function sanitizeDN($dn) { //treating multiple base DNs if(is_array($dn)) { - $result = array(); + $result = []; foreach($dn as $singleDN) { $result[] = $this->sanitizeDN($singleDN); } @@ -251,7 +251,7 @@ class Helper { //escape DN values according to RFC 2253 – this is already done by ldap_explode_dn //to use the DN in search filters, \ needs to be escaped to \5c additionally //to use them in bases, we convert them back to simple backslashes in readAttribute() - $replacements = array( + $replacements = [ '\,' => '\5c2C', '\=' => '\5c3D', '\+' => '\5c2B', @@ -263,7 +263,7 @@ class Helper { '(' => '\28', ')' => '\29', '*' => '\2A', - ); + ]; $dn = str_replace(array_keys($replacements), array_values($replacements), $dn); return $dn; diff --git a/apps/user_ldap/lib/Jobs/Sync.php b/apps/user_ldap/lib/Jobs/Sync.php index 174897d8639..7b95950bda5 100644 --- a/apps/user_ldap/lib/Jobs/Sync.php +++ b/apps/user_ldap/lib/Jobs/Sync.php @@ -161,11 +161,11 @@ class Sync extends TimedJob { $access = $this->accessFactory->get($connection); $access->setUserMapper($this->mapper); - $filter = $access->combineFilterWithAnd(array( + $filter = $access->combineFilterWithAnd([ $access->connection->ldapUserFilter, $access->connection->ldapUserDisplayName . '=*', $access->getFilterPartForUserSearch('') - )); + ]); $results = $access->fetchListOfUsers( $filter, $access->userManager->getAttributes(), diff --git a/apps/user_ldap/lib/Jobs/UpdateGroups.php b/apps/user_ldap/lib/Jobs/UpdateGroups.php index ef42f36f54f..bf5d730c3b8 100644 --- a/apps/user_ldap/lib/Jobs/UpdateGroups.php +++ b/apps/user_ldap/lib/Jobs/UpdateGroups.php @@ -104,21 +104,21 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob { $actualUsers = self::getGroupBE()->usersInGroup($group); $hasChanged = false; foreach(array_diff($knownUsers, $actualUsers) as $removedUser) { - \OCP\Util::emitHook('OC_User', 'post_removeFromGroup', array('uid' => $removedUser, 'gid' => $group)); + \OCP\Util::emitHook('OC_User', 'post_removeFromGroup', ['uid' => $removedUser, 'gid' => $group]); \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – "'.$removedUser.'" removed from "'.$group.'".', ILogger::INFO); $hasChanged = true; } foreach(array_diff($actualUsers, $knownUsers) as $addedUser) { - \OCP\Util::emitHook('OC_User', 'post_addToGroup', array('uid' => $addedUser, 'gid' => $group)); + \OCP\Util::emitHook('OC_User', 'post_addToGroup', ['uid' => $addedUser, 'gid' => $group]); \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – "'.$addedUser.'" added to "'.$group.'".', ILogger::INFO); $hasChanged = true; } if($hasChanged) { - $query->execute(array(serialize($actualUsers), $group)); + $query->execute([serialize($actualUsers), $group]); } } \OCP\Util::writeLog('user_ldap', @@ -141,7 +141,7 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob { 'bgJ "updateGroups" – new group "'.$createdGroup.'" found.', ILogger::INFO); $users = serialize(self::getGroupBE()->usersInGroup($createdGroup)); - $query->execute(array($createdGroup, $users)); + $query->execute([$createdGroup, $users]); } \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – FINISHED dealing with created Groups.', @@ -162,7 +162,7 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob { \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – group "'.$removedGroup.'" was removed.', ILogger::INFO); - $query->execute(array($removedGroup)); + $query->execute([$removedGroup]); } \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – FINISHED dealing with removed groups.', @@ -217,7 +217,7 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob { FROM `*PREFIX*ldap_group_members` '); $result = $query->execute()->fetchAll(); - self::$groupsFromDB = array(); + self::$groupsFromDB = []; foreach($result as $dataset) { self::$groupsFromDB[$dataset['owncloudname']] = $dataset; } diff --git a/apps/user_ldap/lib/LDAP.php b/apps/user_ldap/lib/LDAP.php index e68c3149696..8c8a6bfbf1e 100644 --- a/apps/user_ldap/lib/LDAP.php +++ b/apps/user_ldap/lib/LDAP.php @@ -35,7 +35,7 @@ use OCA\User_LDAP\Exceptions\ConstraintViolationException; class LDAP implements ILDAPWrapper { protected $curFunc = ''; - protected $curArgs = array(); + protected $curArgs = []; /** * @param resource $link @@ -71,7 +71,7 @@ class LDAP implements ILDAPWrapper { */ public function controlPagedResultResponse($link, $result, &$cookie) { $this->preFunctionCall('ldap_control_paged_result_response', - array($link, $result, $cookie)); + [$link, $result, $cookie]); $result = ldap_control_paged_result_response($link, $result, $cookie); $this->postFunctionCall(); @@ -217,7 +217,7 @@ class LDAP implements ILDAPWrapper { * @return bool */ public function modReplace($link, $userDN, $password) { - return $this->invokeLDAPMethod('mod_replace', $link, $userDN, array('userPassword' => $password)); + return $this->invokeLDAPMethod('mod_replace', $link, $userDN, ['userPassword' => $password]); } /** diff --git a/apps/user_ldap/lib/Mapping/AbstractMapping.php b/apps/user_ldap/lib/Mapping/AbstractMapping.php index 472cd8d2779..fecc25da92e 100644 --- a/apps/user_ldap/lib/Mapping/AbstractMapping.php +++ b/apps/user_ldap/lib/Mapping/AbstractMapping.php @@ -84,7 +84,7 @@ abstract class AbstractMapping { WHERE `' . $compareCol . '` = ? '); - $res = $query->execute(array($search)); + $res = $query->execute([$search]); if($res !== false) { return $query->fetchColumn(); } @@ -126,7 +126,7 @@ abstract class AbstractMapping { WHERE `directory_uuid` = ? '); - return $this->modify($query, array($fdn, $uuid)); + return $this->modify($query, [$fdn, $uuid]); } /** @@ -171,8 +171,8 @@ abstract class AbstractMapping { WHERE `owncloud_name` LIKE ? '); - $res = $query->execute(array($prefixMatch.$this->dbc->escapeLikeParameter($search).$postfixMatch)); - $names = array(); + $res = $query->execute([$prefixMatch.$this->dbc->escapeLikeParameter($search).$postfixMatch]); + $names = []; if($res !== false) { while($row = $query->fetch()) { $names[] = $row['owncloud_name']; @@ -240,11 +240,11 @@ abstract class AbstractMapping { return false; } - $row = array( + $row = [ 'ldap_dn' => $fdn, 'owncloud_name' => $name, 'directory_uuid' => $uuid - ); + ]; try { $result = $this->dbc->insertIfNotExist($this->getTableName(), $row); @@ -265,7 +265,7 @@ abstract class AbstractMapping { DELETE FROM `'. $this->getTableName() .'` WHERE `owncloud_name` = ?'); - return $this->modify($query, array($name)); + return $this->modify($query, [$name]); } /** diff --git a/apps/user_ldap/lib/Proxy.php b/apps/user_ldap/lib/Proxy.php index 24313fc7bfb..4515e53c6c4 100644 --- a/apps/user_ldap/lib/Proxy.php +++ b/apps/user_ldap/lib/Proxy.php @@ -37,7 +37,7 @@ use OCA\User_LDAP\Mapping\UserMapping; use OCA\User_LDAP\User\Manager; abstract class Proxy { - static private $accesses = array(); + static private $accesses = []; private $ldap = null; /** @var \OCP\ICache|null */ diff --git a/apps/user_ldap/lib/User/OfflineUser.php b/apps/user_ldap/lib/User/OfflineUser.php index 1511f3bcd61..c75a144e909 100644 --- a/apps/user_ldap/lib/User/OfflineUser.php +++ b/apps/user_ldap/lib/User/OfflineUser.php @@ -105,7 +105,7 @@ class OfflineUser { * @return array */ public function export() { - $data = array(); + $data = []; $data['ocName'] = $this->getOCName(); $data['dn'] = $this->getDN(); $data['uid'] = $this->getUID(); @@ -223,7 +223,7 @@ class OfflineUser { FROM `*PREFIX*share` WHERE `uid_owner` = ? ', 1); - $query->execute(array($this->ocName)); + $query->execute([$this->ocName]); $sResult = $query->fetchColumn(0); if((int)$sResult === 1) { $this->hasActiveShares = true; @@ -235,7 +235,7 @@ class OfflineUser { FROM `*PREFIX*share_external` WHERE `owner` = ? ', 1); - $query->execute(array($this->ocName)); + $query->execute([$this->ocName]); $sResult = $query->fetchColumn(0); if((int)$sResult === 1) { $this->hasActiveShares = true; diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index dea5d91c0ce..eb126b94bfe 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -96,7 +96,7 @@ class User { /** * @var string[] */ - protected $refreshedFeatures = array(); + protected $refreshedFeatures = []; /** * @var string */ @@ -125,7 +125,7 @@ class User { IConfig $config, FilesystemHelper $fs, Image $image, LogWrapper $log, IAvatarManager $avatarManager, IUserManager $userManager, INotificationManager $notificationManager) { - + if ($username === null) { $log->log("uid for '$dn' must not be null!", ILogger::ERROR); throw new \InvalidArgumentException('uid must not be null!'); @@ -683,7 +683,7 @@ class User { * @throws \OC\ServerNotAvailableException */ public function updateExtStorageHome(string $valueFromLDAP = null):string { - if($valueFromLDAP === null) { + if ($valueFromLDAP === null) { $extHomeValues = $this->access->readAttribute($this->getDN(), $this->connection->ldapExtStorageHomeAttribute); } else { $extHomeValues = [$valueFromLDAP]; @@ -709,67 +709,65 @@ class User { return;//password expiry handling disabled } $uid = $params['uid']; - if(isset($uid) && $uid === $this->getUsername()) { + if (isset($uid) && $uid === $this->getUsername()) { //retrieve relevant user attributes - $result = $this->access->search('objectclass=*', array($this->dn), ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']); - - if(array_key_exists('pwdpolicysubentry', $result[0])) { + $result = $this->access->search('objectclass=*', [$this->dn], ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']); + + if (array_key_exists('pwdpolicysubentry', $result[0])) { $pwdPolicySubentry = $result[0]['pwdpolicysubentry']; - if($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){ + if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){ $ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN } } - - $pwdGraceUseTime = array_key_exists('pwdgraceusetime', $result[0]) ? $result[0]['pwdgraceusetime'] : null; - $pwdReset = array_key_exists('pwdreset', $result[0]) ? $result[0]['pwdreset'] : null; - $pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : null; - + + $pwdGraceUseTime = array_key_exists('pwdgraceusetime', $result[0]) ? $result[0]['pwdgraceusetime'] : []; + $pwdReset = array_key_exists('pwdreset', $result[0]) ? $result[0]['pwdreset'] : []; + $pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : []; + //retrieve relevant password policy attributes $cacheKey = 'ppolicyAttributes' . $ppolicyDN; $result = $this->connection->getFromCache($cacheKey); if(is_null($result)) { - $result = $this->access->search('objectclass=*', array($ppolicyDN), ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']); + $result = $this->access->search('objectclass=*', [$ppolicyDN], ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']); $this->connection->writeToCache($cacheKey, $result); } - - $pwdGraceAuthNLimit = array_key_exists('pwdgraceauthnlimit', $result[0]) ? $result[0]['pwdgraceauthnlimit'] : null; - $pwdMaxAge = array_key_exists('pwdmaxage', $result[0]) ? $result[0]['pwdmaxage'] : null; - $pwdExpireWarning = array_key_exists('pwdexpirewarning', $result[0]) ? $result[0]['pwdexpirewarning'] : null; - + + $pwdGraceAuthNLimit = array_key_exists('pwdgraceauthnlimit', $result[0]) ? $result[0]['pwdgraceauthnlimit'] : []; + $pwdMaxAge = array_key_exists('pwdmaxage', $result[0]) ? $result[0]['pwdmaxage'] : []; + $pwdExpireWarning = array_key_exists('pwdexpirewarning', $result[0]) ? $result[0]['pwdexpirewarning'] : []; + //handle grace login - $pwdGraceUseTimeCount = count($pwdGraceUseTime); - if($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login? - if($pwdGraceAuthNLimit - && (count($pwdGraceAuthNLimit) > 0) - &&($pwdGraceUseTimeCount < (int)$pwdGraceAuthNLimit[0])) { //at least one more grace login available? + if (!empty($pwdGraceUseTime)) { //was this a grace login? + if (!empty($pwdGraceAuthNLimit) + && count($pwdGraceUseTime) < (int)$pwdGraceAuthNLimit[0]) { //at least one more grace login available? $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true'); header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute( - 'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid))); + 'user_ldap.renewPassword.showRenewPasswordForm', ['user' => $uid])); } else { //no more grace login available header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute( - 'user_ldap.renewPassword.showLoginFormInvalidPassword', array('user' => $uid))); + 'user_ldap.renewPassword.showLoginFormInvalidPassword', ['user' => $uid])); } exit(); } //handle pwdReset attribute - if($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password + if (!empty($pwdReset) && $pwdReset[0] === 'TRUE') { //user must change his password $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true'); header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute( - 'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid))); + 'user_ldap.renewPassword.showRenewPasswordForm', ['user' => $uid])); exit(); } //handle password expiry warning - if($pwdChangedTime && (count($pwdChangedTime) > 0)) { - if($pwdMaxAge && (count($pwdMaxAge) > 0) - && $pwdExpireWarning && (count($pwdExpireWarning) > 0)) { + if (!empty($pwdChangedTime)) { + if (!empty($pwdMaxAge) + && !empty($pwdExpireWarning)) { $pwdMaxAgeInt = (int)$pwdMaxAge[0]; $pwdExpireWarningInt = (int)$pwdExpireWarning[0]; - if($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){ + if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){ $pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]); $pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S')); $currentDateTime = new \DateTime(); $secondsToExpiry = $pwdChangedTimeDt->getTimestamp() - $currentDateTime->getTimestamp(); - if($secondsToExpiry <= $pwdExpireWarningInt) { + if ($secondsToExpiry <= $pwdExpireWarningInt) { //remove last password expiry warning if any $notification = $this->notificationManager->createNotification(); $notification->setApp('user_ldap') @@ -782,7 +780,7 @@ class User { $notification->setApp('user_ldap') ->setUser($uid) ->setDateTime($currentDateTime) - ->setObject('pwd_exp_warn', $uid) + ->setObject('pwd_exp_warn', $uid) ->setSubject('pwd_exp_warn_days', [(int) ceil($secondsToExpiry / 60 / 60 / 24)]) ; $this->notificationManager->notify($notification); diff --git a/apps/user_ldap/lib/UserPluginManager.php b/apps/user_ldap/lib/UserPluginManager.php index 1407bec011d..6301257b1af 100644 --- a/apps/user_ldap/lib/UserPluginManager.php +++ b/apps/user_ldap/lib/UserPluginManager.php @@ -32,7 +32,7 @@ class UserPluginManager { private $respondToActions = 0; - private $which = array( + private $which = [ Backend::CREATE_USER => null, Backend::SET_PASSWORD => null, Backend::GET_HOME => null, @@ -41,7 +41,7 @@ class UserPluginManager { Backend::PROVIDE_AVATAR => null, Backend::COUNT_USERS => null, 'deleteUser' => null - ); + ]; /** * @return int All implemented actions, except for 'deleteUser' diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php index 323e59860f3..fec3b25a78e 100644 --- a/apps/user_ldap/lib/User_LDAP.php +++ b/apps/user_ldap/lib/User_LDAP.php @@ -260,11 +260,11 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn if($limit <= 0) { $limit = null; } - $filter = $this->access->combineFilterWithAnd(array( + $filter = $this->access->combineFilterWithAnd([ $this->access->connection->ldapUserFilter, $this->access->connection->ldapUserDisplayName . '=*', $this->access->getFilterPartForUserSearch($search) - )); + ]); Util::writeLog('user_ldap', 'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter, @@ -511,7 +511,7 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn return $displayNames; } - $displayNames = array(); + $displayNames = []; $users = $this->getUsers($search, $limit, $offset); foreach ($users as $user) { $displayNames[$user] = $this->getDisplayName($user); diff --git a/apps/user_ldap/lib/User_Proxy.php b/apps/user_ldap/lib/User_Proxy.php index 96be4a7529f..2edc0d2d64a 100644 --- a/apps/user_ldap/lib/User_Proxy.php +++ b/apps/user_ldap/lib/User_Proxy.php @@ -84,7 +84,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, && method_exists($this->getAccess($configPrefix), $method)) { $instance = $this->getAccess($configPrefix); } - if($result = call_user_func_array(array($instance, $method), $parameters)) { + if($result = call_user_func_array([$instance, $method], $parameters)) { $this->writeToCache($cacheKey, $configPrefix); return $result; } @@ -160,7 +160,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, */ public function getUsers($search = '', $limit = 10, $offset = 0) { //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends - $users = array(); + $users = []; foreach($this->backends as $backend) { $backendUsers = $backend->getUsers($search, $limit, $offset); if (is_array($backendUsers)) { @@ -177,7 +177,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, */ public function userExists($uid) { $existsOnLDAP = false; - $existsLocally = $this->handleRequest($uid, 'userExists', array($uid)); + $existsLocally = $this->handleRequest($uid, 'userExists', [$uid]); if($existsLocally) { $existsOnLDAP = $this->userExistsOnLDAP($uid); } @@ -202,7 +202,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, */ public function userExistsOnLDAP($user) { $id = ($user instanceof User) ? $user->getUsername() : $user; - return $this->handleRequest($id, 'userExistsOnLDAP', array($user)); + return $this->handleRequest($id, 'userExistsOnLDAP', [$user]); } /** @@ -214,7 +214,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, * Check if the password is correct without logging in the user */ public function checkPassword($uid, $password) { - return $this->handleRequest($uid, 'checkPassword', array($uid, $password)); + return $this->handleRequest($uid, 'checkPassword', [$uid, $password]); } /** @@ -225,7 +225,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, */ public function loginName2UserName($loginName) { $id = 'LOGINNAME,' . $loginName; - return $this->handleRequest($id, 'loginName2UserName', array($loginName)); + return $this->handleRequest($id, 'loginName2UserName', [$loginName]); } /** @@ -236,7 +236,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, */ public function dn2UserName($dn) { $id = 'DN,' . $dn; - return $this->handleRequest($id, 'dn2UserName', array($dn)); + return $this->handleRequest($id, 'dn2UserName', [$dn]); } /** @@ -245,7 +245,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, * @return boolean */ public function getHome($uid) { - return $this->handleRequest($uid, 'getHome', array($uid)); + return $this->handleRequest($uid, 'getHome', [$uid]); } /** @@ -254,7 +254,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, * @return string display name */ public function getDisplayName($uid) { - return $this->handleRequest($uid, 'getDisplayName', array($uid)); + return $this->handleRequest($uid, 'getDisplayName', [$uid]); } /** @@ -265,7 +265,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, * @return string display name */ public function setDisplayName($uid, $displayName) { - return $this->handleRequest($uid, 'setDisplayName', array($uid, $displayName)); + return $this->handleRequest($uid, 'setDisplayName', [$uid, $displayName]); } /** @@ -286,7 +286,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, */ public function getDisplayNames($search = '', $limit = null, $offset = null) { //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends - $users = array(); + $users = []; foreach($this->backends as $backend) { $backendUsers = $backend->getDisplayNames($search, $limit, $offset); if (is_array($backendUsers)) { @@ -304,7 +304,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, * Deletes a user */ public function deleteUser($uid) { - return $this->handleRequest($uid, 'deleteUser', array($uid)); + return $this->handleRequest($uid, 'deleteUser', [$uid]); } /** @@ -315,7 +315,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, * */ public function setPassword($uid, $password) { - return $this->handleRequest($uid, 'setPassword', array($uid, $password)); + return $this->handleRequest($uid, 'setPassword', [$uid, $password]); } /** @@ -346,7 +346,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, * @return Access instance of Access for LDAP interaction */ public function getLDAPAccess($uid) { - return $this->handleRequest($uid, 'getLDAPAccess', array($uid)); + return $this->handleRequest($uid, 'getLDAPAccess', [$uid]); } /** @@ -356,7 +356,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, * @return resource of the LDAP connection */ public function getNewLDAPConnection($uid) { - return $this->handleRequest($uid, 'getNewLDAPConnection', array($uid)); + return $this->handleRequest($uid, 'getNewLDAPConnection', [$uid]); } /** @@ -366,6 +366,6 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, * @return bool */ public function createUser($username, $password) { - return $this->handleRequest($username, 'createUser', array($username,$password)); + return $this->handleRequest($username, 'createUser', [$username,$password]); } } diff --git a/apps/user_ldap/lib/Wizard.php b/apps/user_ldap/lib/Wizard.php index 82f06010bcf..4e3f41d6fc9 100644 --- a/apps/user_ldap/lib/Wizard.php +++ b/apps/user_ldap/lib/Wizard.php @@ -48,7 +48,7 @@ class Wizard extends LDAPUtility { protected $cr; protected $configuration; protected $result; - protected $resultCache = array(); + protected $resultCache = []; const LRESULT_PROCESSED_OK = 2; const LRESULT_PROCESSED_INVALID = 3; @@ -135,7 +135,7 @@ class Wizard extends LDAPUtility { $filter = $this->configuration->ldapGroupFilter; if(empty($filter)) { - $output = self::$l->n('%s group found', '%s groups found', 0, array(0)); + $output = self::$l->n('%s group found', '%s groups found', 0, [0]); $this->result->addChange('ldap_group_count', $output); return $this->result; } @@ -200,22 +200,22 @@ class Wizard extends LDAPUtility { * @return int|bool */ public function countUsersWithAttribute($attr, $existsCheck = false) { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', 'ldapBase', 'ldapUserFilter', - ))) { + ])) { return false; } - $filter = $this->access->combineFilterWithAnd(array( + $filter = $this->access->combineFilterWithAnd([ $this->configuration->ldapUserFilter, $attr . '=*' - )); + ]); $limit = ($existsCheck === false) ? null : 1; - return $this->access->countUsers($filter, array('dn'), $limit); + return $this->access->countUsers($filter, ['dn'], $limit); } /** @@ -225,11 +225,11 @@ class Wizard extends LDAPUtility { * @throws \Exception */ public function detectUserDisplayNameAttribute() { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', 'ldapBase', 'ldapUserFilter', - ))) { + ])) { return false; } @@ -247,7 +247,7 @@ class Wizard extends LDAPUtility { } // first attribute that has at least one result wins - $displayNameAttrs = array('displayname', 'cn'); + $displayNameAttrs = ['displayname', 'cn']; foreach ($displayNameAttrs as $attr) { $count = (int)$this->countUsersWithAttribute($attr, true); @@ -267,11 +267,11 @@ class Wizard extends LDAPUtility { * @return WizardResult|bool */ public function detectEmailAttribute() { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', 'ldapBase', 'ldapUserFilter', - ))) { + ])) { return false; } @@ -286,7 +286,7 @@ class Wizard extends LDAPUtility { $writeLog = false; } - $emailAttributes = array('mail', 'mailPrimaryAddress'); + $emailAttributes = ['mail', 'mailPrimaryAddress']; $winner = ''; $maxUsers = 0; foreach($emailAttributes as $attr) { @@ -314,11 +314,11 @@ class Wizard extends LDAPUtility { * @throws \Exception */ public function determineAttributes() { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', 'ldapBase', 'ldapUserFilter', - ))) { + ])) { return false; } @@ -343,11 +343,11 @@ class Wizard extends LDAPUtility { * @throws \Exception */ private function getUserAttributes() { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', 'ldapBase', 'ldapUserFilter', - ))) { + ])) { return false; } $cr = $this->getConnection(); @@ -357,13 +357,13 @@ class Wizard extends LDAPUtility { $base = $this->configuration->ldapBase[0]; $filter = $this->configuration->ldapUserFilter; - $rr = $this->ldap->search($cr, $base, $filter, array(), 1, 1); + $rr = $this->ldap->search($cr, $base, $filter, [], 1, 1); if(!$this->ldap->isResource($rr)) { return false; } $er = $this->ldap->firstEntry($cr, $rr); $attributes = $this->ldap->getAttributes($cr, $er); - $pureAttributes = array(); + $pureAttributes = []; for($i = 0; $i < $attributes['count']; $i++) { $pureAttributes[] = $attributes[$i]; } @@ -399,10 +399,10 @@ class Wizard extends LDAPUtility { * @throws \Exception */ private function determineGroups($dbKey, $confKey, $testMemberOf = true) { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', 'ldapBase', - ))) { + ])) { return false; } $cr = $this->getConnection(); @@ -432,9 +432,9 @@ class Wizard extends LDAPUtility { * @throws \Exception */ public function fetchGroups($dbKey, $confKey) { - $obclasses = array('posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames', 'groupOfUniqueNames'); + $obclasses = ['posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames', 'groupOfUniqueNames']; - $filterParts = array(); + $filterParts = []; foreach($obclasses as $obclass) { $filterParts[] = 'objectclass='.$obclass; } @@ -442,16 +442,16 @@ class Wizard extends LDAPUtility { //- that looks like a group and //- has the group display name set $filter = $this->access->combineFilterWithOr($filterParts); - $filter = $this->access->combineFilterWithAnd(array($filter, 'cn=*')); + $filter = $this->access->combineFilterWithAnd([$filter, 'cn=*']); - $groupNames = array(); - $groupEntries = array(); + $groupNames = []; + $groupEntries = []; $limit = 400; $offset = 0; do { // we need to request dn additionally here, otherwise memberOf // detection will fail later - $result = $this->access->searchGroups($filter, array('cn', 'dn'), $limit, $offset); + $result = $this->access->searchGroups($filter, ['cn', 'dn'], $limit, $offset); foreach($result as $item) { if(!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) { // just in case - no issue known @@ -479,17 +479,17 @@ class Wizard extends LDAPUtility { } public function determineGroupMemberAssoc() { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', 'ldapGroupFilter', - ))) { + ])) { return false; } $attribute = $this->detectGroupMemberAssoc(); if($attribute === false) { return false; } - $this->configuration->setConfiguration(array('ldapGroupMemberAssocAttr' => $attribute)); + $this->configuration->setConfiguration(['ldapGroupMemberAssocAttr' => $attribute]); $this->result->addChange('ldap_group_member_assoc_attribute', $attribute); return $this->result; @@ -501,10 +501,10 @@ class Wizard extends LDAPUtility { * @throws \Exception */ public function determineGroupObjectClasses() { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', 'ldapBase', - ))) { + ])) { return false; } $cr = $this->getConnection(); @@ -512,7 +512,7 @@ class Wizard extends LDAPUtility { throw new \Exception('Could not connect to LDAP'); } - $obclasses = array('groupOfNames', 'groupOfUniqueNames', 'group', 'posixGroup', '*'); + $obclasses = ['groupOfNames', 'groupOfUniqueNames', 'group', 'posixGroup', '*']; $this->determineFeature($obclasses, 'objectclass', 'ldap_groupfilter_objectclass', @@ -528,10 +528,10 @@ class Wizard extends LDAPUtility { * @throws \Exception */ public function determineUserObjectClasses() { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', 'ldapBase', - ))) { + ])) { return false; } $cr = $this->getConnection(); @@ -539,8 +539,8 @@ class Wizard extends LDAPUtility { throw new \Exception('Could not connect to LDAP'); } - $obclasses = array('inetOrgPerson', 'person', 'organizationalPerson', - 'user', 'posixAccount', '*'); + $obclasses = ['inetOrgPerson', 'person', 'organizationalPerson', + 'user', 'posixAccount', '*']; $filter = $this->configuration->ldapUserFilter; //if filter is empty, it is probably the first time the wizard is called //then, apply suggestions. @@ -558,10 +558,10 @@ class Wizard extends LDAPUtility { * @throws \Exception */ public function getGroupFilter() { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', 'ldapBase', - ))) { + ])) { return false; } //make sure the use display name is set @@ -582,10 +582,10 @@ class Wizard extends LDAPUtility { * @throws \Exception */ public function getUserListFilter() { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', 'ldapBase', - ))) { + ])) { return false; } //make sure the use display name is set @@ -608,11 +608,11 @@ class Wizard extends LDAPUtility { * @throws \Exception */ public function getUserLoginFilter() { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', 'ldapBase', 'ldapUserFilter', - ))) { + ])) { return false; } @@ -631,11 +631,11 @@ class Wizard extends LDAPUtility { * @throws \Exception */ public function testLoginName($loginName) { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', 'ldapBase', 'ldapLoginFilter', - ))) { + ])) { return false; } @@ -665,8 +665,8 @@ class Wizard extends LDAPUtility { * @throws \Exception */ public function guessPortAndTLS() { - if(!$this->checkRequirements(array('ldapHost', - ))) { + if(!$this->checkRequirements(['ldapHost', + ])) { return false; } $this->checkHost(); @@ -698,10 +698,10 @@ class Wizard extends LDAPUtility { } if ($settingsFound === true) { - $config = array( + $config = [ 'ldapPort' => $p, 'ldapTLS' => (int)$t - ); + ]; $this->configuration->setConfiguration($config); \OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, ILogger::DEBUG); $this->result->addChange('ldap_port', $p); @@ -718,9 +718,9 @@ class Wizard extends LDAPUtility { * @return WizardResult|false WizardResult on success, false otherwise */ public function guessBaseDN() { - if(!$this->checkRequirements(array('ldapHost', + if(!$this->checkRequirements(['ldapHost', 'ldapPort', - ))) { + ])) { return false; } @@ -766,7 +766,7 @@ class Wizard extends LDAPUtility { */ private function applyFind($key, $value) { $this->result->addChange($key, $value); - $this->configuration->setConfiguration(array($key => $value)); + $this->configuration->setConfiguration([$key => $value]); } /** @@ -844,7 +844,7 @@ class Wizard extends LDAPUtility { //base is there, let's validate it. If we search for anything, we should //get a result set > 0 on a proper base - $rr = $this->ldap->search($cr, $base, 'objectClass=*', array('dn'), 0, 1); + $rr = $this->ldap->search($cr, $base, 'objectClass=*', ['dn'], 0, 1); if(!$this->ldap->isResource($rr)) { $errorNo = $this->ldap->errno($cr); $errorMsg = $this->ldap->error($cr); @@ -870,7 +870,7 @@ class Wizard extends LDAPUtility { if(!$cr) { throw new \Exception('Could not connect to LDAP'); } - $result = $this->access->countUsers('memberOf=*', array('memberOf'), 1); + $result = $this->access->countUsers('memberOf=*', ['memberOf'], 1); if(is_int($result) && $result > 0) { return true; } @@ -911,7 +911,7 @@ class Wizard extends LDAPUtility { } $base = $this->configuration->ldapBase[0]; foreach($cns as $cn) { - $rr = $this->ldap->search($cr, $base, 'cn=' . $cn, array('dn', 'primaryGroupToken')); + $rr = $this->ldap->search($cr, $base, 'cn=' . $cn, ['dn', 'primaryGroupToken']); if(!$this->ldap->isResource($rr)) { continue; } @@ -1132,8 +1132,8 @@ class Wizard extends LDAPUtility { * @return array|false an array with the values on success, false otherwise */ public function cumulativeSearchOnAttribute($filters, $attr, $dnReadLimit = 3, &$maxF = null) { - $dnRead = array(); - $foundItems = array(); + $dnRead = []; + $foundItems = []; $maxEntries = 0; if(!is_array($this->configuration->ldapBase) || !isset($this->configuration->ldapBase[0])) { @@ -1154,7 +1154,7 @@ class Wizard extends LDAPUtility { continue; } // 20k limit for performance and reason - $rr = $this->ldap->search($cr, $base, $filter, array($attr), 0, 20000); + $rr = $this->ldap->search($cr, $base, $filter, [$attr], 0, 20000); if(!$this->ldap->isResource($rr)) { continue; } @@ -1178,7 +1178,7 @@ class Wizard extends LDAPUtility { if($dn === false || in_array($dn, $dnRead)) { continue; } - $newItems = array(); + $newItems = []; $state = $this->getAttributeValuesFromEntry($attributes, $attr, $newItems); @@ -1317,14 +1317,14 @@ class Wizard extends LDAPUtility { * @return array */ private function getDefaultLdapPortSettings() { - static $settings = array( - array('port' => 7636, 'tls' => false), - array('port' => 636, 'tls' => false), - array('port' => 7389, 'tls' => true), - array('port' => 389, 'tls' => true), - array('port' => 7389, 'tls' => false), - array('port' => 389, 'tls' => false), - ); + static $settings = [ + ['port' => 7636, 'tls' => false], + ['port' => 636, 'tls' => false], + ['port' => 7389, 'tls' => true], + ['port' => 389, 'tls' => true], + ['port' => 7389, 'tls' => false], + ['port' => 389, 'tls' => false], + ]; return $settings; } @@ -1337,7 +1337,7 @@ class Wizard extends LDAPUtility { //7xxx ← UCS. need to be checked first, because both ports may be open $host = $this->configuration->ldapHost; $port = (int)$this->configuration->ldapPort; - $portSettings = array(); + $portSettings = []; //In case the port is already provided, we will check this first if($port > 0) { @@ -1345,9 +1345,9 @@ class Wizard extends LDAPUtility { if(!(is_array($hostInfo) && isset($hostInfo['scheme']) && stripos($hostInfo['scheme'], 'ldaps') !== false)) { - $portSettings[] = array('port' => $port, 'tls' => true); + $portSettings[] = ['port' => $port, 'tls' => true]; } - $portSettings[] =array('port' => $port, 'tls' => false); + $portSettings[] =['port' => $port, 'tls' => false]; } //default ports diff --git a/apps/user_ldap/lib/WizardResult.php b/apps/user_ldap/lib/WizardResult.php index 74bb1171d48..ae90cfe437a 100644 --- a/apps/user_ldap/lib/WizardResult.php +++ b/apps/user_ldap/lib/WizardResult.php @@ -29,8 +29,8 @@ namespace OCA\User_LDAP; class WizardResult { - protected $changes = array(); - protected $options = array(); + protected $changes = []; + protected $options = []; protected $markedChange = false; /** @@ -52,7 +52,7 @@ class WizardResult { */ public function addOptions($key, $values) { if(!is_array($values)) { - $values = array($values); + $values = [$values]; } $this->options[$key] = $values; } @@ -68,7 +68,7 @@ class WizardResult { * @return array */ public function getResultArray() { - $result = array(); + $result = []; $result['changes'] = $this->changes; if(count($this->options) > 0) { $result['options'] = $this->options; diff --git a/apps/user_ldap/templates/part.wizard-server.php b/apps/user_ldap/templates/part.wizard-server.php index 5b607f7be86..56194bafecd 100644 --- a/apps/user_ldap/templates/part.wizard-server.php +++ b/apps/user_ldap/templates/part.wizard-server.php @@ -6,7 +6,7 @@ $sel = ' selected'; foreach($_['serverConfigurationPrefixes'] as $prefix) { ?> - <option value="<?php p($prefix); ?>"<?php p($sel); $sel = ''; ?>><?php p($l->t('%s. Server:', array($i++)));?> <?php p(' '.$_['serverConfigurationHosts'][$prefix]); ?></option> + <option value="<?php p($prefix); ?>"<?php p($sel); $sel = ''; ?>><?php p($l->t('%s. Server:', [$i++]));?> <?php p(' '.$_['serverConfigurationHosts'][$prefix]); ?></option> <?php } ?> diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php index 012a6831eb4..0397a851557 100644 --- a/apps/user_ldap/tests/AccessTest.php +++ b/apps/user_ldap/tests/AccessTest.php @@ -116,7 +116,7 @@ class AccessTest extends TestCase { ->getMock(); $helper = new Helper(\OC::$server->getConfig()); - return array($lw, $connector, $um, $helper); + return [$lw, $connector, $um, $helper]; } public function testEscapeFilterPartValidChars() { @@ -147,9 +147,9 @@ class AccessTest extends TestCase { } public function convertSID2StrSuccessData() { - return array( - array( - array( + return [ + [ + [ "\x01", "\x04", "\x00\x00\x00\x00\x00\x05", @@ -157,20 +157,20 @@ class AccessTest extends TestCase { "\xa6\x81\xe5\x0e", "\x4d\x6c\x6c\x2b", "\xca\x32\x05\x5f", - ), + ], 'S-1-5-21-249921958-728525901-1594176202', - ), - array( - array( + ], + [ + [ "\x01", "\x02", "\xFF\xFF\xFF\xFF\xFF\xFF", "\xFF\xFF\xFF\xFF", "\xFF\xFF\xFF\xFF", - ), + ], 'S-1-281474976710655-4294967295-4294967295', - ), - ); + ], + ]; } public function testConvertSID2StrInputError() { @@ -187,7 +187,7 @@ class AccessTest extends TestCase { $this->ldap->expects($this->once()) ->method('explodeDN') ->with($inputDN, 0) - ->will($this->returnValue(explode(',', $inputDN))); + ->willReturn(explode(',', $inputDN)); $this->assertSame($domainDN, $this->access->getDomainDNFromDN($inputDN)); } @@ -199,7 +199,7 @@ class AccessTest extends TestCase { $this->ldap->expects($this->once()) ->method('explodeDN') ->with($inputDN, 0) - ->will($this->returnValue(false)); + ->willReturn(false); $this->assertSame($expected, $this->access->getDomainDNFromDN($inputDN)); } @@ -208,12 +208,12 @@ class AccessTest extends TestCase { return [[ [ 'input' => 'foo=bar,bar=foo,dc=foobar', - 'interResult' => array( + 'interResult' => [ 'count' => 3, 0 => 'foo=bar', 1 => 'bar=foo', 2 => 'dc=foobar' - ), + ], 'expectedResult' => true ], [ @@ -236,12 +236,12 @@ class AccessTest extends TestCase { $lw->expects($this->exactly(1)) ->method('explodeDN') - ->will($this->returnCallback(function ($dn) use ($case) { + ->willReturnCallback(function ($dn) use ($case) { if($dn === $case['input']) { return $case['interResult']; } return null; - })); + }); $this->assertSame($case['expectedResult'], $access->stringResemblesDN($case['input'])); } @@ -294,7 +294,7 @@ class AccessTest extends TestCase { // also returns for userUuidAttribute $this->access->connection->expects($this->any()) ->method('__get') - ->will($this->returnValue('displayName')); + ->willReturn('displayName'); $this->access->setUserMapper($mapperMock); @@ -319,7 +319,7 @@ class AccessTest extends TestCase { $this->userManager->expects($this->exactly(count($data) * 2)) ->method('get') - ->will($this->returnValue($userMock)); + ->willReturn($userMock); $this->access->batchApplyUserAttributes($data); } @@ -329,13 +329,13 @@ class AccessTest extends TestCase { $mapperMock = $this->createMock(UserMapping::class); $mapperMock->expects($this->any()) ->method('getNameByDN') - ->will($this->returnValue('a_username')); + ->willReturn('a_username'); $userMock = $this->createMock(User::class); $this->access->connection->expects($this->any()) ->method('__get') - ->will($this->returnValue('displayName')); + ->willReturn('displayName'); $this->access->setUserMapper($mapperMock); @@ -370,13 +370,13 @@ class AccessTest extends TestCase { $mapperMock = $this->createMock(UserMapping::class); $mapperMock->expects($this->any()) ->method('getNameByDN') - ->will($this->returnValue('a_username')); + ->willReturn('a_username'); $userMock = $this->createMock(User::class); $this->access->connection->expects($this->any()) ->method('__get') - ->will($this->returnValue('displayName')); + ->willReturn('displayName'); $this->access->setUserMapper($mapperMock); @@ -401,19 +401,19 @@ class AccessTest extends TestCase { $this->userManager->expects($this->exactly(count($data) * 2)) ->method('get') - ->will($this->returnValue($userMock)); + ->willReturn($userMock); $this->access->batchApplyUserAttributes($data); } public function dNAttributeProvider() { // corresponds to Access::resemblesDN() - return array( - 'dn' => array('dn'), - 'uniqueMember' => array('uniquemember'), - 'member' => array('member'), - 'memberOf' => array('memberof') - ); + return [ + 'dn' => ['dn'], + 'uniqueMember' => ['uniquemember'], + 'member' => ['member'], + 'memberOf' => ['memberof'] + ]; } /** @@ -429,12 +429,12 @@ class AccessTest extends TestCase { $lw->expects($this->any()) ->method('isResource') - ->will($this->returnValue(true)); + ->willReturn(true); $lw->expects($this->any()) ->method('getAttributes') - ->will($this->returnValue(array( - $attribute => array('count' => 1, $dnFromServer) - ))); + ->willReturn([ + $attribute => ['count' => 1, $dnFromServer] + ]); $access = new Access($con, $lw, $um, $helper, $config, $this->ncUserManager); $values = $access->readAttribute('uid=whoever,dc=example,dc=org', $attribute); diff --git a/apps/user_ldap/tests/ConfigurationTest.php b/apps/user_ldap/tests/ConfigurationTest.php index 1c757aa5a47..c44f8a0177a 100644 --- a/apps/user_ldap/tests/ConfigurationTest.php +++ b/apps/user_ldap/tests/ConfigurationTest.php @@ -36,71 +36,71 @@ class ConfigurationTest extends \Test\TestCase { } public function configurationDataProvider() { - $inputWithDN = array( + $inputWithDN = [ 'cn=someUsers,dc=example,dc=org', ' ', ' cn=moreUsers,dc=example,dc=org ' - ); - $expectWithDN = array( + ]; + $expectWithDN = [ 'cn=someUsers,dc=example,dc=org', 'cn=moreUsers,dc=example,dc=org' - ); + ]; - $inputNames = array( + $inputNames = [ ' uid ', 'cn ', ' ', '', ' whats my name', ' ' - ); - $expectedNames = array('uid', 'cn', 'whats my name'); + ]; + $expectedNames = ['uid', 'cn', 'whats my name']; $inputString = ' alea iacta est '; $expectedString = 'alea iacta est'; - $inputHomeFolder = array( + $inputHomeFolder = [ ' homeDirectory ', ' attr:homeDirectory ', ' ' - ); + ]; - $expectedHomeFolder = array( + $expectedHomeFolder = [ 'attr:homeDirectory', 'attr:homeDirectory', '' - ); + ]; $password = ' such a passw0rd '; - return array( - 'set general base' => array('ldapBase', $inputWithDN, $expectWithDN), - 'set user base' => array('ldapBaseUsers', $inputWithDN, $expectWithDN), - 'set group base' => array('ldapBaseGroups', $inputWithDN, $expectWithDN), + return [ + 'set general base' => ['ldapBase', $inputWithDN, $expectWithDN], + 'set user base' => ['ldapBaseUsers', $inputWithDN, $expectWithDN], + 'set group base' => ['ldapBaseGroups', $inputWithDN, $expectWithDN], - 'set search attributes users' => array('ldapAttributesForUserSearch', $inputNames, $expectedNames), - 'set search attributes groups' => array('ldapAttributesForGroupSearch', $inputNames, $expectedNames), + 'set search attributes users' => ['ldapAttributesForUserSearch', $inputNames, $expectedNames], + 'set search attributes groups' => ['ldapAttributesForGroupSearch', $inputNames, $expectedNames], - 'set user filter objectclasses' => array('ldapUserFilterObjectclass', $inputNames, $expectedNames), - 'set user filter groups' => array('ldapUserFilterGroups', $inputNames, $expectedNames), - 'set group filter objectclasses' => array('ldapGroupFilterObjectclass', $inputNames, $expectedNames), - 'set group filter groups' => array('ldapGroupFilterGroups', $inputNames, $expectedNames), - 'set login filter attributes' => array('ldapLoginFilterAttributes', $inputNames, $expectedNames), + 'set user filter objectclasses' => ['ldapUserFilterObjectclass', $inputNames, $expectedNames], + 'set user filter groups' => ['ldapUserFilterGroups', $inputNames, $expectedNames], + 'set group filter objectclasses' => ['ldapGroupFilterObjectclass', $inputNames, $expectedNames], + 'set group filter groups' => ['ldapGroupFilterGroups', $inputNames, $expectedNames], + 'set login filter attributes' => ['ldapLoginFilterAttributes', $inputNames, $expectedNames], - 'set agent password' => array('ldapAgentPassword', $password, $password), + 'set agent password' => ['ldapAgentPassword', $password, $password], - 'set home folder, variant 1' => array('homeFolderNamingRule', $inputHomeFolder[0], $expectedHomeFolder[0]), - 'set home folder, variant 2' => array('homeFolderNamingRule', $inputHomeFolder[1], $expectedHomeFolder[1]), - 'set home folder, empty' => array('homeFolderNamingRule', $inputHomeFolder[2], $expectedHomeFolder[2]), + 'set home folder, variant 1' => ['homeFolderNamingRule', $inputHomeFolder[0], $expectedHomeFolder[0]], + 'set home folder, variant 2' => ['homeFolderNamingRule', $inputHomeFolder[1], $expectedHomeFolder[1]], + 'set home folder, empty' => ['homeFolderNamingRule', $inputHomeFolder[2], $expectedHomeFolder[2]], // default behaviour, one case is enough, special needs must be tested // individually - 'set string value' => array('ldapHost', $inputString, $expectedString), + 'set string value' => ['ldapHost', $inputString, $expectedString], 'set avatar rule, default' => ['ldapUserAvatarRule', 'default', 'default'], 'set avatar rule, none' => ['ldapUserAvatarRule', 'none', 'none'], 'set avatar rule, data attribute' => ['ldapUserAvatarRule', 'data:jpegPhoto', 'data:jpegPhoto'], 'set external storage home attribute' => ['ldapExtStorageHomeAttribute', 'homePath', 'homePath'], - ); + ]; } /** diff --git a/apps/user_ldap/tests/ConnectionTest.php b/apps/user_ldap/tests/ConnectionTest.php index 26921592405..778a666317b 100644 --- a/apps/user_ldap/tests/ConnectionTest.php +++ b/apps/user_ldap/tests/ConnectionTest.php @@ -57,7 +57,7 @@ class ConnectionTest extends \Test\TestCase { $this->ldap->expects($this->any()) ->method('areLDAPFunctionsAvailable') - ->will($this->returnValue(true)); + ->willReturn(true); } public function testOriginalAgentUnchangedOnClone() { @@ -67,17 +67,17 @@ class ConnectionTest extends \Test\TestCase { $lw = $this->createMock(ILDAPWrapper::class); $connection = new Connection($lw, '', null); - $agent = array( + $agent = [ 'ldapAgentName' => 'agent', 'ldapAgentPassword' => '123456', - ); + ]; $connection->setConfiguration($agent); $testConnection = clone $connection; - $user = array( + $user = [ 'ldapAgentName' => 'user', 'ldapAgentPassword' => 'password', - ); + ]; $testConnection->setConfiguration($user); $agentName = $connection->ldapAgentName; @@ -105,19 +105,19 @@ class ConnectionTest extends \Test\TestCase { $this->ldap->expects($this->any()) ->method('isResource') - ->will($this->returnValue(true)); + ->willReturn(true); $this->ldap->expects($this->any()) ->method('setOption') - ->will($this->returnValue(true)); + ->willReturn(true); $this->ldap->expects($this->exactly(3)) ->method('connect') - ->will($this->returnValue('ldapResource')); + ->willReturn('ldapResource'); $this->ldap->expects($this->any()) ->method('errno') - ->will($this->returnValue(0)); + ->willReturn(0); // Not called often enough? Then, the fallback to the backup server is broken. $this->connection->expects($this->exactly(4)) @@ -132,13 +132,13 @@ class ConnectionTest extends \Test\TestCase { $isThrown = false; $this->ldap->expects($this->exactly(3)) ->method('bind') - ->will($this->returnCallback(function () use (&$isThrown) { + ->willReturnCallback(function () use (&$isThrown) { if(!$isThrown) { $isThrown = true; throw new \OC\ServerNotAvailableException(); } return true; - })); + }); $this->connection->init(); $this->connection->resetConnectionResource(); @@ -164,19 +164,19 @@ class ConnectionTest extends \Test\TestCase { $this->ldap->expects($this->any()) ->method('isResource') - ->will($this->returnValue(true)); + ->willReturn(true); $this->ldap->expects($this->any()) ->method('setOption') - ->will($this->returnValue(true)); + ->willReturn(true); $this->ldap->expects($this->once()) ->method('connect') - ->will($this->returnValue('ldapResource')); + ->willReturn('ldapResource'); $this->ldap->expects($this->any()) ->method('errno') - ->will($this->returnValue(49)); + ->willReturn(49); $this->connection->expects($this->any()) ->method('getFromCache') @@ -212,24 +212,24 @@ class ConnectionTest extends \Test\TestCase { $this->ldap->expects($this->any()) ->method('isResource') - ->will($this->returnValue(true)); + ->willReturn(true); $this->ldap->expects($this->any()) ->method('setOption') - ->will($this->returnValue(true)); + ->willReturn(true); $this->ldap->expects($this->any()) ->method('connect') - ->will($this->returnValue('ldapResource')); + ->willReturn('ldapResource'); $this->ldap->expects($this->once()) ->method('bind') - ->will($this->returnValue(false)); + ->willReturn(false); // LDAP_INVALID_CREDENTIALS $this->ldap->expects($this->any()) ->method('errno') - ->will($this->returnValue(0x31)); + ->willReturn(0x31); try { $this->assertFalse($this->connection->bind(), 'Connection::bind() should not return true with invalid credentials.'); @@ -259,27 +259,27 @@ class ConnectionTest extends \Test\TestCase { $this->ldap->expects($this->any()) ->method('isResource') - ->will($this->returnValue(true)); + ->willReturn(true); $this->ldap->expects($this->any()) ->method('connect') - ->will($this->returnValue('ldapResource')); + ->willReturn('ldapResource'); $this->ldap->expects($this->any()) ->method('setOption') - ->will($this->returnValue(true)); + ->willReturn(true); $this->ldap->expects($this->any()) ->method('bind') - ->will($this->returnValue(true)); + ->willReturn(true); $this->ldap->expects($this->any()) ->method('errno') - ->will($this->returnValue(0)); + ->willReturn(0); $this->ldap->expects($this->any()) ->method('startTls') - ->will($this->returnValue(false)); + ->willReturn(false); $this->expectException(\OC\ServerNotAvailableException::class); $this->expectExceptionMessage('Start TLS failed, when connecting to LDAP host ' . $host . '.'); diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php index 7ea4cb463d9..d5a6f3b712c 100644 --- a/apps/user_ldap/tests/Group_LDAPTest.php +++ b/apps/user_ldap/tests/Group_LDAPTest.php @@ -70,7 +70,7 @@ class Group_LDAPTest extends TestCase { $access->expects($this->any()) ->method('getConnection') - ->will($this->returnValue($connector)); + ->willReturn($connector); return $access; } @@ -87,12 +87,12 @@ class Group_LDAPTest extends TestCase { $access->connection->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'ldapDynamicGroupMemberURL') { return ''; } return 1; - })); + }); } public function testCountEmptySearchString() { @@ -104,7 +104,7 @@ class Group_LDAPTest extends TestCase { $access->expects($this->any()) ->method('groupname2dn') - ->will($this->returnValue($groupDN)); + ->willReturn($groupDN); $access->expects($this->any()) ->method('readAttribute') @@ -123,7 +123,7 @@ class Group_LDAPTest extends TestCase { // for primary groups $access->expects($this->once()) ->method('countUsers') - ->will($this->returnValue(2)); + ->willReturn(2); $groupBackend = new GroupLDAP($access, $pluginManager); $users = $groupBackend->countUsersInGroup('group'); @@ -139,15 +139,15 @@ class Group_LDAPTest extends TestCase { $access->expects($this->any()) ->method('groupname2dn') - ->will($this->returnValue('cn=group,dc=foo,dc=bar')); + ->willReturn('cn=group,dc=foo,dc=bar'); $access->expects($this->any()) ->method('fetchListOfUsers') - ->will($this->returnValue([])); + ->willReturn([]); $access->expects($this->any()) ->method('readAttribute') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { //the search operation will call readAttribute, thus we need //to anaylze the "dn". All other times we just need to return //something that is neither null or false, but once an array @@ -157,13 +157,13 @@ class Group_LDAPTest extends TestCase { return strpos($name, '3'); } return ['u11', 'u22', 'u33', 'u34']; - })); + }); $access->expects($this->any()) ->method('dn2username') - ->will($this->returnCallback(function() { + ->willReturnCallback(function() { return 'foobar' . \OC::$server->getSecureRandom()->generate(7); - })); + }); $groupBackend = new GroupLDAP($access,$pluginManager); $users = $groupBackend->countUsersInGroup('group', '3'); @@ -205,12 +205,12 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('searchGroups') - ->will($this->returnValue([['dn' => ['cn=foo,dc=barfoo,dc=bar']]])); + ->willReturn([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]); $access->expects($this->once()) ->method('dn2groupname') ->with('cn=foo,dc=barfoo,dc=bar') - ->will($this->returnValue('MyGroup')); + ->willReturn('MyGroup'); $groupBackend = new GroupLDAP($access, $pluginManager); @@ -229,7 +229,7 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('searchGroups') - ->will($this->returnValue(array())); + ->willReturn([]); $access->expects($this->never()) ->method('dn2groupname'); @@ -251,11 +251,11 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('searchGroups') - ->will($this->returnValue([['dn' => ['cn=foo,dc=barfoo,dc=bar']]])); + ->willReturn([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]); $access->expects($this->once()) ->method('dn2groupname') - ->will($this->returnValue(false)); + ->willReturn(false); $groupBackend = new GroupLDAP($access, $pluginManager); @@ -276,7 +276,7 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('readAttribute') ->with($dn, $attr) - ->will($this->returnValue(array('3117'))); + ->willReturn(['3117']); $groupBackend = new GroupLDAP($access, $pluginManager); @@ -297,7 +297,7 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('readAttribute') ->with($dn, $attr) - ->will($this->returnValue(false)); + ->willReturn(false); $groupBackend = new GroupLDAP($access, $pluginManager); @@ -317,16 +317,16 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('getSID') ->with($userDN) - ->will($this->returnValue('S-1-5-21-249921958-728525901-1594176202')); + ->willReturn('S-1-5-21-249921958-728525901-1594176202'); $access->expects($this->once()) ->method('searchGroups') - ->will($this->returnValue([['dn' => ['cn=foo,dc=barfoo,dc=bar']]])); + ->willReturn([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]); $access->expects($this->once()) ->method('dn2groupname') ->with('cn=foo,dc=barfoo,dc=bar') - ->will($this->returnValue('MyGroup')); + ->willReturn('MyGroup'); $groupBackend = new GroupLDAP($access, $pluginManager); @@ -346,7 +346,7 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('getSID') ->with($userDN) - ->will($this->returnValue(false)); + ->willReturn(false); $access->expects($this->never()) ->method('searchGroups'); @@ -372,11 +372,11 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('getSID') ->with($userDN) - ->will($this->returnValue('S-1-5-21-249921958-728525901-1594176202')); + ->willReturn('S-1-5-21-249921958-728525901-1594176202'); $access->expects($this->once()) ->method('searchGroups') - ->will($this->returnValue(array())); + ->willReturn([]); $access->expects($this->never()) ->method('dn2groupname'); @@ -399,15 +399,15 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('getSID') ->with($userDN) - ->will($this->returnValue('S-1-5-21-249921958-728525901-1594176202')); + ->willReturn('S-1-5-21-249921958-728525901-1594176202'); $access->expects($this->once()) ->method('searchGroups') - ->will($this->returnValue([['dn' => ['cn=foo,dc=barfoo,dc=bar']]])); + ->willReturn([['dn' => ['cn=foo,dc=barfoo,dc=bar']]]); $access->expects($this->once()) ->method('dn2groupname') - ->will($this->returnValue(false)); + ->willReturn(false); $groupBackend = new GroupLDAP($access, $pluginManager); @@ -430,7 +430,7 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('readAttribute') ->with($dn, $attr) - ->will($this->returnValue(array('3117'))); + ->willReturn(['3117']); $groupBackend = new GroupLDAP($access, $pluginManager); @@ -453,7 +453,7 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('readAttribute') ->with($dn, $attr) - ->will($this->returnValue(false)); + ->willReturn(false); $groupBackend = new GroupLDAP($access, $pluginManager); @@ -479,7 +479,7 @@ class Group_LDAPTest extends TestCase { $access->connection->expects($this->once()) ->method('getFromCache') ->with($cacheKey) - ->will($this->returnValue(true)); + ->willReturn(true); $access->expects($this->never()) ->method('username2dn'); @@ -496,7 +496,7 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('nextcloudGroupNames') - ->will($this->returnValue(array('group1', 'group2'))); + ->willReturn(['group1', 'group2']); $groupBackend = new GroupLDAP($access, $pluginManager); $groups = $groupBackend->getGroups('', 2, 2); @@ -516,20 +516,20 @@ class Group_LDAPTest extends TestCase { $access->connection->expects($this->any()) ->method('getFromCache') - ->will($this->returnValue(null)); + ->willReturn(null); $access->expects($this->any()) ->method('readAttribute') - ->will($this->returnCallback(function($dn, $attr) { + ->willReturnCallback(function($dn, $attr) { if($attr === 'primaryGroupToken') { - return array(1337); + return [1337]; } else if($attr === 'gidNumber') { return [4211]; } - return array(); - })); + return []; + }); $access->expects($this->any()) ->method('groupname2dn') - ->will($this->returnValue('cn=foobar,dc=foo,dc=bar')); + ->willReturn('cn=foobar,dc=foo,dc=bar'); $access->expects($this->exactly(2)) ->method('nextcloudUserNames') ->willReturnOnConsecutiveCalls(['lisa', 'bart', 'kira', 'brad'], ['walle', 'dino', 'xenia']); @@ -553,21 +553,21 @@ class Group_LDAPTest extends TestCase { $access->connection->expects($this->any()) ->method('getFromCache') - ->will($this->returnValue(null)); + ->willReturn(null); $access->expects($this->any()) ->method('readAttribute') - ->will($this->returnCallback(function($dn, $attr) { + ->willReturnCallback(function($dn, $attr) { if($attr === 'primaryGroupToken') { - return array(1337); + return [1337]; } - return array(); - })); + return []; + }); $access->expects($this->any()) ->method('groupname2dn') - ->will($this->returnValue('cn=foobar,dc=foo,dc=bar')); + ->willReturn('cn=foobar,dc=foo,dc=bar'); $access->expects($this->once()) ->method('nextcloudUserNames') - ->will($this->returnValue(array('lisa', 'bart', 'kira', 'brad'))); + ->willReturn(['lisa', 'bart', 'kira', 'brad']); $access->userManager = $this->createMock(Manager::class); $groupBackend = new GroupLDAP($access, $pluginManager); @@ -588,24 +588,24 @@ class Group_LDAPTest extends TestCase { $access->connection->expects($this->any()) ->method('getFromCache') - ->will($this->returnValue(null)); + ->willReturn(null); $access->expects($this->any()) ->method('readAttribute') - ->will($this->returnCallback(function($dn, $attr) { + ->willReturnCallback(function($dn, $attr) { if($attr === 'primaryGroupToken') { - return array(1337); + return [1337]; } - return array(); - })); + return []; + }); $access->expects($this->any()) ->method('groupname2dn') - ->will($this->returnValue('cn=foobar,dc=foo,dc=bar')); + ->willReturn('cn=foobar,dc=foo,dc=bar'); $access->expects($this->once()) ->method('countUsers') - ->will($this->returnValue(4)); + ->willReturn(4); $groupBackend = new GroupLDAP($access, $pluginManager); $users = $groupBackend->countUsersInGroup('foobar'); @@ -626,7 +626,7 @@ class Group_LDAPTest extends TestCase { $access->expects($this->any()) ->method('username2dn') - ->will($this->returnValue($dn)); + ->willReturn($dn); $access->expects($this->exactly(3)) ->method('readAttribute') @@ -634,11 +634,11 @@ class Group_LDAPTest extends TestCase { $access->expects($this->exactly(2)) ->method('dn2groupname') - ->will($this->returnArgument(0)); + ->willReturnArgument(0); $access->expects($this->exactly(1)) ->method('groupsMatchFilter') - ->will($this->returnArgument(0)); + ->willReturnArgument(0); $groupBackend = new GroupLDAP($access, $pluginManager); $groups = $groupBackend->getUserGroups('userX'); @@ -653,14 +653,14 @@ class Group_LDAPTest extends TestCase { $access->connection = $this->createMock(Connection::class); $access->connection->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'useMemberOfToDetectMembership') { return 0; } else if($name === 'ldapDynamicGroupMemberURL') { return ''; } return 1; - })); + }); $dn = 'cn=userX,dc=foobar'; @@ -669,13 +669,13 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('username2dn') - ->will($this->returnValue($dn)); + ->willReturn($dn); $access->expects($this->never()) ->method('readAttribute') ->with($dn, 'memberOf'); $access->expects($this->once()) ->method('nextcloudGroupNames') - ->will($this->returnValue([])); + ->willReturn([]); $access->expects($this->any()) ->method('groupsMatchFilter') ->willReturnArgument(0); @@ -691,7 +691,7 @@ class Group_LDAPTest extends TestCase { $access->connection = $this->createMock(Connection::class); $access->connection->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { switch($name) { case 'useMemberOfToDetectMembership': return 0; @@ -703,7 +703,7 @@ class Group_LDAPTest extends TestCase { return 'member'; } return 1; - })); + }); $dn = 'cn=userX,dc=foobar'; @@ -712,7 +712,7 @@ class Group_LDAPTest extends TestCase { $access->expects($this->exactly(2)) ->method('username2dn') - ->will($this->returnValue($dn)); + ->willReturn($dn); $access->expects($this->never()) ->method('readAttribute') @@ -730,10 +730,10 @@ class Group_LDAPTest extends TestCase { $access->expects($this->once()) ->method('nextcloudGroupNames') ->with([$group1, $group2]) - ->will($this->returnValue(['group1', 'group2'])); + ->willReturn(['group1', 'group2']); $access->expects($this->once()) ->method('fetchListOfGroups') - ->will($this->returnValue([$group1, $group2])); + ->willReturn([$group1, $group2]); $access->expects($this->any()) ->method('groupsMatchFilter') ->willReturnArgument(0); @@ -816,7 +816,7 @@ class Group_LDAPTest extends TestCase { $access = $this->getAccessMock(); $access->expects($this->any()) ->method('getGroupMapper') - ->will($this->returnValue($mapper)); + ->willReturn($mapper); $access->connection = $this->createMock(Connection::class); diff --git a/apps/user_ldap/tests/HelperTest.php b/apps/user_ldap/tests/HelperTest.php index af4d24739be..a9b889dbc55 100644 --- a/apps/user_ldap/tests/HelperTest.php +++ b/apps/user_ldap/tests/HelperTest.php @@ -67,7 +67,7 @@ class HelperTest extends \Test\TestCase { ]); $this->config->method('getAppValue') - ->will($this->returnCallback(function($app, $key, $default) { + ->willReturnCallback(function($app, $key, $default) { if ($app !== 'user_ldap') { $this->fail('wrong app'); } @@ -75,7 +75,7 @@ class HelperTest extends \Test\TestCase { return '1'; } return $default; - })); + }); $result = $this->helper->getServerConfigurationPrefixes(true); @@ -93,7 +93,7 @@ class HelperTest extends \Test\TestCase { ]); $this->config->method('getAppValue') - ->will($this->returnCallback(function($app, $key, $default) { + ->willReturnCallback(function($app, $key, $default) { if ($app !== 'user_ldap') { $this->fail('wrong app'); } @@ -104,7 +104,7 @@ class HelperTest extends \Test\TestCase { return 'foo.bar.com'; } return $default; - })); + }); $result = $this->helper->getServerConfigurationHosts(); diff --git a/apps/user_ldap/tests/Integration/ExceptionOnLostConnection.php b/apps/user_ldap/tests/Integration/ExceptionOnLostConnection.php index e652b7a644c..6912fc2d9a7 100644 --- a/apps/user_ldap/tests/Integration/ExceptionOnLostConnection.php +++ b/apps/user_ldap/tests/Integration/ExceptionOnLostConnection.php @@ -129,12 +129,12 @@ class ExceptionOnLostConnection { //host contains port, 2nd parameter will be ignored $cr = $this->ldap->connect($this->ldapHost, 0); $this->ldap->bind($cr, $this->ldapBindDN, $this->ldapBindPwd); - $this->ldap->search($cr, $this->ldapBase, 'objectClass=*', array('dn'), true, 5); + $this->ldap->search($cr, $this->ldapBase, 'objectClass=*', ['dn'], true, 5); // disable LDAP, will cause lost connection $this->setProxyState(false); try { - $this->ldap->search($cr, $this->ldapBase, 'objectClass=*', array('dn'), true, 5); + $this->ldap->search($cr, $this->ldapBase, 'objectClass=*', ['dn'], true, 5); } catch (ServerNotAvailableException $e) { print("Test PASSED" . PHP_EOL); exit(0); @@ -173,9 +173,9 @@ class ExceptionOnLostConnection { $ch = $this->getCurl(); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( + curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', - 'Content-Length: ' . strlen($postData)) + 'Content-Length: ' . strlen($postData)] ); $recvd = curl_exec($ch); $this->checkCurlResult($ch, $recvd); diff --git a/apps/user_ldap/tests/Jobs/CleanUpTest.php b/apps/user_ldap/tests/Jobs/CleanUpTest.php index 2d8ab254257..f08a5440c4f 100644 --- a/apps/user_ldap/tests/Jobs/CleanUpTest.php +++ b/apps/user_ldap/tests/Jobs/CleanUpTest.php @@ -31,7 +31,7 @@ use OCP\IDBConnection; class CleanUpTest extends \Test\TestCase { public function getMocks() { - $mocks = array(); + $mocks = []; $mocks['userBackend'] = $this->getMockBuilder('\OCA\User_LDAP\User_Proxy') ->disableOriginalConstructor() @@ -54,7 +54,7 @@ class CleanUpTest extends \Test\TestCase { $args = $this->getMocks(); $args['helper']->expects($this->once()) ->method('haveDisabledConfigurations') - ->will($this->returnValue(true) ); + ->willReturn(true ); $args['ocConfig']->expects($this->never()) ->method('getSystemValue'); @@ -93,11 +93,11 @@ class CleanUpTest extends \Test\TestCase { $args = $this->getMocks(); $args['helper']->expects($this->once()) ->method('haveDisabledConfigurations') - ->will($this->returnValue(false)); + ->willReturn(false); $args['ocConfig']->expects($this->once()) ->method('getSystemValue') - ->will($this->returnValue(false)); + ->willReturn(false); $bgJob = new \OCA\User_LDAP\Jobs\CleanUp(); $bgJob->setArguments($args); @@ -113,11 +113,11 @@ class CleanUpTest extends \Test\TestCase { $args = $this->getMocks(); $args['helper']->expects($this->once()) ->method('haveDisabledConfigurations') - ->will($this->returnValue(false)); + ->willReturn(false); $args['ocConfig']->expects($this->once()) ->method('getSystemValue') - ->will($this->returnValue(true)); + ->willReturn(true); $bgJob = new \OCA\User_LDAP\Jobs\CleanUp(); $bgJob->setArguments($args); diff --git a/apps/user_ldap/tests/LDAPProviderTest.php b/apps/user_ldap/tests/LDAPProviderTest.php index b6e63f4a7ae..71e08654893 100644 --- a/apps/user_ldap/tests/LDAPProviderTest.php +++ b/apps/user_ldap/tests/LDAPProviderTest.php @@ -601,7 +601,7 @@ class LDAPProviderTest extends \Test\TestCase { ->willReturn(true); $userBackend->expects($this->at(3)) ->method('getConfiguration') - ->willReturn(array('ldap_display_name'=>'displayName')); + ->willReturn(['ldap_display_name'=>'displayName']); $userBackend->expects($this->any()) ->method($this->anything()) ->willReturnSelf(); @@ -639,7 +639,7 @@ class LDAPProviderTest extends \Test\TestCase { ->willReturn(true); $userBackend->expects($this->at(3)) ->method('getConfiguration') - ->willReturn(array('ldap_email_attr'=>'mail')); + ->willReturn(['ldap_email_attr'=>'mail']); $userBackend->expects($this->any()) ->method($this->anything()) ->willReturnSelf(); @@ -687,7 +687,7 @@ class LDAPProviderTest extends \Test\TestCase { ->willReturn(true); $groupBackend->expects($this->any()) ->method('getConfiguration') - ->willReturn(array('ldap_group_member_assoc_attribute'=>'assoc_type')); + ->willReturn(['ldap_group_member_assoc_attribute'=>'assoc_type']); $groupBackend->expects($this->any()) ->method($this->anything()) ->willReturnSelf(); diff --git a/apps/user_ldap/tests/LDAPTest.php b/apps/user_ldap/tests/LDAPTest.php index 9821336df75..c06017f4be4 100644 --- a/apps/user_ldap/tests/LDAPTest.php +++ b/apps/user_ldap/tests/LDAPTest.php @@ -86,7 +86,7 @@ class LDAPTest extends TestCase { $this->ldap ->expects($this->once()) ->method('invokeLDAPMethod') - ->with('mod_replace', $link, $userDN, array('userPassword' => $password)) + ->with('mod_replace', $link, $userDN, ['userPassword' => $password]) ->willReturn(true); $this->assertTrue($this->ldap->modReplace($link, $userDN, $password)); diff --git a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php b/apps/user_ldap/tests/Mapping/AbstractMappingTest.php index 57177819c2d..e4aadb3ea97 100644 --- a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php +++ b/apps/user_ldap/tests/Mapping/AbstractMappingTest.php @@ -49,23 +49,23 @@ abstract class AbstractMappingTest extends \Test\TestCase { * @return array */ protected function getTestData() { - $data = array( - array( + $data = [ + [ 'dn' => 'uid=foobar,dc=example,dc=org', 'name' => 'Foobar', 'uuid' => '1111-AAAA-1234-CDEF', - ), - array( + ], + [ 'dn' => 'uid=barfoo,dc=example,dc=org', 'name' => 'Barfoo', 'uuid' => '2222-BBBB-1234-CDEF', - ), - array( + ], + [ 'dn' => 'uid=barabara,dc=example,dc=org', 'name' => 'BaraBara', 'uuid' => '3333-CCCC-1234-CDEF', - ) - ); + ] + ]; return $data; } @@ -97,7 +97,7 @@ abstract class AbstractMappingTest extends \Test\TestCase { $mapper->clear(); $this->mapEntries($mapper, $data); - return array($mapper, $data); + return [$mapper, $data]; } /** @@ -109,7 +109,7 @@ abstract class AbstractMappingTest extends \Test\TestCase { // test that mapping will not happen when it shall not $tooLongDN = 'uid=joann,ou=Secret Small Specialized Department,ou=Some Tremendously Important Department,ou=Another Very Important Department,ou=Pretty Meaningful Derpartment,ou=Quite Broad And General Department,ou=The Topmost Department,dc=hugelysuccessfulcompany,dc=com'; - $paramKeys = array('', 'dn', 'name', 'uuid', $tooLongDN); + $paramKeys = ['', 'dn', 'name', 'uuid', $tooLongDN]; foreach($paramKeys as $key) { $failEntry = $data[0]; if(!empty($key)) { diff --git a/apps/user_ldap/tests/User/ManagerTest.php b/apps/user_ldap/tests/User/ManagerTest.php index 784719c3b90..ad73d096efd 100644 --- a/apps/user_ldap/tests/User/ManagerTest.php +++ b/apps/user_ldap/tests/User/ManagerTest.php @@ -104,7 +104,7 @@ class ManagerTest extends \Test\TestCase { $this->access->expects($this->any()) ->method('getConnection') - ->will($this->returnValue($this->connection)); + ->willReturn($this->connection); /** @noinspection PhpUnhandledExceptionInspection */ $this->manager = new Manager( @@ -138,11 +138,11 @@ class ManagerTest extends \Test\TestCase { $this->access->expects($this->once()) ->method('stringResemblesDN') ->with($this->equalTo($inputDN)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->access->expects($this->once()) ->method('dn2username') ->with($this->equalTo($inputDN)) - ->will($this->returnValue($uid)); + ->willReturn($uid); $this->access->expects($this->never()) ->method('username2dn'); @@ -163,15 +163,15 @@ class ManagerTest extends \Test\TestCase { $this->access->expects($this->once()) ->method('stringResemblesDN') ->with($this->equalTo($inputDN)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->access->expects($this->once()) ->method('dn2username') ->with($this->equalTo($inputDN)) - ->will($this->returnValue(false)); + ->willReturn(false); $this->access->expects($this->once()) ->method('username2dn') ->with($this->equalTo($inputDN)) - ->will($this->returnValue(false)); + ->willReturn(false); /** @noinspection PhpUnhandledExceptionInspection */ $user = $this->manager->get($inputDN); @@ -188,11 +188,11 @@ class ManagerTest extends \Test\TestCase { $this->access->expects($this->once()) ->method('username2dn') ->with($this->equalTo($uid)) - ->will($this->returnValue($dn)); + ->willReturn($dn); $this->access->expects($this->once()) ->method('stringResemblesDN') ->with($this->equalTo($uid)) - ->will($this->returnValue(false)); + ->willReturn(false); /** @noinspection PhpUnhandledExceptionInspection */ $this->manager->get($uid); @@ -213,7 +213,7 @@ class ManagerTest extends \Test\TestCase { $this->access->expects($this->exactly(1)) ->method('username2dn') ->with($this->equalTo($uid)) - ->will($this->returnValue(false)); + ->willReturn(false); /** @noinspection PhpUnhandledExceptionInspection */ $user = $this->manager->get($uid); diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php index 36a312172c1..54a35f032b4 100644 --- a/apps/user_ldap/tests/User/UserTest.php +++ b/apps/user_ldap/tests/User/UserTest.php @@ -118,13 +118,13 @@ class UserTest extends \Test\TestCase { $this->connection->expects($this->once()) ->method('__get') ->with($this->equalTo('ldapEmailAttribute')) - ->will($this->returnValue('email')); + ->willReturn('email'); $this->access->expects($this->once()) ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('email')) - ->will($this->returnValue(['alice@foo.bar'])); + ->willReturn(['alice@foo.bar']); $coreUser = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() @@ -144,13 +144,13 @@ class UserTest extends \Test\TestCase { $this->connection->expects($this->once()) ->method('__get') ->with($this->equalTo('ldapEmailAttribute')) - ->will($this->returnValue('email')); + ->willReturn('email'); $this->access->expects($this->once()) ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('email')) - ->will($this->returnValue(false)); + ->willReturn(false); $this->config->expects($this->never()) ->method('setUserValue'); @@ -162,7 +162,7 @@ class UserTest extends \Test\TestCase { $this->connection->expects($this->once()) ->method('__get') ->with($this->equalTo('ldapEmailAttribute')) - ->will($this->returnValue('')); + ->willReturn(''); $this->access->expects($this->never()) ->method('readAttribute'); @@ -185,7 +185,7 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('myquota')) - ->will($this->returnValue(['42 GB'])); + ->willReturn(['42 GB']); $coreUser = $this->createMock(IUser::class); $coreUser->expects($this->once()) @@ -195,7 +195,7 @@ class UserTest extends \Test\TestCase { $this->userManager->expects($this->atLeastOnce()) ->method('get') ->with($this->uid) - ->will($this->returnValue($coreUser)); + ->willReturn($coreUser); $this->user->updateQuota(); } @@ -212,7 +212,7 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('myquota')) - ->will($this->returnValue(['default'])); + ->willReturn(['default']); $coreUser = $this->createMock(IUser::class); $coreUser->expects($this->once()) @@ -222,7 +222,7 @@ class UserTest extends \Test\TestCase { $this->userManager->expects($this->once()) ->method('get') ->with($this->uid) - ->will($this->returnValue($coreUser)); + ->willReturn($coreUser); $this->user->updateQuota(); } @@ -239,7 +239,7 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('myquota')) - ->will($this->returnValue(['none'])); + ->willReturn(['none']); $coreUser = $this->createMock(IUser::class); $coreUser->expects($this->once()) @@ -249,7 +249,7 @@ class UserTest extends \Test\TestCase { $this->userManager->expects($this->once()) ->method('get') ->with($this->uid) - ->will($this->returnValue($coreUser)); + ->willReturn($coreUser); $this->user->updateQuota(); } @@ -258,11 +258,11 @@ class UserTest extends \Test\TestCase { $this->connection->expects($this->at(0)) ->method('__get') ->with($this->equalTo('ldapQuotaAttribute')) - ->will($this->returnValue('myquota')); + ->willReturn('myquota'); $this->connection->expects($this->at(1)) ->method('__get') ->with($this->equalTo('ldapQuotaDefault')) - ->will($this->returnValue('25 GB')); + ->willReturn('25 GB'); $this->connection->expects($this->exactly(2)) ->method('__get'); @@ -270,7 +270,7 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('myquota')) - ->will($this->returnValue(false)); + ->willReturn(false); $coreUser = $this->createMock(IUser::class); $coreUser->expects($this->once()) @@ -280,7 +280,7 @@ class UserTest extends \Test\TestCase { $this->userManager->expects($this->once()) ->method('get') ->with($this->uid) - ->will($this->returnValue($coreUser)); + ->willReturn($coreUser); $this->user->updateQuota(); } @@ -297,7 +297,7 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('myquota')) - ->will($this->returnValue(['27 GB'])); + ->willReturn(['27 GB']); $coreUser = $this->createMock(IUser::class); $coreUser->expects($this->once()) @@ -307,7 +307,7 @@ class UserTest extends \Test\TestCase { $this->userManager->expects($this->once()) ->method('get') ->with($this->uid) - ->will($this->returnValue($coreUser)); + ->willReturn($coreUser); $this->user->updateQuota(); } @@ -324,7 +324,7 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('myquota')) - ->will($this->returnValue(false)); + ->willReturn(false); $coreUser = $this->createMock(IUser::class); $coreUser->expects($this->never()) @@ -385,7 +385,7 @@ class UserTest extends \Test\TestCase { $this->userManager->expects($this->once()) ->method('get') ->with($this->uid) - ->will($this->returnValue($user)); + ->willReturn($user); $this->user->updateQuota($readQuota); } @@ -405,7 +405,7 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('myquota')) - ->will($this->returnValue(['42 GBwos'])); + ->willReturn(['42 GBwos']); $coreUser = $this->createMock(IUser::class); $coreUser->expects($this->once()) @@ -415,7 +415,7 @@ class UserTest extends \Test\TestCase { $this->userManager->expects($this->once()) ->method('get') ->with($this->uid) - ->will($this->returnValue($coreUser)); + ->willReturn($coreUser); $this->user->updateQuota(); } @@ -435,7 +435,7 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('myquota')) - ->will($this->returnValue(false)); + ->willReturn(false); $coreUser = $this->createMock(IUser::class); $coreUser->expects($this->never()) @@ -462,7 +462,7 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('myquota')) - ->will($this->returnValue(['23 flush'])); + ->willReturn(['23 flush']); $coreUser = $this->createMock(IUser::class); $coreUser->expects($this->never()) @@ -504,26 +504,26 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('jpegphoto')) - ->will($this->returnValue(['this is a photo'])); + ->willReturn(['this is a photo']); $this->image->expects($this->once()) ->method('loadFromBase64') ->willReturn('imageResource'); $this->image->expects($this->once()) ->method('valid') - ->will($this->returnValue(true)); + ->willReturn(true); $this->image->expects($this->once()) ->method('width') - ->will($this->returnValue(128)); + ->willReturn(128); $this->image->expects($this->once()) ->method('height') - ->will($this->returnValue(128)); + ->willReturn(128); $this->image->expects($this->once()) ->method('centerCrop') - ->will($this->returnValue(true)); + ->willReturn(true); $this->image->expects($this->once()) ->method('data') - ->will($this->returnValue('this is a photo')); + ->willReturn('this is a photo'); $this->config->expects($this->once()) ->method('getUserValue') @@ -535,7 +535,7 @@ class UserTest extends \Test\TestCase { $this->filesystemhelper->expects($this->once()) ->method('isLoaded') - ->will($this->returnValue(true)); + ->willReturn(true); $avatar = $this->createMock(IAvatar::class); $avatar->expects($this->once()) @@ -545,7 +545,7 @@ class UserTest extends \Test\TestCase { $this->avatarManager->expects($this->once()) ->method('getAvatar') ->with($this->equalTo($this->uid)) - ->will($this->returnValue($avatar)); + ->willReturn($avatar); $this->connection->expects($this->any()) ->method('resolveRule') @@ -560,7 +560,7 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('jpegphoto')) - ->will($this->returnValue(['this is a photo'])); + ->willReturn(['this is a photo']); $this->image->expects($this->once()) ->method('loadFromBase64') @@ -575,7 +575,7 @@ class UserTest extends \Test\TestCase { ->method('centerCrop'); $this->image->expects($this->once()) ->method('data') - ->will($this->returnValue('this is a photo')); + ->willReturn('this is a photo'); $this->config->expects($this->once()) ->method('getUserValue') @@ -623,19 +623,19 @@ class UserTest extends \Test\TestCase { ->willReturn('imageResource'); $this->image->expects($this->once()) ->method('valid') - ->will($this->returnValue(true)); + ->willReturn(true); $this->image->expects($this->once()) ->method('width') - ->will($this->returnValue(128)); + ->willReturn(128); $this->image->expects($this->once()) ->method('height') - ->will($this->returnValue(128)); + ->willReturn(128); $this->image->expects($this->once()) ->method('centerCrop') - ->will($this->returnValue(true)); + ->willReturn(true); $this->image->expects($this->once()) ->method('data') - ->will($this->returnValue('this is a photo')); + ->willReturn('this is a photo'); $this->config->expects($this->once()) ->method('getUserValue') @@ -647,7 +647,7 @@ class UserTest extends \Test\TestCase { $this->filesystemhelper->expects($this->once()) ->method('isLoaded') - ->will($this->returnValue(true)); + ->willReturn(true); $avatar = $this->createMock(IAvatar::class); $avatar->expects($this->once()) @@ -657,7 +657,7 @@ class UserTest extends \Test\TestCase { $this->avatarManager->expects($this->once()) ->method('getAvatar') ->with($this->equalTo($this->uid)) - ->will($this->returnValue($avatar)); + ->willReturn($avatar); $this->connection->expects($this->any()) ->method('resolveRule') @@ -741,19 +741,19 @@ class UserTest extends \Test\TestCase { ->willReturn('imageResource'); $this->image->expects($this->once()) ->method('valid') - ->will($this->returnValue(true)); + ->willReturn(true); $this->image->expects($this->once()) ->method('width') - ->will($this->returnValue(128)); + ->willReturn(128); $this->image->expects($this->once()) ->method('height') - ->will($this->returnValue(128)); + ->willReturn(128); $this->image->expects($this->once()) ->method('centerCrop') - ->will($this->returnValue(true)); + ->willReturn(true); $this->image->expects($this->once()) ->method('data') - ->will($this->returnValue('this is a photo')); + ->willReturn('this is a photo'); $this->config->expects($this->once()) ->method('getUserValue') @@ -764,7 +764,7 @@ class UserTest extends \Test\TestCase { $this->filesystemhelper->expects($this->once()) ->method('isLoaded') - ->will($this->returnValue(true)); + ->willReturn(true); $avatar = $this->createMock(IAvatar::class); $avatar->expects($this->once()) @@ -775,7 +775,7 @@ class UserTest extends \Test\TestCase { $this->avatarManager->expects($this->once()) ->method('getAvatar') ->with($this->equalTo($this->uid)) - ->will($this->returnValue($avatar)); + ->willReturn($avatar); $this->connection->expects($this->any()) ->method('resolveRule') @@ -837,13 +837,13 @@ class UserTest extends \Test\TestCase { ->with($this->equalTo($this->uid), $this->equalTo('user_ldap'), $this->equalTo(User::USER_PREFKEY_FIRSTLOGIN), $this->equalTo(0)) - ->will($this->returnValue(0)); + ->willReturn(0); $this->config->expects($this->at(1)) ->method('getUserValue') ->with($this->equalTo($this->uid), $this->equalTo('user_ldap'), $this->equalTo(User::USER_PREFKEY_LASTREFRESH), $this->equalTo(0)) - ->will($this->returnValue(0)); + ->willReturn(0); $this->config->expects($this->exactly(2)) ->method('getUserValue'); $this->config->expects($this->never()) @@ -858,13 +858,13 @@ class UserTest extends \Test\TestCase { ->with($this->equalTo($this->uid), $this->equalTo('user_ldap'), $this->equalTo(User::USER_PREFKEY_FIRSTLOGIN), $this->equalTo(0)) - ->will($this->returnValue(1)); + ->willReturn(1); $this->config->expects($this->at(1)) ->method('getUserValue') ->with($this->equalTo($this->uid), $this->equalTo('user_ldap'), $this->equalTo(User::USER_PREFKEY_LASTREFRESH), $this->equalTo(0)) - ->will($this->returnValue(0)); + ->willReturn(0); $this->config->expects($this->exactly(2)) ->method('getUserValue'); $this->config->expects($this->once()) @@ -872,7 +872,7 @@ class UserTest extends \Test\TestCase { ->with($this->equalTo($this->uid), $this->equalTo('user_ldap'), $this->equalTo(User::USER_PREFKEY_LASTREFRESH), $this->anything()) - ->will($this->returnValue(true)); + ->willReturn(true); $this->connection->expects($this->any()) ->method('resolveRule') @@ -932,19 +932,19 @@ class UserTest extends \Test\TestCase { ->with($this->equalTo($this->uid), $this->equalTo('user_ldap'), $this->equalTo(User::USER_PREFKEY_FIRSTLOGIN), $this->equalTo(0)) - ->will($this->returnValue(1)); + ->willReturn(1); $this->config->expects($this->at(1)) ->method('getUserValue') ->with($this->equalTo($this->uid), $this->equalTo('user_ldap'), $this->equalTo(User::USER_PREFKEY_LASTREFRESH), $this->equalTo(0)) - ->will($this->returnValue(time() - 10)); + ->willReturn(time() - 10); $this->config->expects($this->once()) ->method('getAppValue') ->with($this->equalTo('user_ldap'), $this->equalTo('updateAttributesInterval'), $this->anything()) - ->will($this->returnValue(1800)); + ->willReturn(1800); $this->config->expects($this->exactly(2)) ->method('getUserValue'); $this->config->expects($this->never()) @@ -960,7 +960,7 @@ class UserTest extends \Test\TestCase { $this->equalTo('user_ldap'), $this->equalTo(User::USER_PREFKEY_FIRSTLOGIN), $this->equalTo(1)) - ->will($this->returnValue(true)); + ->willReturn(true); $this->user->markLogin(); } @@ -970,7 +970,7 @@ class UserTest extends \Test\TestCase { ->method('readAttribute') ->with($this->equalTo($this->dn), $this->equalTo('jpegphoto')) - ->will($this->returnValue(['this is a photo'])); + ->willReturn(['this is a photo']); $this->connection->expects($this->any()) ->method('resolveRule') ->with('avatar') @@ -1032,17 +1032,17 @@ class UserTest extends \Test\TestCase { ->setMethods($requiredMethods) ->getMock(); - $this->connection->setConfiguration(array( + $this->connection->setConfiguration([ 'homeFolderNamingRule' => 'homeDirectory' - )); + ]); $this->connection->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'homeFolderNamingRule') { return 'attr:homeDirectory'; } return $name; - })); + }); $this->connection->expects($this->any()) ->method('resolveRule') ->with('avatar') @@ -1070,10 +1070,10 @@ class UserTest extends \Test\TestCase { } public function emptyHomeFolderAttributeValueProvider() { - return array( + return [ 'empty' => [''], 'prefixOnly' => ['attr:'], - ); + ]; } /** @@ -1083,7 +1083,7 @@ class UserTest extends \Test\TestCase { $this->connection->expects($this->any()) ->method('__get') ->with($this->equalTo('homeFolderNamingRule')) - ->will($this->returnValue($attributeValue)); + ->willReturn($attributeValue); $this->access->expects($this->never()) ->method('readAttribute'); @@ -1099,16 +1099,16 @@ class UserTest extends \Test\TestCase { $this->connection->expects($this->any()) ->method('__get') ->with($this->equalTo('homeFolderNamingRule')) - ->will($this->returnValue('attr:foobar')); + ->willReturn('attr:foobar'); $this->access->expects($this->once()) ->method('readAttribute') - ->will($this->returnValue(false)); + ->willReturn(false); // asks for "enforce_home_folder_naming_rule" $this->config->expects($this->once()) ->method('getAppValue') - ->will($this->returnValue(false)); + ->willReturn(false); /** @noinspection PhpUnhandledExceptionInspection */ $this->assertFalse($this->user->getHomePath()); @@ -1121,16 +1121,16 @@ class UserTest extends \Test\TestCase { $this->connection->expects($this->any()) ->method('__get') ->with($this->equalTo('homeFolderNamingRule')) - ->will($this->returnValue('attr:foobar')); + ->willReturn('attr:foobar'); $this->access->expects($this->once()) ->method('readAttribute') - ->will($this->returnValue(false)); + ->willReturn(false); // asks for "enforce_home_folder_naming_rule" $this->config->expects($this->once()) ->method('getAppValue') - ->will($this->returnValue(true)); + ->willReturn(true); $this->user->getHomePath(); } @@ -1192,7 +1192,7 @@ class UserTest extends \Test\TestCase { public function testHandlePasswordExpiryWarningDefaultPolicy() { $this->connection->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'ldapDefaultPPolicyDN') { return 'cn=default,ou=policies,dc=foo,dc=bar'; } @@ -1200,11 +1200,11 @@ class UserTest extends \Test\TestCase { return '1'; } return $name; - })); + }); $this->access->expects($this->any()) ->method('search') - ->will($this->returnCallback(function($filter, $base) { + ->willReturnCallback(function($filter, $base) { if($base === [$this->dn]) { return [ [ @@ -1222,27 +1222,27 @@ class UserTest extends \Test\TestCase { ]; } return []; - })); + }); $notification = $this->getMockBuilder(INotification::class) ->disableOriginalConstructor() ->getMock(); $notification->expects($this->any()) ->method('setApp') - ->will($this->returnValue($notification)); + ->willReturn($notification); $notification->expects($this->any()) ->method('setUser') - ->will($this->returnValue($notification)); + ->willReturn($notification); $notification->expects($this->any()) ->method('setObject') - ->will($this->returnValue($notification)); + ->willReturn($notification); $notification->expects($this->any()) ->method('setDateTime') - ->will($this->returnValue($notification)); + ->willReturn($notification); $this->notificationManager->expects($this->exactly(2)) ->method('createNotification') - ->will($this->returnValue($notification)); + ->willReturn($notification); $this->notificationManager->expects($this->exactly(1)) ->method('notify'); @@ -1255,7 +1255,7 @@ class UserTest extends \Test\TestCase { public function testHandlePasswordExpiryWarningCustomPolicy() { $this->connection->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'ldapDefaultPPolicyDN') { return 'cn=default,ou=policies,dc=foo,dc=bar'; } @@ -1263,11 +1263,11 @@ class UserTest extends \Test\TestCase { return '1'; } return $name; - })); + }); $this->access->expects($this->any()) ->method('search') - ->will($this->returnCallback(function($filter, $base) { + ->willReturnCallback(function($filter, $base) { if($base === [$this->dn]) { return [ [ @@ -1286,27 +1286,27 @@ class UserTest extends \Test\TestCase { ]; } return []; - })); + }); $notification = $this->getMockBuilder(INotification::class) ->disableOriginalConstructor() ->getMock(); $notification->expects($this->any()) ->method('setApp') - ->will($this->returnValue($notification)); + ->willReturn($notification); $notification->expects($this->any()) ->method('setUser') - ->will($this->returnValue($notification)); + ->willReturn($notification); $notification->expects($this->any()) ->method('setObject') - ->will($this->returnValue($notification)); + ->willReturn($notification); $notification->expects($this->any()) ->method('setDateTime') - ->will($this->returnValue($notification)); + ->willReturn($notification); $this->notificationManager->expects($this->exactly(2)) ->method('createNotification') - ->will($this->returnValue($notification)); + ->willReturn($notification); $this->notificationManager->expects($this->exactly(1)) ->method('notify'); diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index e4a105b2bd6..baa307b2e6b 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -107,7 +107,7 @@ class User_LDAPTest extends TestCase { private function prepareMockForUserExists() { $this->access->expects($this->any()) ->method('username2dn') - ->will($this->returnCallback(function($uid) { + ->willReturnCallback(function($uid) { switch ($uid) { case 'gunslinger': return 'dnOfRoland,dc=test'; @@ -124,7 +124,7 @@ class User_LDAPTest extends TestCase { default: return false; } - })); + }); $this->access->method('fetchUsersByLoginName') ->willReturn([]); @@ -138,29 +138,29 @@ class User_LDAPTest extends TestCase { private function prepareAccessForCheckPassword($noDisplayName = false) { $this->connection->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'ldapLoginFilter') { return '%uid'; } return null; - })); + }); $this->access->expects($this->any()) ->method('fetchListOfUsers') - ->will($this->returnCallback(function($filter) { + ->willReturnCallback(function($filter) { if($filter === 'roland') { - return array(array('dn' => ['dnOfRoland,dc=test'])); + return [['dn' => ['dnOfRoland,dc=test']]]; } - return array(); - })); + return []; + }); $this->access->expects($this->any()) ->method('fetchUsersByLoginName') - ->will($this->returnCallback(function($uid) { + ->willReturnCallback(function($uid) { if($uid === 'roland') { - return array(array('dn' => ['dnOfRoland,dc=test'])); + return [['dn' => ['dnOfRoland,dc=test']]]; } - return array(); - })); + return []; + }); $retVal = 'gunslinger'; if($noDisplayName === true) { @@ -169,19 +169,19 @@ class User_LDAPTest extends TestCase { $this->access->expects($this->any()) ->method('dn2username') ->with($this->equalTo('dnOfRoland,dc=test')) - ->will($this->returnValue($retVal)); + ->willReturn($retVal); $this->access->expects($this->any()) ->method('stringResemblesDN') ->with($this->equalTo('dnOfRoland,dc=test')) - ->will($this->returnValue(true)); + ->willReturn(true); $this->access->expects($this->any()) ->method('areCredentialsValid') - ->will($this->returnCallback(function($dn, $pwd) { + ->willReturnCallback(function($dn, $pwd) { if($pwd === 'dt19') { return true; } return false; - })); + }); } public function testCheckPasswordUidReturn() { @@ -297,10 +297,10 @@ class User_LDAPTest extends TestCase { $mapping = $this->createMock(UserMapping::class); $mapping->expects($this->once()) ->method('unmap') - ->will($this->returnValue(true)); + ->willReturn(true); $this->access->expects($this->once()) ->method('getUserMapper') - ->will($this->returnValue($mapping)); + ->willReturn($mapping); $this->connection->expects($this->any()) ->method('getConnectionResource') ->willReturn('this is an ldap link'); @@ -362,27 +362,27 @@ class User_LDAPTest extends TestCase { private function prepareAccessForGetUsers() { $this->access->expects($this->once()) ->method('escapeFilterPart') - ->will($this->returnCallback(function($search) { + ->willReturnCallback(function($search) { return $search; - })); + }); $this->access->expects($this->any()) ->method('getFilterPartForUserSearch') - ->will($this->returnCallback(function($search) { + ->willReturnCallback(function($search) { return $search; - })); + }); $this->access->expects($this->any()) ->method('combineFilterWithAnd') - ->will($this->returnCallback(function($param) { + ->willReturnCallback(function($param) { return $param[2]; - })); + }); $this->access->expects($this->any()) ->method('fetchListOfUsers') - ->will($this->returnCallback(function($search, $a, $l, $o) { - $users = array('gunslinger', 'newyorker', 'ladyofshadows'); + ->willReturnCallback(function($search, $a, $l, $o) { + $users = ['gunslinger', 'newyorker', 'ladyofshadows']; if(empty($search)) { $result = $users; } else { - $result = array(); + $result = []; foreach($users as $user) { if(stripos($user, $search) !== false) { $result[] = $user; @@ -393,10 +393,10 @@ class User_LDAPTest extends TestCase { $result = array_slice($result, $o, $l); } return $result; - })); + }); $this->access->expects($this->any()) ->method('nextcloudUserNames') - ->will($this->returnArgument(0)); + ->willReturnArgument(0); $this->access->method('fetchUsersByLoginName') ->willReturn([]); } @@ -543,12 +543,12 @@ class User_LDAPTest extends TestCase { $this->access->expects($this->any()) ->method('readAttribute') - ->will($this->returnCallback(function($dn) { + ->willReturnCallback(function($dn) { if($dn === 'dnOfRoland,dc=test') { - return array(); + return []; } return false; - })); + }); //test for never-existing user /** @noinspection PhpUnhandledExceptionInspection */ @@ -568,12 +568,12 @@ class User_LDAPTest extends TestCase { $this->access->expects($this->any()) ->method('readAttribute') - ->will($this->returnCallback(function($dn) { + ->willReturnCallback(function($dn) { if($dn === 'dnOfRoland,dc=test') { - return array(); + return []; } return false; - })); + }); $this->userManager->expects($this->atLeastOnce()) ->method('get') ->willReturn($user); @@ -600,27 +600,27 @@ class User_LDAPTest extends TestCase { $this->connection->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'homeFolderNamingRule') { return 'attr:testAttribute'; } return null; - })); + }); $this->access->expects($this->any()) ->method('readAttribute') - ->will($this->returnCallback(function($dn, $attr) { + ->willReturnCallback(function($dn, $attr) { switch ($dn) { case 'dnOfRoland,dc=test': if($attr === 'testAttribute') { - return array('/tmp/rolandshome/'); + return ['/tmp/rolandshome/']; } - return array(); + return []; break; default: return false; } - })); + }); $user = $this->createMock(User::class); $user->expects($this->any()) @@ -652,27 +652,27 @@ class User_LDAPTest extends TestCase { $this->connection->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'homeFolderNamingRule') { return 'attr:testAttribute'; } return null; - })); + }); $this->access->expects($this->any()) ->method('readAttribute') - ->will($this->returnCallback(function($dn, $attr) { + ->willReturnCallback(function($dn, $attr) { switch ($dn) { case 'dnOfLadyOfShadows,dc=test': if($attr === 'testAttribute') { - return array('susannah/'); + return ['susannah/']; } - return array(); + return []; break; default: return false; } - })); + }); $user = $this->createMock(User::class); $user->expects($this->any()) @@ -703,20 +703,20 @@ class User_LDAPTest extends TestCase { $this->connection->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'homeFolderNamingRule') { return 'attr:testAttribute'; } return null; - })); + }); $this->access->expects($this->any()) ->method('readAttribute') - ->will($this->returnCallback(function($dn, $attr) { + ->willReturnCallback(function($dn, $attr) { switch ($dn) { default: return false; } - })); + }); $this->access->connection->expects($this->any()) ->method('getFromCache') ->willReturnCallback(function($key) { @@ -751,26 +751,26 @@ class User_LDAPTest extends TestCase { $this->connection->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'homeFolderNamingRule') { return 'attr:testAttribute'; } return null; - })); + }); $this->access->expects($this->any()) ->method('readAttribute') - ->will($this->returnValue([])); + ->willReturn([]); $userMapper = $this->createMock(UserMapping::class); $this->access->expects($this->any()) ->method('getUserMapper') - ->will($this->returnValue($userMapper)); + ->willReturn($userMapper); $this->config->expects($this->any()) ->method('getUserValue') - ->will($this->returnValue(true)); + ->willReturn(true); $offlineUser = $this->createMock(OfflineUser::class); $offlineUser->expects($this->atLeastOnce()) @@ -797,9 +797,9 @@ class User_LDAPTest extends TestCase { $this->connection->expects($this->any()) ->method('getFromCache') - ->will($this->returnCallback(function($uid) { + ->willReturnCallback(function($uid) { return true; - })); + }); /** @noinspection PhpUnhandledExceptionInspection */ $this->assertEquals($this->backend->getHome('uid'),'result'); @@ -808,28 +808,28 @@ class User_LDAPTest extends TestCase { private function prepareAccessForGetDisplayName() { $this->connection->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'ldapUserDisplayName') { return 'displayname'; } return null; - })); + }); $this->access->expects($this->any()) ->method('readAttribute') - ->will($this->returnCallback(function($dn, $attr) { + ->willReturnCallback(function($dn, $attr) { switch ($dn) { case 'dnOfRoland,dc=test': if($attr === 'displayname') { - return array('Roland Deschain'); + return ['Roland Deschain']; } - return array(); + return []; break; default: return false; } - })); + }); $this->access->method('fetchUsersByLoginName') ->willReturn([]); } @@ -841,9 +841,9 @@ class User_LDAPTest extends TestCase { $this->connection->expects($this->any()) ->method('getConnectionResource') - ->will($this->returnCallback(function() { + ->willReturnCallback(function() { return true; - })); + }); $user1 = $this->createMock(User::class); $user1->expects($this->once()) @@ -894,7 +894,7 @@ class User_LDAPTest extends TestCase { public function testGetDisplayNamePublicAPI() { $this->access->expects($this->any()) ->method('username2dn') - ->will($this->returnCallback(function($uid) { + ->willReturnCallback(function($uid) { switch ($uid) { case 'gunslinger': return 'dnOfRoland,dc=test'; @@ -911,16 +911,16 @@ class User_LDAPTest extends TestCase { default: return false; } - })); + }); $this->prepareAccessForGetDisplayName(); $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager); $this->prepareMockForUserExists(); $this->connection->expects($this->any()) ->method('getConnectionResource') - ->will($this->returnCallback(function() { + ->willReturnCallback(function() { return true; - })); + }); \OC_User::useBackend($backend); @@ -989,7 +989,7 @@ class User_LDAPTest extends TestCase { public function testCountUsers() { $this->access->expects($this->once()) ->method('countUsers') - ->will($this->returnValue(5)); + ->willReturn(5); $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager); @@ -1000,7 +1000,7 @@ class User_LDAPTest extends TestCase { public function testCountUsersFailing() { $this->access->expects($this->once()) ->method('countUsers') - ->will($this->returnValue(false)); + ->willReturn(false); $backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager); @@ -1134,7 +1134,7 @@ class User_LDAPTest extends TestCase { private function prepareAccessForSetPassword($enablePasswordChange = true) { $this->connection->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) use (&$enablePasswordChange) { + ->willReturnCallback(function($name) use (&$enablePasswordChange) { if($name === 'ldapLoginFilter') { return '%uid'; } @@ -1142,48 +1142,48 @@ class User_LDAPTest extends TestCase { return $enablePasswordChange?1:0; } return null; - })); + }); $this->connection->expects($this->any()) ->method('getFromCache') - ->will($this->returnCallback(function($uid) { + ->willReturnCallback(function($uid) { if($uid === 'userExists'.'roland') { return true; } return null; - })); + }); $this->access->expects($this->any()) ->method('fetchListOfUsers') - ->will($this->returnCallback(function($filter) { + ->willReturnCallback(function($filter) { if($filter === 'roland') { - return array(array('dn' => ['dnOfRoland,dc=test'])); + return [['dn' => ['dnOfRoland,dc=test']]]; } - return array(); - })); + return []; + }); $this->access->expects($this->any()) ->method('fetchUsersByLoginName') - ->will($this->returnCallback(function($uid) { + ->willReturnCallback(function($uid) { if($uid === 'roland') { - return array(array('dn' => ['dnOfRoland,dc=test'])); + return [['dn' => ['dnOfRoland,dc=test']]]; } - return array(); - })); + return []; + }); $this->access->expects($this->any()) ->method('dn2username') ->with($this->equalTo('dnOfRoland,dc=test')) - ->will($this->returnValue('roland')); + ->willReturn('roland'); $this->access->expects($this->any()) ->method('stringResemblesDN') ->with($this->equalTo('dnOfRoland,dc=test')) - ->will($this->returnValue(true)); + ->willReturn(true); $this->access->expects($this->any()) ->method('setPassword') - ->will($this->returnCallback(function($uid, $password) { + ->willReturnCallback(function($uid, $password) { if(strlen($password) <= 5) { throw new HintException('Password fails quality checking policy', '', 19); } return true; - })); + }); } diff --git a/apps/user_ldap/tests/WizardTest.php b/apps/user_ldap/tests/WizardTest.php index 5535a28f44c..50931c75ff6 100644 --- a/apps/user_ldap/tests/WizardTest.php +++ b/apps/user_ldap/tests/WizardTest.php @@ -47,8 +47,8 @@ class WizardTest extends TestCase { parent::setUp(); //we need to make sure the consts are defined, otherwise tests will fail //on systems without php5_ldap - $ldapConsts = array('LDAP_OPT_PROTOCOL_VERSION', - 'LDAP_OPT_REFERRALS', 'LDAP_OPT_NETWORK_TIMEOUT'); + $ldapConsts = ['LDAP_OPT_PROTOCOL_VERSION', + 'LDAP_OPT_REFERRALS', 'LDAP_OPT_NETWORK_TIMEOUT']; foreach($ldapConsts as $const) { if(!defined($const)) { define($const, 42); @@ -78,22 +78,22 @@ class WizardTest extends TestCase { /** @var Access|\PHPUnit_Framework_MockObject_MockObject $access */ $access = $this->createMock(Access::class); - return array(new Wizard($conf, $lw, $access), $conf, $lw, $access); + return [new Wizard($conf, $lw, $access), $conf, $lw, $access]; } private function prepareLdapWrapperForConnections(MockObject &$ldap) { $ldap->expects($this->once()) ->method('connect') //dummy value, usually invalid - ->will($this->returnValue(true)); + ->willReturn(true); $ldap->expects($this->exactly(3)) ->method('setOption') - ->will($this->returnValue(true)); + ->willReturn(true); $ldap->expects($this->once()) ->method('bind') - ->will($this->returnValue(true)); + ->willReturn(true); } @@ -102,57 +102,57 @@ class WizardTest extends TestCase { $configuration->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'ldapBase') { - return array('base'); + return ['base']; } return null; - })); + }); $this->prepareLdapWrapperForConnections($ldap); $ldap->expects($this->any()) ->method('isResource') - ->will($this->returnValue(true)); + ->willReturn(true); $ldap->expects($this->exactly(2)) ->method('search') //dummy value, usually invalid - ->will($this->returnValue(true)); + ->willReturn(true); $ldap->expects($this->exactly(2)) ->method('countEntries') //an is_resource check will follow, so we need to return a dummy resource - ->will($this->returnValue(23)); + ->willReturn(23); //5 DNs per filter means 2x firstEntry and 8x nextEntry $ldap->expects($this->exactly(2)) ->method('firstEntry') //dummy value, usually invalid - ->will($this->returnValue(true)); + ->willReturn(true); $ldap->expects($this->exactly(8)) ->method('nextEntry') //dummy value, usually invalid - ->will($this->returnValue(true)); + ->willReturn(true); $ldap->expects($this->exactly(10)) ->method('getAttributes') //dummy value, usually invalid - ->will($this->returnValue(array('cn' => array('foo'), 'count' => 1))); + ->willReturn(['cn' => ['foo'], 'count' => 1]); global $uidnumber; $uidnumber = 1; $ldap->expects($this->exactly(10)) ->method('getDN') //dummy value, usually invalid - ->will($this->returnCallback(function($a, $b) { + ->willReturnCallback(function($a, $b) { global $uidnumber; return $uidnumber++; - })); + }); // The following expectations are the real test - $filters = array('f1', 'f2', '*'); + $filters = ['f1', 'f2', '*']; $wizard->cumulativeSearchOnAttribute($filters, 'cn', 5); unset($uidnumber); } @@ -162,18 +162,18 @@ class WizardTest extends TestCase { $configuration->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'ldapBase') { - return array('base'); + return ['base']; } return null; - })); + }); $this->prepareLdapWrapperForConnections($ldap); $ldap->expects($this->any()) ->method('isResource') - ->will($this->returnCallback(function($r) { + ->willReturnCallback(function($r) { if($r === true) { return true; } @@ -183,52 +183,52 @@ class WizardTest extends TestCase { return false; } return true; - })); + }); $ldap->expects($this->exactly(2)) ->method('search') //dummy value, usually invalid - ->will($this->returnValue(true)); + ->willReturn(true); $ldap->expects($this->exactly(2)) ->method('countEntries') //an is_resource check will follow, so we need to return a dummy resource - ->will($this->returnValue(23)); + ->willReturn(23); //5 DNs per filter means 2x firstEntry and 8x nextEntry $ldap->expects($this->exactly(2)) ->method('firstEntry') //dummy value, usually invalid - ->will($this->returnCallback(function($r) { + ->willReturnCallback(function($r) { global $uidnumber; return $uidnumber; - })); + }); $ldap->expects($this->exactly(46)) ->method('nextEntry') //dummy value, usually invalid - ->will($this->returnCallback(function($r) { + ->willReturnCallback(function($r) { global $uidnumber; return $uidnumber; - })); + }); $ldap->expects($this->exactly(46)) ->method('getAttributes') //dummy value, usually invalid - ->will($this->returnValue(array('cn' => array('foo'), 'count' => 1))); + ->willReturn(['cn' => ['foo'], 'count' => 1]); global $uidnumber; $uidnumber = 1; $ldap->expects($this->exactly(46)) ->method('getDN') //dummy value, usually invalid - ->will($this->returnCallback(function($a, $b) { + ->willReturnCallback(function($a, $b) { global $uidnumber; return $uidnumber++; - })); + }); // The following expectations are the real test - $filters = array('f1', 'f2', '*'); + $filters = ['f1', 'f2', '*']; $wizard->cumulativeSearchOnAttribute($filters, 'cn', 0); unset($uidnumber); } @@ -239,18 +239,18 @@ class WizardTest extends TestCase { $configuration->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function ($name) { + ->willReturnCallback(function ($name) { if($name === 'ldapEmailAttribute') { return 'myEmailAttribute'; } else { //for requirement checks return 'let me pass'; } - })); + }); $access->expects($this->once()) ->method('countUsers') - ->will($this->returnValue(42)); + ->willReturn(42); $wizard->detectEmailAttribute(); } @@ -261,24 +261,24 @@ class WizardTest extends TestCase { $configuration->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function ($name) { + ->willReturnCallback(function ($name) { if($name === 'ldapEmailAttribute') { return 'myEmailAttribute'; } else { //for requirement checks return 'let me pass'; } - })); + }); $access->expects($this->exactly(3)) ->method('combineFilterWithAnd') - ->will($this->returnCallback(function ($filterParts) { + ->willReturnCallback(function ($filterParts) { return str_replace('=*', '', array_pop($filterParts)); - })); + }); $access->expects($this->exactly(3)) ->method('countUsers') - ->will($this->returnCallback(function ($filter) { + ->willReturnCallback(function ($filter) { if($filter === 'myEmailAttribute') { return 0; } else if($filter === 'mail') { @@ -287,7 +287,7 @@ class WizardTest extends TestCase { return 17; } throw new \Exception('Untested filter: ' . $filter); - })); + }); $result = $wizard->detectEmailAttribute()->getResultArray(); $this->assertSame('mailPrimaryAddress', @@ -300,24 +300,24 @@ class WizardTest extends TestCase { $configuration->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function ($name) { + ->willReturnCallback(function ($name) { if($name === 'ldapEmailAttribute') { return ''; } else { //for requirement checks return 'let me pass'; } - })); + }); $access->expects($this->exactly(2)) ->method('combineFilterWithAnd') - ->will($this->returnCallback(function ($filterParts) { + ->willReturnCallback(function ($filterParts) { return str_replace('=*', '', array_pop($filterParts)); - })); + }); $access->expects($this->exactly(2)) ->method('countUsers') - ->will($this->returnCallback(function ($filter) { + ->willReturnCallback(function ($filter) { if($filter === 'myEmailAttribute') { return 0; } else if($filter === 'mail') { @@ -326,7 +326,7 @@ class WizardTest extends TestCase { return 17; } throw new \Exception('Untested filter: ' . $filter); - })); + }); $result = $wizard->detectEmailAttribute()->getResultArray(); $this->assertSame('mailPrimaryAddress', @@ -339,24 +339,24 @@ class WizardTest extends TestCase { $configuration->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function ($name) { + ->willReturnCallback(function ($name) { if($name === 'ldapEmailAttribute') { return 'myEmailAttribute'; } else { //for requirement checks return 'let me pass'; } - })); + }); $access->expects($this->exactly(3)) ->method('combineFilterWithAnd') - ->will($this->returnCallback(function ($filterParts) { + ->willReturnCallback(function ($filterParts) { return str_replace('=*', '', array_pop($filterParts)); - })); + }); $access->expects($this->exactly(3)) ->method('countUsers') - ->will($this->returnCallback(function ($filter) { + ->willReturnCallback(function ($filter) { if($filter === 'myEmailAttribute') { return 0; } else if($filter === 'mail') { @@ -365,7 +365,7 @@ class WizardTest extends TestCase { return 0; } throw new \Exception('Untested filter: ' . $filter); - })); + }); $result = $wizard->detectEmailAttribute(); $this->assertSame(false, $result->hasChanges()); @@ -378,36 +378,36 @@ class WizardTest extends TestCase { $configuration->expects($this->any()) ->method('__get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if($name === 'ldapBase') { - return array('base'); + return ['base']; } return null; - })); + }); $this->prepareLdapWrapperForConnections($ldap); $ldap->expects($this->any()) ->method('isResource') - ->will($this->returnCallback(function($res) { + ->willReturnCallback(function($res) { return (bool)$res; - })); + }); $ldap->expects($this->any()) ->method('search') //dummy value, usually invalid - ->will($this->returnValue(true)); + ->willReturn(true); $ldap->expects($this->any()) ->method('countEntries') //an is_resource check will follow, so we need to return a dummy resource - ->will($this->returnValue(7)); + ->willReturn(7); //5 DNs per filter means 2x firstEntry and 8x nextEntry $ldap->expects($this->any()) ->method('firstEntry') //dummy value, usually invalid - ->will($this->returnValue(1)); + ->willReturn(1); global $mark; $mark = false; @@ -415,7 +415,7 @@ class WizardTest extends TestCase { $ldap->expects($this->any()) ->method('nextEntry') //dummy value, usually invalid - ->will($this->returnCallback(function($a, $prev){ + ->willReturnCallback(function($a, $prev){ $current = $prev + 1; if($current === 7) { return false; @@ -426,24 +426,24 @@ class WizardTest extends TestCase { return 4; } return $current; - })); + }); $ldap->expects($this->any()) ->method('getAttributes') //dummy value, usually invalid - ->will($this->returnCallback(function($a, $entry) { - return array('cn' => array($entry), 'count' => 1); - })); + ->willReturnCallback(function($a, $entry) { + return ['cn' => [$entry], 'count' => 1]; + }); $ldap->expects($this->any()) ->method('getDN') //dummy value, usually invalid - ->will($this->returnCallback(function($a, $b) { + ->willReturnCallback(function($a, $b) { return $b; - })); + }); // The following expectations are the real test - $filters = array('f1', 'f2', '*'); + $filters = ['f1', 'f2', '*']; $resultArray = $wizard->cumulativeSearchOnAttribute($filters, 'cn', 0); $this->assertSame(6, count($resultArray)); unset($mark); |