Skip to content

Commit 6a8c25f

Browse files
authored
Merge pull request #38608 from fsamapoor/replace_strcalls_in_user_ldap_app
Refactors "strpos" calls in /apps/user_ldap
2 parents e464446 + b0938b9 commit 6a8c25f

File tree

13 files changed

+23
-23
lines changed

13 files changed

+23
-23
lines changed

apps/user_ldap/lib/Access.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ public function extractAttributeValuesFromResult($result, $attribute) {
313313
public function extractRangeData($result, $attribute) {
314314
$keys = array_keys($result);
315315
foreach ($keys as $key) {
316-
if ($key !== $attribute && strpos((string)$key, $attribute) === 0) {
316+
if ($key !== $attribute && str_starts_with((string)$key, $attribute)) {
317317
$queryData = explode(';', (string)$key);
318-
if (strpos($queryData[1], 'range=') === 0) {
318+
if (str_starts_with($queryData[1], 'range=')) {
319319
$high = substr($queryData[1], 1 + strpos($queryData[1], '-'));
320320
$data = [
321321
'values' => $result[$key],
@@ -405,7 +405,7 @@ public function getDomainDNFromDN($dn) {
405405
$domainParts = [];
406406
$dcFound = false;
407407
foreach ($allParts as $part) {
408-
if (!$dcFound && strpos($part, 'dc=') === 0) {
408+
if (!$dcFound && str_starts_with($part, 'dc=')) {
409409
$dcFound = true;
410410
}
411411
if ($dcFound) {
@@ -1530,7 +1530,7 @@ private function getAdvancedFilterPartForSearch(string $search, $searchAttribute
15301530
private function getFilterPartForSearch(string $search, $searchAttributes, string $fallbackAttribute): string {
15311531
$filter = [];
15321532
$haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0);
1533-
if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1533+
if ($haveMultiSearchAttributes && str_contains(trim($search), ' ')) {
15341534
try {
15351535
return $this->getAdvancedFilterPartForSearch($search, $searchAttributes);
15361536
} catch (DomainException $e) {

apps/user_ldap/lib/Configuration.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function getConfiguration(): array {
176176
public function setConfiguration(array $config, array &$applied = null): void {
177177
$cta = $this->getConfigTranslationArray();
178178
foreach ($config as $inputKey => $val) {
179-
if (strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) {
179+
if (str_contains($inputKey, '_') && array_key_exists($inputKey, $cta)) {
180180
$key = $cta[$inputKey];
181181
} elseif (array_key_exists($inputKey, $this->config)) {
182182
$key = $inputKey;
@@ -191,7 +191,7 @@ public function setConfiguration(array $config, array &$applied = null): void {
191191
break;
192192
case 'homeFolderNamingRule':
193193
$trimmedVal = trim($val);
194-
if ($trimmedVal !== '' && strpos($val, 'attr:') === false) {
194+
if ($trimmedVal !== '' && !str_contains($val, 'attr:')) {
195195
$val = 'attr:'.$trimmedVal;
196196
}
197197
break;
@@ -584,7 +584,7 @@ public function getAvatarAttributes(): array {
584584
if ($value === self::AVATAR_PREFIX_NONE) {
585585
return [];
586586
}
587-
if (strpos($value, self::AVATAR_PREFIX_DATA_ATTRIBUTE) === 0) {
587+
if (str_starts_with($value, self::AVATAR_PREFIX_DATA_ATTRIBUTE)) {
588588
$attribute = trim(substr($value, strlen(self::AVATAR_PREFIX_DATA_ATTRIBUTE)));
589589
if ($attribute === '') {
590590
return $defaultAttributes;

apps/user_ldap/lib/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public function getConfiguration() {
377377
foreach ($cta as $dbkey => $configkey) {
378378
switch ($configkey) {
379379
case 'homeFolderNamingRule':
380-
if (strpos($config[$configkey], 'attr:') === 0) {
380+
if (str_starts_with($config[$configkey], 'attr:')) {
381381
$result[$dbkey] = substr($config[$configkey], 5);
382382
} else {
383383
$result[$dbkey] = '';

apps/user_ldap/lib/Jobs/Sync.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function updateInterval() {
103103
protected function getMinPagingSize() {
104104
$configKeys = $this->config->getAppKeys('user_ldap');
105105
$configKeys = array_filter($configKeys, function ($key) {
106-
return strpos($key, 'ldap_paging_size') !== false;
106+
return str_contains($key, 'ldap_paging_size');
107107
});
108108
$minPagingSize = null;
109109
foreach ($configKeys as $configKey) {

apps/user_ldap/lib/LDAP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function search($link, $baseDN, $filter, $attr, $attrsOnly = 0, $limit =
204204
}
205205

206206
$oldHandler = set_error_handler(function ($no, $message, $file, $line) use (&$oldHandler) {
207-
if (strpos($message, 'Partial search results returned: Sizelimit exceeded') !== false) {
207+
if (str_contains($message, 'Partial search results returned: Sizelimit exceeded')) {
208208
return true;
209209
}
210210
$oldHandler($no, $message, $file, $line);

apps/user_ldap/lib/Migration/UUIDFixInsert.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function run(IOutput $output) {
9090
$this->jobList->add($jobClass, ['records' => $records]);
9191
$offset += $batchSize;
9292
} catch (\InvalidArgumentException $e) {
93-
if (strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) {
93+
if (str_contains($e->getMessage(), 'Background job arguments can\'t exceed 4000')) {
9494
$batchSize = (int)floor(count($records) * 0.8);
9595
$retry = true;
9696
}

apps/user_ldap/lib/User/Manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function getAttributes($minimal = false) {
165165
];
166166

167167
$homeRule = (string)$this->access->getConnection()->homeFolderNamingRule;
168-
if (strpos($homeRule, 'attr:') === 0) {
168+
if (str_starts_with($homeRule, 'attr:')) {
169169
$attributes[] = substr($homeRule, strlen('attr:'));
170170
}
171171

apps/user_ldap/lib/User/OfflineUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ protected function determineShares() {
253253
$shareConstants = $shareInterface->getConstants();
254254

255255
foreach ($shareConstants as $constantName => $constantValue) {
256-
if (strpos($constantName, 'TYPE_') !== 0
256+
if (!str_starts_with($constantName, 'TYPE_')
257257
|| $constantValue === IShare::TYPE_USERGROUP
258258
) {
259259
continue;

apps/user_ldap/lib/User/User.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function processAttributes($ldapEntry) {
214214
}
215215

216216
//homePath
217-
if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
217+
if (str_starts_with($this->connection->homeFolderNamingRule, 'attr:')) {
218218
$attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:')));
219219
if (isset($ldapEntry[$attr])) {
220220
$this->access->cacheUserHome(
@@ -391,7 +391,7 @@ public function getHomePath($valueFromLDAP = null) {
391391
$attr = null;
392392

393393
if (is_null($valueFromLDAP)
394-
&& strpos($this->access->connection->homeFolderNamingRule, 'attr:') === 0
394+
&& str_starts_with($this->access->connection->homeFolderNamingRule, 'attr:')
395395
&& $this->access->connection->homeFolderNamingRule !== 'attr:') {
396396
$attr = substr($this->access->connection->homeFolderNamingRule, strlen('attr:'));
397397
$homedir = $this->access->readAttribute($this->access->username2dn($this->getUsername()), $attr);
@@ -630,7 +630,7 @@ private function verifyQuotaValue(string $quotaValue) {
630630

631631
/**
632632
* takes values from LDAP and stores it as Nextcloud user profile value
633-
*
633+
*
634634
* @param array $profileValues associative array of property keys and values from LDAP
635635
*/
636636
private function updateProfile(array $profileValues): void {

apps/user_ldap/tests/Group_LDAPTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ public function testCountWithSearchString() {
157157
//to analyze the "dn". All other times we just need to return
158158
//something that is neither null or false, but once an array
159159
//with the users in the group – so we do so all other times for
160-
//simplicicity.
161-
if (strpos($name, 'u') === 0) {
160+
//simplicity.
161+
if (str_starts_with($name, 'u')) {
162162
return strpos($name, '3');
163163
}
164164
return ['u11', 'u22', 'u33', 'u34'];
@@ -1009,7 +1009,7 @@ public function testGetGroupsByMember(bool $nestedGroups) {
10091009
if (!$nestedGroups) {
10101010
// When nested groups are enabled, groups cannot be filtered early as it would
10111011
// exclude intermediate groups. But we can, and should, when working with flat groups.
1012-
$this->assertTrue(strpos($filter, $groupFilter) !== false);
1012+
$this->assertTrue(str_contains($filter, $groupFilter));
10131013
}
10141014
[$memberFilter] = explode('&', $filter);
10151015
if ($memberFilter === 'member='.$dn) {

0 commit comments

Comments
 (0)