Skip to content

Commit

Permalink
Merge pull request #20511 from nextcloud/fix/cs-fixer-ldap
Browse files Browse the repository at this point in the history
PHP-CS-Fixer green
  • Loading branch information
rullzer committed Apr 16, 2020
2 parents 79cf13e + d9990b0 commit 8971403
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 32 deletions.
28 changes: 14 additions & 14 deletions apps/user_ldap/lib/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Access extends LDAPUtility {
protected $pagedSearchedSuccessful;

/**
protected $cookies = [];
* protected $cookies = [];
* @var AbstractMapping $userMapper
*/
protected $userMapper;
Expand Down Expand Up @@ -1174,7 +1174,7 @@ private function executeSearch(
$sr = $this->invokeLDAPMethod('search', $cr, $base, $filter, $attr);
// cannot use $cr anymore, might have changed in the previous call!
$error = $this->ldap->errno($this->connection->getConnectionResource());
if(!$this->ldap->isResource($sr) || $error !== 0) {
if (!$this->ldap->isResource($sr) || $error !== 0) {
\OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), ILogger::ERROR);
return false;
}
Expand Down Expand Up @@ -1204,7 +1204,7 @@ private function processPagedSearchStatus(
$cookie = null;
if ($pagedSearchOK) {
$cr = $this->connection->getConnectionResource();
if($this->ldap->controlPagedResultResponse($cr, $sr, $cookie)) {
if ($this->ldap->controlPagedResultResponse($cr, $sr, $cookie)) {
$this->lastCookie = $cookie;
}

Expand All @@ -1215,7 +1215,7 @@ private function processPagedSearchStatus(
// if count is bigger, then the server does not support
// paged search. Instead, he did a normal search. We set a
// flag here, so the callee knows how to deal with it.
if($foundItems <= $limit) {
if ($foundItems <= $limit) {
$this->pagedSearchedSuccessful = true;
}
} else {
Expand Down Expand Up @@ -1261,8 +1261,8 @@ private function count(
'filter' => $filter
]);

if(!is_null($attr) && !is_array($attr)) {
$attr = array(mb_strtolower($attr, 'UTF-8'));
if (!is_null($attr) && !is_array($attr)) {
$attr = [mb_strtolower($attr, 'UTF-8')];
}

$limitPerPage = (int)$this->connection->ldapPagingSize;
Expand All @@ -1274,10 +1274,10 @@ private function count(
$count = null;
$this->connection->getConnectionResource();

foreach($bases as $base) {
foreach ($bases as $base) {
do {
$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
if ($search === false) {
if ($search === false) {
return $counter > 0 ? $counter : false;
}
list($sr, $pagedSearchOK) = $search;
Expand All @@ -1295,7 +1295,7 @@ private function count(
* Continue now depends on $hasMorePages value
*/
$continue = $pagedSearchOK && $hasMorePages;
} while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
} while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
}

return $counter;
Expand Down Expand Up @@ -1328,7 +1328,7 @@ public function search(
$limitPerPage = $limit;
}

if(!is_null($attr) && !is_array($attr)) {
if (!is_null($attr) && !is_array($attr)) {
$attr = [mb_strtolower($attr, 'UTF-8')];
}

Expand Down Expand Up @@ -1671,7 +1671,7 @@ public function getUserDnByUuid($uuid) {
break;
}
}
if(!isset($hasFound) || !$hasFound) {
if (!isset($hasFound) || !$hasFound) {
throw new \Exception('Cannot determine UUID attribute');
}
} else {
Expand Down Expand Up @@ -1962,7 +1962,7 @@ public function isDNPartOfBase($dn, $bases) {
* @throws ServerNotAvailableException
*/
private function abandonPagedSearch() {
if($this->lastCookie === '') {
if ($this->lastCookie === '') {
return;
}
$cr = $this->connection->getConnectionResource();
Expand Down Expand Up @@ -2033,14 +2033,14 @@ private function initPagedSearch(
]
);
//get the cookie from the search for the previous search, required by LDAP
if(empty($this->lastCookie) && $this->lastCookie !== "0" && ($offset > 0)) {
if (empty($this->lastCookie) && $this->lastCookie !== "0" && ($offset > 0)) {
// no cookie known from a potential previous search. We need
// to start from 0 to come to the desired page. cookie value
// of '0' is valid, because 389ds
$reOffset = ($offset - $limit) < 0 ? 0 : $offset - $limit;
$this->search($filter, $base, $attr, $limit, $reOffset, true);
}
if($this->lastCookie !== '' && $offset === 0) {
if ($this->lastCookie !== '' && $offset === 0) {
//since offset = 0, this is a new search. We abandon other searches that might be ongoing.
$this->abandonPagedSearch();
}
Expand Down
4 changes: 2 additions & 2 deletions apps/user_ldap/lib/LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LDAP implements ILDAPWrapper {
protected $pagedResultsAdapter;

public function __construct() {
if(version_compare(PHP_VERSION, '7.3', '<') === true) {
if (version_compare(PHP_VERSION, '7.3', '<') === true) {
$this->pagedResultsAdapter = new Php54();
} else {
$this->pagedResultsAdapter = new Php73();
Expand Down Expand Up @@ -103,7 +103,7 @@ public function controlPagedResultResponse($link, $result, &$cookie): bool {
public function controlPagedResult($link, $pageSize, $isCritical) {
$fn = $this->pagedResultsAdapter->getRequestCallFunc();
$this->pagedResultsAdapter->setRequestParameters($link, $pageSize, $isCritical);
if($fn === null) {
if ($fn === null) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/PagedResults/IAdapter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
Expand Down Expand Up @@ -126,5 +127,4 @@ public function getReadArgs($link): array;
* @return string
*/
public function getCookie($link): string;

}
9 changes: 5 additions & 4 deletions apps/user_ldap/lib/PagedResults/Php54.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
Expand Down Expand Up @@ -48,7 +49,7 @@ public function responseCall($link): bool {

public function getResponseCallArgs(array $originalArgs): array {
$linkId = $this->getLinkId($originalArgs[0]);
if(!isset($this->linkData[$linkId])) {
if (!isset($this->linkData[$linkId])) {
throw new \LogicException('There should be a request before the response');
}
$this->linkData[$linkId]['responseArgs'] = &$originalArgs;
Expand All @@ -68,7 +69,7 @@ public function getRequestCallFunc(): ?string {
public function setRequestParameters($link, int $pageSize, bool $isCritical): void {
$linkId = $this->getLinkId($link);

if($pageSize === 0 || !isset($this->linkData[$linkId]['cookie'])) {
if ($pageSize === 0 || !isset($this->linkData[$linkId]['cookie'])) {
// abandons a previous paged search
$this->linkData[$linkId]['cookie'] = '';
}
Expand Down Expand Up @@ -100,7 +101,7 @@ public function setSearchArgs(
int $limit
): void {
$linkId = $this->getLinkId($link);
if(!isset($this->linkData[$linkId])) {
if (!isset($this->linkData[$linkId])) {
$this->linkData[$linkId] = [];
}
$this->linkData[$linkId]['searchArgs'] = func_get_args();
Expand All @@ -113,7 +114,7 @@ public function getSearchArgs($link): array {

public function setReadArgs($link, string $baseDN, string $filter, array $attr): void {
$linkId = $this->getLinkId($link);
if(!isset($this->linkData[$linkId])) {
if (!isset($this->linkData[$linkId])) {
$this->linkData[$linkId] = [];
}
$this->linkData[$linkId]['readArgs'] = func_get_args();
Expand Down
11 changes: 6 additions & 5 deletions apps/user_ldap/lib/PagedResults/Php73.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
Expand Down Expand Up @@ -50,7 +51,7 @@ public function getResponseCallArgs(array $originalArgs): array {
$link = array_shift($originalArgs);
$linkId = $this->getLinkId($link);

if(!isset($this->linkData[$linkId])) {
if (!isset($this->linkData[$linkId])) {
$this->linkData[$linkId] = [];
}

Expand Down Expand Up @@ -85,7 +86,7 @@ public function getRequestCallFunc(): ?string {

public function setRequestParameters($link, int $pageSize, bool $isCritical): void {
$linkId = $this->getLinkId($link);
if(!isset($this->linkData[$linkId])) {
if (!isset($this->linkData[$linkId])) {
$this->linkData[$linkId] = [];
}
$this->linkData[$linkId]['requestArgs'] = [];
Expand All @@ -112,7 +113,7 @@ public function setSearchArgs(
int $limit
): void {
$linkId = $this->getLinkId($link);
if(!isset($this->linkData[$linkId])) {
if (!isset($this->linkData[$linkId])) {
$this->linkData[$linkId] = [];
}

Expand All @@ -127,7 +128,7 @@ public function getSearchArgs($link): array {

public function setReadArgs($link, string $baseDN, string $filter, array $attr): void {
$linkId = $this->getLinkId($link);
if(!isset($this->linkData[$linkId])) {
if (!isset($this->linkData[$linkId])) {
$this->linkData[$linkId] = [];
}

Expand All @@ -143,7 +144,7 @@ public function getReadArgs($link): array {
}

protected function preparePagesResultsArgs(int $linkId, string $methodKey): void {
if(!isset($this->linkData[$linkId]['requestArgs'])) {
if (!isset($this->linkData[$linkId]['requestArgs'])) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions apps/user_ldap/lib/PagedResults/TLinkId.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
Expand All @@ -24,12 +25,11 @@

namespace OCA\User_LDAP\PagedResults;


trait TLinkId {
public function getLinkId($link) {
if(is_resource($link)) {
if (is_resource($link)) {
return (int)$link;
} else if(is_array($link) && isset($link[0]) && is_resource($link[0])) {
} elseif (is_array($link) && isset($link[0]) && is_resource($link[0])) {
return (int)$link[0];
}
throw new \RuntimeException('No resource provided');
Expand Down
6 changes: 3 additions & 3 deletions apps/user_ldap/tests/User/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1197,15 +1197,15 @@ public function testHandlePasswordExpiryWarningDefaultPolicy() {
$this->access->expects($this->any())
->method('search')
->willReturnCallback(function ($filter, $base) {
if($base === $this->dn) {
if ($base === $this->dn) {
return [
[
'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'],
'pwdgraceusetime' => [],
],
];
}
if($base === 'cn=default,ou=policies,dc=foo,dc=bar') {
if ($base === 'cn=default,ou=policies,dc=foo,dc=bar') {
return [
[
'pwdmaxage' => ['2592000'],
Expand Down Expand Up @@ -1260,7 +1260,7 @@ public function testHandlePasswordExpiryWarningCustomPolicy() {
$this->access->expects($this->any())
->method('search')
->willReturnCallback(function ($filter, $base) {
if($base === $this->dn) {
if ($base === $this->dn) {
return [
[
'pwdpolicysubentry' => ['cn=custom,ou=policies,dc=foo,dc=bar'],
Expand Down
1 change: 1 addition & 0 deletions lib/public/Http/Client/LocalServerException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
Expand Down

0 comments on commit 8971403

Please sign in to comment.