Use type casting instead of *val() method

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2018-01-26 15:01:27 +01:00
parent ca493ab5b1
commit 2ad2eb38e8
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
6 changed files with 35 additions and 35 deletions

View File

@ -195,7 +195,7 @@ class Access extends LDAPUtility implements IUserTools {
$this->abandonPagedSearch(); $this->abandonPagedSearch();
// openLDAP requires that we init a new Paged Search. Not needed by AD, // openLDAP requires that we init a new Paged Search. Not needed by AD,
// but does not hurt either. // but does not hurt either.
$pagingSize = intval($this->connection->ldapPagingSize); $pagingSize = (int)$this->connection->ldapPagingSize;
// 0 won't result in replies, small numbers may leave out groups // 0 won't result in replies, small numbers may leave out groups
// (cf. #12306), 500 is default for paging and should work everywhere. // (cf. #12306), 500 is default for paging and should work everywhere.
$maxResults = $pagingSize > 20 ? $pagingSize : 500; $maxResults = $pagingSize > 20 ? $pagingSize : 500;
@ -352,7 +352,7 @@ class Access extends LDAPUtility implements IUserTools {
* @throws \Exception * @throws \Exception
*/ */
public function setPassword($userDN, $password) { public function setPassword($userDN, $password) {
if(intval($this->connection->turnOnPasswordChange) !== 1) { if((int)$this->connection->turnOnPasswordChange !== 1) {
throw new \Exception('LDAP password changes are disabled.'); throw new \Exception('LDAP password changes are disabled.');
} }
$cr = $this->connection->getConnectionResource(); $cr = $this->connection->getConnectionResource();
@ -573,7 +573,7 @@ class Access extends LDAPUtility implements IUserTools {
} }
if($isUser) { if($isUser) {
$usernameAttribute = strval($this->connection->ldapExpertUsernameAttr); $usernameAttribute = (string)$this->connection->ldapExpertUsernameAttr;
if ($usernameAttribute !== '') { if ($usernameAttribute !== '') {
$username = $this->readAttribute($fdn, $usernameAttribute); $username = $this->readAttribute($fdn, $usernameAttribute);
$username = $username[0]; $username = $username[0];
@ -751,9 +751,9 @@ class Access extends LDAPUtility implements IUserTools {
} else { } else {
natsort($usedNames); natsort($usedNames);
$lastName = array_pop($usedNames); $lastName = array_pop($usedNames);
$lastNo = intval(substr($lastName, strrpos($lastName, '_') + 1)); $lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1);
} }
$altName = $name.'_'.strval($lastNo+1); $altName = $name.'_'. (string)($lastNo+1);
unset($usedNames); unset($usedNames);
$attempts = 1; $attempts = 1;
@ -1051,7 +1051,7 @@ class Access extends LDAPUtility implements IUserTools {
} }
//check whether paged search should be attempted //check whether paged search should be attempted
$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, intval($limit), $offset); $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, $offset);
$linkResources = array_pad(array(), count($base), $cr); $linkResources = array_pad(array(), count($base), $cr);
$sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr); $sr = $this->invokeLDAPMethod('search', $linkResources, $base, $filter, $attr);
@ -1099,7 +1099,7 @@ class Access extends LDAPUtility implements IUserTools {
$this->pagedSearchedSuccessful = true; $this->pagedSearchedSuccessful = true;
} }
} else { } else {
if(!is_null($limit) && intval($this->connection->ldapPagingSize) !== 0) { if(!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) {
\OC::$server->getLogger()->debug( \OC::$server->getLogger()->debug(
'Paged search was not available', 'Paged search was not available',
[ 'app' => 'user_ldap' ] [ 'app' => 'user_ldap' ]
@ -1131,7 +1131,7 @@ class Access extends LDAPUtility implements IUserTools {
private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
\OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG);
$limitPerPage = intval($this->connection->ldapPagingSize); $limitPerPage = (int)$this->connection->ldapPagingSize;
if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
$limitPerPage = $limit; $limitPerPage = $limit;
} }
@ -1174,7 +1174,7 @@ class Access extends LDAPUtility implements IUserTools {
$counter = 0; $counter = 0;
foreach($searchResults as $res) { foreach($searchResults as $res) {
$count = intval($this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res)); $count = (int)$this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $res);
$counter += $count; $counter += $count;
} }
@ -1194,7 +1194,7 @@ class Access extends LDAPUtility implements IUserTools {
* @throws ServerNotAvailableException * @throws ServerNotAvailableException
*/ */
public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
$limitPerPage = intval($this->connection->ldapPagingSize); $limitPerPage = (int)$this->connection->ldapPagingSize;
if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
$limitPerPage = $limit; $limitPerPage = $limit;
} }
@ -1287,7 +1287,7 @@ class Access extends LDAPUtility implements IUserTools {
&& !is_null($limit) && !is_null($limit)
) )
) { ) {
$findings = array_slice($findings, intval($offset), $limit); $findings = array_slice($findings, (int)$offset, $limit);
} }
return $findings; return $findings;
} }
@ -1829,7 +1829,7 @@ class Access extends LDAPUtility implements IUserTools {
} }
$offset -= $limit; $offset -= $limit;
//we work with cache here //we work with cache here
$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . intval($limit) . '-' . intval($offset); $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
$cookie = ''; $cookie = '';
if(isset($this->cookies[$cacheKey])) { if(isset($this->cookies[$cacheKey])) {
$cookie = $this->cookies[$cacheKey]; $cookie = $this->cookies[$cacheKey];
@ -1876,7 +1876,7 @@ class Access extends LDAPUtility implements IUserTools {
private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) { private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) {
// allow '0' for 389ds // allow '0' for 389ds
if(!empty($cookie) || $cookie === '0') { if(!empty($cookie) || $cookie === '0') {
$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' .intval($limit) . '-' . intval($offset); $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . (int)$limit . '-' . (int)$offset;
$this->cookies[$cacheKey] = $cookie; $this->cookies[$cacheKey] = $cookie;
$this->lastCookie = $cookie; $this->lastCookie = $cookie;
} }
@ -1904,7 +1904,7 @@ class Access extends LDAPUtility implements IUserTools {
private function initPagedSearch($filter, $bases, $attr, $limit, $offset) { private function initPagedSearch($filter, $bases, $attr, $limit, $offset) {
$pagedSearchOK = false; $pagedSearchOK = false;
if($this->connection->hasPagedResultSupport && ($limit !== 0)) { if($this->connection->hasPagedResultSupport && ($limit !== 0)) {
$offset = intval($offset); //can be null $offset = (int)$offset; //can be null
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'initializing paged search for Filter '.$filter.' base '.print_r($bases, true) 'initializing paged search for Filter '.$filter.' base '.print_r($bases, true)
.' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset, .' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset,
@ -1956,7 +1956,7 @@ class Access extends LDAPUtility implements IUserTools {
$this->abandonPagedSearch(); $this->abandonPagedSearch();
// in case someone set it to 0 … use 500, otherwise no results will // in case someone set it to 0 … use 500, otherwise no results will
// be returned. // be returned.
$pageSize = intval($this->connection->ldapPagingSize) > 0 ? intval($this->connection->ldapPagingSize) : 500; $pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500;
$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult', $pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
$this->connection->getConnectionResource(), $this->connection->getConnectionResource(),
$pageSize, false, ''); $pageSize, false, '');

View File

@ -1008,7 +1008,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
return array(); return array();
} }
$search = $this->access->escapeFilterPart($search, true); $search = $this->access->escapeFilterPart($search, true);
$pagingSize = intval($this->access->connection->ldapPagingSize); $pagingSize = (int)$this->access->connection->ldapPagingSize;
if (!$this->access->connection->hasPagedResultSupport || $pagingSize <= 0) { if (!$this->access->connection->hasPagedResultSupport || $pagingSize <= 0) {
return $this->getGroupsChunk($search, $limit, $offset); return $this->getGroupsChunk($search, $limit, $offset);
} }

View File

@ -194,11 +194,11 @@ class User {
$displayName = $displayName2 = ''; $displayName = $displayName2 = '';
$attr = strtolower($this->connection->ldapUserDisplayName); $attr = strtolower($this->connection->ldapUserDisplayName);
if(isset($ldapEntry[$attr])) { if(isset($ldapEntry[$attr])) {
$displayName = strval($ldapEntry[$attr][0]); $displayName = (string)$ldapEntry[$attr][0];
} }
$attr = strtolower($this->connection->ldapUserDisplayName2); $attr = strtolower($this->connection->ldapUserDisplayName2);
if(isset($ldapEntry[$attr])) { if(isset($ldapEntry[$attr])) {
$displayName2 = strval($ldapEntry[$attr][0]); $displayName2 = (string)$ldapEntry[$attr][0];
} }
if ($displayName !== '') { if ($displayName !== '') {
$this->composeAndStoreDisplayName($displayName); $this->composeAndStoreDisplayName($displayName);
@ -281,7 +281,7 @@ class User {
* @throws \Exception * @throws \Exception
*/ */
public function getHomePath($valueFromLDAP = null) { public function getHomePath($valueFromLDAP = null) {
$path = strval($valueFromLDAP); $path = (string)$valueFromLDAP;
$attr = null; $attr = null;
if (is_null($valueFromLDAP) if (is_null($valueFromLDAP)
@ -387,7 +387,7 @@ class User {
$lastChecked = $this->config->getUserValue($this->uid, 'user_ldap', $lastChecked = $this->config->getUserValue($this->uid, 'user_ldap',
self::USER_PREFKEY_LASTREFRESH, 0); self::USER_PREFKEY_LASTREFRESH, 0);
if((time() - intval($lastChecked)) < intval($this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) ) { if((time() - (int)$lastChecked) < (int)$this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) {
return false; return false;
} }
return true; return true;
@ -412,7 +412,7 @@ class User {
* @returns string the effective display name * @returns string the effective display name
*/ */
public function composeAndStoreDisplayName($displayName, $displayName2 = '') { public function composeAndStoreDisplayName($displayName, $displayName2 = '') {
$displayName2 = strval($displayName2); $displayName2 = (string)$displayName2;
if($displayName2 !== '') { if($displayName2 !== '') {
$displayName .= ' (' . $displayName2 . ')'; $displayName .= ' (' . $displayName2 . ')';
} }
@ -452,20 +452,20 @@ class User {
if($this->wasRefreshed('email')) { if($this->wasRefreshed('email')) {
return; return;
} }
$email = strval($valueFromLDAP); $email = (string)$valueFromLDAP;
if(is_null($valueFromLDAP)) { if(is_null($valueFromLDAP)) {
$emailAttribute = $this->connection->ldapEmailAttribute; $emailAttribute = $this->connection->ldapEmailAttribute;
if ($emailAttribute !== '') { if ($emailAttribute !== '') {
$aEmail = $this->access->readAttribute($this->dn, $emailAttribute); $aEmail = $this->access->readAttribute($this->dn, $emailAttribute);
if(is_array($aEmail) && (count($aEmail) > 0)) { if(is_array($aEmail) && (count($aEmail) > 0)) {
$email = strval($aEmail[0]); $email = (string)$aEmail[0];
} }
} }
} }
if ($email !== '') { if ($email !== '') {
$user = $this->userManager->get($this->uid); $user = $this->userManager->get($this->uid);
if (!is_null($user)) { if (!is_null($user)) {
$currentEmail = strval($user->getEMailAddress()); $currentEmail = (string)$user->getEMailAddress();
if ($currentEmail !== $email) { if ($currentEmail !== $email) {
$user->setEMailAddress($email); $user->setEMailAddress($email);
} }
@ -610,7 +610,7 @@ class User {
*/ */
public function handlePasswordExpiry($params) { public function handlePasswordExpiry($params) {
$ppolicyDN = $this->connection->ldapDefaultPPolicyDN; $ppolicyDN = $this->connection->ldapDefaultPPolicyDN;
if (empty($ppolicyDN) || (intval($this->connection->turnOnPasswordChange) !== 1)) { if (empty($ppolicyDN) || ((int)$this->connection->turnOnPasswordChange !== 1)) {
return;//password expiry handling disabled return;//password expiry handling disabled
} }
$uid = $params['uid']; $uid = $params['uid'];
@ -646,7 +646,7 @@ class User {
if($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login? if($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login?
if($pwdGraceAuthNLimit if($pwdGraceAuthNLimit
&& (count($pwdGraceAuthNLimit) > 0) && (count($pwdGraceAuthNLimit) > 0)
&&($pwdGraceUseTimeCount < intval($pwdGraceAuthNLimit[0]))) { //at least one more grace login available? &&($pwdGraceUseTimeCount < (int)$pwdGraceAuthNLimit[0])) { //at least one more grace login available?
$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true'); $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute( header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid))); 'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
@ -667,8 +667,8 @@ class User {
if($pwdChangedTime && (count($pwdChangedTime) > 0)) { if($pwdChangedTime && (count($pwdChangedTime) > 0)) {
if($pwdMaxAge && (count($pwdMaxAge) > 0) if($pwdMaxAge && (count($pwdMaxAge) > 0)
&& $pwdExpireWarning && (count($pwdExpireWarning) > 0)) { && $pwdExpireWarning && (count($pwdExpireWarning) > 0)) {
$pwdMaxAgeInt = intval($pwdMaxAge[0]); $pwdMaxAgeInt = (int)$pwdMaxAge[0];
$pwdExpireWarningInt = intval($pwdExpireWarning[0]); $pwdExpireWarningInt = (int)$pwdExpireWarning[0];
if($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){ if($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){
$pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]); $pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]);
$pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S')); $pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S'));

View File

@ -232,7 +232,7 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
$ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN; $ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
$turnOnPasswordChange = $this->access->connection->turnOnPasswordChange; $turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) { if (!empty($ldapDefaultPPolicyDN) && ((int)$turnOnPasswordChange === 1)) {
//remove last password expiry warning if any //remove last password expiry warning if any
$notification = $this->notificationManager->createNotification(); $notification = $this->notificationManager->createNotification();
$notification->setApp('user_ldap') $notification->setApp('user_ldap')
@ -387,7 +387,7 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
} }
$marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
if(intval($marked) === 0) { if((int)$marked === 0) {
\OC::$server->getLogger()->notice( \OC::$server->getLogger()->notice(
'User '.$uid . ' is not marked as deleted, not cleaning up.', 'User '.$uid . ' is not marked as deleted, not cleaning up.',
array('app' => 'user_ldap')); array('app' => 'user_ldap'));
@ -549,7 +549,7 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
| Backend::GET_DISPLAYNAME | Backend::GET_DISPLAYNAME
| Backend::PROVIDE_AVATAR | Backend::PROVIDE_AVATAR
| Backend::COUNT_USERS | Backend::COUNT_USERS
| ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0) | (((int)$this->access->connection->turnOnPasswordChange === 1)?(Backend::SET_PASSWORD):0)
| $this->userPluginManager->getImplementedActions()) | $this->userPluginManager->getImplementedActions())
& $actions); & $actions);
} }

View File

@ -690,7 +690,7 @@ class Wizard extends LDAPUtility {
if ($settingsFound === true) { if ($settingsFound === true) {
$config = array( $config = array(
'ldapPort' => $p, 'ldapPort' => $p,
'ldapTLS' => intval($t) 'ldapTLS' => (int)$t
); );
$this->configuration->setConfiguration($config); $this->configuration->setConfiguration($config);
\OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, \OCP\Util::DEBUG);
@ -1069,7 +1069,7 @@ class Wizard extends LDAPUtility {
if($login === true) { if($login === true) {
$this->ldap->unbind($cr); $this->ldap->unbind($cr);
\OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '. $port . ' TLS ' . intval($tls), \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '. $port . ' TLS ' . (int)$tls, \OCP\Util::DEBUG);
return true; return true;
} }
@ -1326,7 +1326,7 @@ class Wizard extends LDAPUtility {
//636 ← LDAPS / SSL //636 ← LDAPS / SSL
//7xxx ← UCS. need to be checked first, because both ports may be open //7xxx ← UCS. need to be checked first, because both ports may be open
$host = $this->configuration->ldapHost; $host = $this->configuration->ldapHost;
$port = intval($this->configuration->ldapPort); $port = (int)$this->configuration->ldapPort;
$portSettings = array(); $portSettings = array();
//In case the port is already provided, we will check this first //In case the port is already provided, we will check this first

View File

@ -327,7 +327,7 @@ class Database extends \OC\Group\Backend {
$result = $stmt->execute($parameters); $result = $stmt->execute($parameters);
$count = $result->fetchOne(); $count = $result->fetchOne();
if($count !== false) { if($count !== false) {
$count = intval($count); $count = (int)$count;
} }
return $count; return $count;
} }