aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib
diff options
context:
space:
mode:
authorFaraz Samapoor <f.samapoor@gmail.com>2023-06-02 15:26:55 +0330
committerFaraz Samapoor <f.samapoor@gmail.com>2023-06-02 15:26:55 +0330
commitb0938b90839503fed01924d4a7874482caf2fc80 (patch)
tree6704ccb6066e29813fd164111e46b896036d65d5 /apps/user_ldap/lib
parent09c5f997c6d185d8b23b37a996e7a1130a426d75 (diff)
downloadnextcloud-server-b0938b90839503fed01924d4a7874482caf2fc80.tar.gz
nextcloud-server-b0938b90839503fed01924d4a7874482caf2fc80.zip
Refactors "strpos" calls in /apps/user_ldap to improve code readability.
Signed-off-by: Faraz Samapoor <f.samapoor@gmail.com>
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r--apps/user_ldap/lib/Access.php8
-rw-r--r--apps/user_ldap/lib/Configuration.php6
-rw-r--r--apps/user_ldap/lib/Connection.php2
-rw-r--r--apps/user_ldap/lib/Jobs/Sync.php2
-rw-r--r--apps/user_ldap/lib/LDAP.php2
-rw-r--r--apps/user_ldap/lib/Migration/UUIDFixInsert.php2
-rw-r--r--apps/user_ldap/lib/User/Manager.php2
-rw-r--r--apps/user_ldap/lib/User/OfflineUser.php2
-rw-r--r--apps/user_ldap/lib/User/User.php6
9 files changed, 16 insertions, 16 deletions
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php
index 3f120caefe6..3edeabda747 100644
--- a/apps/user_ldap/lib/Access.php
+++ b/apps/user_ldap/lib/Access.php
@@ -313,9 +313,9 @@ class Access extends LDAPUtility {
public function extractRangeData($result, $attribute) {
$keys = array_keys($result);
foreach ($keys as $key) {
- if ($key !== $attribute && strpos((string)$key, $attribute) === 0) {
+ if ($key !== $attribute && str_starts_with((string)$key, $attribute)) {
$queryData = explode(';', (string)$key);
- if (strpos($queryData[1], 'range=') === 0) {
+ if (str_starts_with($queryData[1], 'range=')) {
$high = substr($queryData[1], 1 + strpos($queryData[1], '-'));
$data = [
'values' => $result[$key],
@@ -405,7 +405,7 @@ class Access extends LDAPUtility {
$domainParts = [];
$dcFound = false;
foreach ($allParts as $part) {
- if (!$dcFound && strpos($part, 'dc=') === 0) {
+ if (!$dcFound && str_starts_with($part, 'dc=')) {
$dcFound = true;
}
if ($dcFound) {
@@ -1530,7 +1530,7 @@ class Access extends LDAPUtility {
private function getFilterPartForSearch(string $search, $searchAttributes, string $fallbackAttribute): string {
$filter = [];
$haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0);
- if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
+ if ($haveMultiSearchAttributes && str_contains(trim($search), ' ')) {
try {
return $this->getAdvancedFilterPartForSearch($search, $searchAttributes);
} catch (DomainException $e) {
diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php
index ef64f75a9ef..5a0fcc79ab8 100644
--- a/apps/user_ldap/lib/Configuration.php
+++ b/apps/user_ldap/lib/Configuration.php
@@ -176,7 +176,7 @@ class Configuration {
public function setConfiguration(array $config, array &$applied = null): void {
$cta = $this->getConfigTranslationArray();
foreach ($config as $inputKey => $val) {
- if (strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) {
+ if (str_contains($inputKey, '_') && array_key_exists($inputKey, $cta)) {
$key = $cta[$inputKey];
} elseif (array_key_exists($inputKey, $this->config)) {
$key = $inputKey;
@@ -191,7 +191,7 @@ class Configuration {
break;
case 'homeFolderNamingRule':
$trimmedVal = trim($val);
- if ($trimmedVal !== '' && strpos($val, 'attr:') === false) {
+ if ($trimmedVal !== '' && !str_contains($val, 'attr:')) {
$val = 'attr:'.$trimmedVal;
}
break;
@@ -584,7 +584,7 @@ class Configuration {
if ($value === self::AVATAR_PREFIX_NONE) {
return [];
}
- if (strpos($value, self::AVATAR_PREFIX_DATA_ATTRIBUTE) === 0) {
+ if (str_starts_with($value, self::AVATAR_PREFIX_DATA_ATTRIBUTE)) {
$attribute = trim(substr($value, strlen(self::AVATAR_PREFIX_DATA_ATTRIBUTE)));
if ($attribute === '') {
return $defaultAttributes;
diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php
index d8d00dd4d27..861fb1e246b 100644
--- a/apps/user_ldap/lib/Connection.php
+++ b/apps/user_ldap/lib/Connection.php
@@ -377,7 +377,7 @@ class Connection extends LDAPUtility {
foreach ($cta as $dbkey => $configkey) {
switch ($configkey) {
case 'homeFolderNamingRule':
- if (strpos($config[$configkey], 'attr:') === 0) {
+ if (str_starts_with($config[$configkey], 'attr:')) {
$result[$dbkey] = substr($config[$configkey], 5);
} else {
$result[$dbkey] = '';
diff --git a/apps/user_ldap/lib/Jobs/Sync.php b/apps/user_ldap/lib/Jobs/Sync.php
index f8a9b14d02f..f715a5e9fb9 100644
--- a/apps/user_ldap/lib/Jobs/Sync.php
+++ b/apps/user_ldap/lib/Jobs/Sync.php
@@ -103,7 +103,7 @@ class Sync extends TimedJob {
protected function getMinPagingSize() {
$configKeys = $this->config->getAppKeys('user_ldap');
$configKeys = array_filter($configKeys, function ($key) {
- return strpos($key, 'ldap_paging_size') !== false;
+ return str_contains($key, 'ldap_paging_size');
});
$minPagingSize = null;
foreach ($configKeys as $configKey) {
diff --git a/apps/user_ldap/lib/LDAP.php b/apps/user_ldap/lib/LDAP.php
index 41a6f651f3b..6309a0c8f91 100644
--- a/apps/user_ldap/lib/LDAP.php
+++ b/apps/user_ldap/lib/LDAP.php
@@ -204,7 +204,7 @@ class LDAP implements ILDAPWrapper {
}
$oldHandler = set_error_handler(function ($no, $message, $file, $line) use (&$oldHandler) {
- if (strpos($message, 'Partial search results returned: Sizelimit exceeded') !== false) {
+ if (str_contains($message, 'Partial search results returned: Sizelimit exceeded')) {
return true;
}
$oldHandler($no, $message, $file, $line);
diff --git a/apps/user_ldap/lib/Migration/UUIDFixInsert.php b/apps/user_ldap/lib/Migration/UUIDFixInsert.php
index a8e9d2829d7..68b33e1b95b 100644
--- a/apps/user_ldap/lib/Migration/UUIDFixInsert.php
+++ b/apps/user_ldap/lib/Migration/UUIDFixInsert.php
@@ -90,7 +90,7 @@ class UUIDFixInsert implements IRepairStep {
$this->jobList->add($jobClass, ['records' => $records]);
$offset += $batchSize;
} catch (\InvalidArgumentException $e) {
- if (strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) {
+ if (str_contains($e->getMessage(), 'Background job arguments can\'t exceed 4000')) {
$batchSize = (int)floor(count($records) * 0.8);
$retry = true;
}
diff --git a/apps/user_ldap/lib/User/Manager.php b/apps/user_ldap/lib/User/Manager.php
index 04c67a537b8..f904d829c08 100644
--- a/apps/user_ldap/lib/User/Manager.php
+++ b/apps/user_ldap/lib/User/Manager.php
@@ -165,7 +165,7 @@ class Manager {
];
$homeRule = (string)$this->access->getConnection()->homeFolderNamingRule;
- if (strpos($homeRule, 'attr:') === 0) {
+ if (str_starts_with($homeRule, 'attr:')) {
$attributes[] = substr($homeRule, strlen('attr:'));
}
diff --git a/apps/user_ldap/lib/User/OfflineUser.php b/apps/user_ldap/lib/User/OfflineUser.php
index 6801a21a1d2..e39c4b0bb99 100644
--- a/apps/user_ldap/lib/User/OfflineUser.php
+++ b/apps/user_ldap/lib/User/OfflineUser.php
@@ -253,7 +253,7 @@ class OfflineUser {
$shareConstants = $shareInterface->getConstants();
foreach ($shareConstants as $constantName => $constantValue) {
- if (strpos($constantName, 'TYPE_') !== 0
+ if (!str_starts_with($constantName, 'TYPE_')
|| $constantValue === IShare::TYPE_USERGROUP
) {
continue;
diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php
index f85e4206eff..dac8bf1cfbc 100644
--- a/apps/user_ldap/lib/User/User.php
+++ b/apps/user_ldap/lib/User/User.php
@@ -214,7 +214,7 @@ class User {
}
//homePath
- if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
+ if (str_starts_with($this->connection->homeFolderNamingRule, 'attr:')) {
$attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:')));
if (isset($ldapEntry[$attr])) {
$this->access->cacheUserHome(
@@ -391,7 +391,7 @@ class User {
$attr = null;
if (is_null($valueFromLDAP)
- && strpos($this->access->connection->homeFolderNamingRule, 'attr:') === 0
+ && str_starts_with($this->access->connection->homeFolderNamingRule, 'attr:')
&& $this->access->connection->homeFolderNamingRule !== 'attr:') {
$attr = substr($this->access->connection->homeFolderNamingRule, strlen('attr:'));
$homedir = $this->access->readAttribute($this->access->username2dn($this->getUsername()), $attr);
@@ -630,7 +630,7 @@ class User {
/**
* takes values from LDAP and stores it as Nextcloud user profile value
- *
+ *
* @param array $profileValues associative array of property keys and values from LDAP
*/
private function updateProfile(array $profileValues): void {