Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactors "strpos" calls in /apps/user_ldap #38608

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/user_ldap/lib/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ public function extractAttributeValuesFromResult($result, $attribute) {
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],
Expand Down Expand Up @@ -405,7 +405,7 @@ public function getDomainDNFromDN($dn) {
$domainParts = [];
$dcFound = false;
foreach ($allParts as $part) {
if (!$dcFound && strpos($part, 'dc=') === 0) {
if (!$dcFound && str_starts_with($part, 'dc=')) {
$dcFound = true;
}
if ($dcFound) {
Expand Down Expand Up @@ -1530,7 +1530,7 @@ private function getAdvancedFilterPartForSearch(string $search, $searchAttribute
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) {
Expand Down
6 changes: 3 additions & 3 deletions apps/user_ldap/lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function getConfiguration(): array {
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;
Expand All @@ -191,7 +191,7 @@ public function setConfiguration(array $config, array &$applied = null): void {
break;
case 'homeFolderNamingRule':
$trimmedVal = trim($val);
if ($trimmedVal !== '' && strpos($val, 'attr:') === false) {
if ($trimmedVal !== '' && !str_contains($val, 'attr:')) {
$val = 'attr:'.$trimmedVal;
}
break;
Expand Down Expand Up @@ -584,7 +584,7 @@ public function getAvatarAttributes(): array {
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;
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public function getConfiguration() {
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] = '';
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Jobs/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function updateInterval() {
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) {
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function search($link, $baseDN, $filter, $attr, $attrsOnly = 0, $limit =
}

$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);
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Migration/UUIDFixInsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function run(IOutput $output) {
$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;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function getAttributes($minimal = false) {
];

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

Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/User/OfflineUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ protected function determineShares() {
$shareConstants = $shareInterface->getConstants();

foreach ($shareConstants as $constantName => $constantValue) {
if (strpos($constantName, 'TYPE_') !== 0
if (!str_starts_with($constantName, 'TYPE_')
|| $constantValue === IShare::TYPE_USERGROUP
) {
continue;
Expand Down
6 changes: 3 additions & 3 deletions apps/user_ldap/lib/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function processAttributes($ldapEntry) {
}

//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(
Expand Down Expand Up @@ -391,7 +391,7 @@ public function getHomePath($valueFromLDAP = null) {
$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);
Expand Down Expand Up @@ -630,7 +630,7 @@ private function verifyQuotaValue(string $quotaValue) {

/**
* 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 {
Expand Down
6 changes: 3 additions & 3 deletions apps/user_ldap/tests/Group_LDAPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public function testCountWithSearchString() {
//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'];
Expand Down Expand Up @@ -1009,7 +1009,7 @@ public function testGetGroupsByMember(bool $nestedGroups) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function run() {
$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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function case1() {
$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)');
}

/**
Expand All @@ -88,7 +88,7 @@ protected function case2() {
$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)');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/tests/User_LDAPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ public function avatarDataProvider() {

/** @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())
Expand Down