aboutsummaryrefslogtreecommitdiffstats
path: root/apps
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
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')
-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
-rw-r--r--apps/user_ldap/tests/Group_LDAPTest.php6
-rw-r--r--apps/user_ldap/tests/Integration/AbstractIntegrationTest.php2
-rw-r--r--apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php4
-rw-r--r--apps/user_ldap/tests/User_LDAPTest.php2
13 files changed, 23 insertions, 23 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 {
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php
index edcb4be8819..2f7c0b04cdc 100644
--- a/apps/user_ldap/tests/Group_LDAPTest.php
+++ b/apps/user_ldap/tests/Group_LDAPTest.php
@@ -157,8 +157,8 @@ class Group_LDAPTest extends TestCase {
//to analyze the "dn". All other times we just need to return
//something that is neither null or false, but once an array
//with the users in the group – so we do so all other times for
- //simplicicity.
- if (strpos($name, 'u') === 0) {
+ //simplicity.
+ if (str_starts_with($name, 'u')) {
return strpos($name, '3');
}
return ['u11', 'u22', 'u33', 'u34'];
@@ -1009,7 +1009,7 @@ class Group_LDAPTest extends TestCase {
if (!$nestedGroups) {
// When nested groups are enabled, groups cannot be filtered early as it would
// exclude intermediate groups. But we can, and should, when working with flat groups.
- $this->assertTrue(strpos($filter, $groupFilter) !== false);
+ $this->assertTrue(str_contains($filter, $groupFilter));
}
[$memberFilter] = explode('&', $filter);
if ($memberFilter === 'member='.$dn) {
diff --git a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php
index e22678620c1..58475a2bea9 100644
--- a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php
+++ b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php
@@ -155,7 +155,7 @@ abstract class AbstractIntegrationTest {
$methods = get_class_methods($this);
$atLeastOneCaseRan = false;
foreach ($methods as $method) {
- if (strpos($method, 'case') === 0) {
+ if (str_starts_with($method, 'case')) {
print("running $method " . PHP_EOL);
try {
if (!$this->$method()) {
diff --git a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php
index 7353c5bef30..993ceec5abb 100644
--- a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php
+++ b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php
@@ -71,7 +71,7 @@ class IntegrationTestUserDisplayName extends AbstractIntegrationTest {
$this->prepareUser($dn, $username);
$displayName = \OC::$server->getUserManager()->get($username)->getDisplayName();
- return strpos($displayName, '(Alice@example.com)') !== false;
+ return str_contains($displayName, '(Alice@example.com)');
}
/**
@@ -88,7 +88,7 @@ class IntegrationTestUserDisplayName extends AbstractIntegrationTest {
$this->prepareUser($dn, $username);
$displayName = \OC::$server->getUserManager()->get($username)->getDisplayName();
- return strpos($displayName, '(Boris@example.com)') === false;
+ return !str_contains($displayName, '(Boris@example.com)');
}
/**
diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php
index b00c93e79f0..e837471bab0 100644
--- a/apps/user_ldap/tests/User_LDAPTest.php
+++ b/apps/user_ldap/tests/User_LDAPTest.php
@@ -1312,7 +1312,7 @@ class User_LDAPTest extends TestCase {
/** @dataProvider avatarDataProvider */
public function testCanChangeAvatar($imageData, $expected) {
- $isValidImage = strpos((string)$imageData, 'valid') === 0;
+ $isValidImage = str_starts_with((string)$imageData, 'valid');
$user = $this->createMock(User::class);
$user->expects($this->once())