PHP-CS-Fixer green

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2020-04-16 09:25:17 +02:00
parent 1f2df2f6bc
commit d9990b09b8
No known key found for this signature in database
GPG Key ID: F941078878347C0C
8 changed files with 35 additions and 32 deletions

View File

@ -74,7 +74,7 @@ class Access extends LDAPUtility {
protected $pagedSearchedSuccessful; protected $pagedSearchedSuccessful;
/** /**
protected $cookies = []; * protected $cookies = [];
* @var AbstractMapping $userMapper * @var AbstractMapping $userMapper
*/ */
protected $userMapper; protected $userMapper;
@ -1174,7 +1174,7 @@ class Access extends LDAPUtility {
$sr = $this->invokeLDAPMethod('search', $cr, $base, $filter, $attr); $sr = $this->invokeLDAPMethod('search', $cr, $base, $filter, $attr);
// cannot use $cr anymore, might have changed in the previous call! // cannot use $cr anymore, might have changed in the previous call!
$error = $this->ldap->errno($this->connection->getConnectionResource()); $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); \OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), ILogger::ERROR);
return false; return false;
} }
@ -1204,7 +1204,7 @@ class Access extends LDAPUtility {
$cookie = null; $cookie = null;
if ($pagedSearchOK) { if ($pagedSearchOK) {
$cr = $this->connection->getConnectionResource(); $cr = $this->connection->getConnectionResource();
if($this->ldap->controlPagedResultResponse($cr, $sr, $cookie)) { if ($this->ldap->controlPagedResultResponse($cr, $sr, $cookie)) {
$this->lastCookie = $cookie; $this->lastCookie = $cookie;
} }
@ -1215,7 +1215,7 @@ class Access extends LDAPUtility {
// if count is bigger, then the server does not support // if count is bigger, then the server does not support
// paged search. Instead, he did a normal search. We set a // paged search. Instead, he did a normal search. We set a
// flag here, so the callee knows how to deal with it. // flag here, so the callee knows how to deal with it.
if($foundItems <= $limit) { if ($foundItems <= $limit) {
$this->pagedSearchedSuccessful = true; $this->pagedSearchedSuccessful = true;
} }
} else { } else {
@ -1261,8 +1261,8 @@ class Access extends LDAPUtility {
'filter' => $filter 'filter' => $filter
]); ]);
if(!is_null($attr) && !is_array($attr)) { if (!is_null($attr) && !is_array($attr)) {
$attr = array(mb_strtolower($attr, 'UTF-8')); $attr = [mb_strtolower($attr, 'UTF-8')];
} }
$limitPerPage = (int)$this->connection->ldapPagingSize; $limitPerPage = (int)$this->connection->ldapPagingSize;
@ -1274,10 +1274,10 @@ class Access extends LDAPUtility {
$count = null; $count = null;
$this->connection->getConnectionResource(); $this->connection->getConnectionResource();
foreach($bases as $base) { foreach ($bases as $base) {
do { do {
$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
if ($search === false) { if ($search === false) {
return $counter > 0 ? $counter : false; return $counter > 0 ? $counter : false;
} }
list($sr, $pagedSearchOK) = $search; list($sr, $pagedSearchOK) = $search;
@ -1295,7 +1295,7 @@ class Access extends LDAPUtility {
* Continue now depends on $hasMorePages value * Continue now depends on $hasMorePages value
*/ */
$continue = $pagedSearchOK && $hasMorePages; $continue = $pagedSearchOK && $hasMorePages;
} while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); } while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
} }
return $counter; return $counter;
@ -1328,7 +1328,7 @@ class Access extends LDAPUtility {
$limitPerPage = $limit; $limitPerPage = $limit;
} }
if(!is_null($attr) && !is_array($attr)) { if (!is_null($attr) && !is_array($attr)) {
$attr = [mb_strtolower($attr, 'UTF-8')]; $attr = [mb_strtolower($attr, 'UTF-8')];
} }
@ -1671,7 +1671,7 @@ class Access extends LDAPUtility {
break; break;
} }
} }
if(!isset($hasFound) || !$hasFound) { if (!isset($hasFound) || !$hasFound) {
throw new \Exception('Cannot determine UUID attribute'); throw new \Exception('Cannot determine UUID attribute');
} }
} else { } else {
@ -1962,7 +1962,7 @@ class Access extends LDAPUtility {
* @throws ServerNotAvailableException * @throws ServerNotAvailableException
*/ */
private function abandonPagedSearch() { private function abandonPagedSearch() {
if($this->lastCookie === '') { if ($this->lastCookie === '') {
return; return;
} }
$cr = $this->connection->getConnectionResource(); $cr = $this->connection->getConnectionResource();
@ -2033,14 +2033,14 @@ class Access extends LDAPUtility {
] ]
); );
//get the cookie from the search for the previous search, required by LDAP //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 // no cookie known from a potential previous search. We need
// to start from 0 to come to the desired page. cookie value // to start from 0 to come to the desired page. cookie value
// of '0' is valid, because 389ds // of '0' is valid, because 389ds
$reOffset = ($offset - $limit) < 0 ? 0 : $offset - $limit; $reOffset = ($offset - $limit) < 0 ? 0 : $offset - $limit;
$this->search($filter, $base, $attr, $limit, $reOffset, true); $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. //since offset = 0, this is a new search. We abandon other searches that might be ongoing.
$this->abandonPagedSearch(); $this->abandonPagedSearch();
} }

View File

@ -45,7 +45,7 @@ class LDAP implements ILDAPWrapper {
protected $pagedResultsAdapter; protected $pagedResultsAdapter;
public function __construct() { public function __construct() {
if(version_compare(PHP_VERSION, '7.3', '<') === true) { if (version_compare(PHP_VERSION, '7.3', '<') === true) {
$this->pagedResultsAdapter = new Php54(); $this->pagedResultsAdapter = new Php54();
} else { } else {
$this->pagedResultsAdapter = new Php73(); $this->pagedResultsAdapter = new Php73();
@ -103,7 +103,7 @@ class LDAP implements ILDAPWrapper {
public function controlPagedResult($link, $pageSize, $isCritical) { public function controlPagedResult($link, $pageSize, $isCritical) {
$fn = $this->pagedResultsAdapter->getRequestCallFunc(); $fn = $this->pagedResultsAdapter->getRequestCallFunc();
$this->pagedResultsAdapter->setRequestParameters($link, $pageSize, $isCritical); $this->pagedResultsAdapter->setRequestParameters($link, $pageSize, $isCritical);
if($fn === null) { if ($fn === null) {
return true; return true;
} }

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de> * @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
@ -126,5 +127,4 @@ interface IAdapter {
* @return string * @return string
*/ */
public function getCookie($link): string; public function getCookie($link): string;
} }

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de> * @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
@ -48,7 +49,7 @@ class Php54 implements IAdapter {
public function getResponseCallArgs(array $originalArgs): array { public function getResponseCallArgs(array $originalArgs): array {
$linkId = $this->getLinkId($originalArgs[0]); $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'); throw new \LogicException('There should be a request before the response');
} }
$this->linkData[$linkId]['responseArgs'] = &$originalArgs; $this->linkData[$linkId]['responseArgs'] = &$originalArgs;
@ -68,7 +69,7 @@ class Php54 implements IAdapter {
public function setRequestParameters($link, int $pageSize, bool $isCritical): void { public function setRequestParameters($link, int $pageSize, bool $isCritical): void {
$linkId = $this->getLinkId($link); $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 // abandons a previous paged search
$this->linkData[$linkId]['cookie'] = ''; $this->linkData[$linkId]['cookie'] = '';
} }
@ -100,7 +101,7 @@ class Php54 implements IAdapter {
int $limit int $limit
): void { ): void {
$linkId = $this->getLinkId($link); $linkId = $this->getLinkId($link);
if(!isset($this->linkData[$linkId])) { if (!isset($this->linkData[$linkId])) {
$this->linkData[$linkId] = []; $this->linkData[$linkId] = [];
} }
$this->linkData[$linkId]['searchArgs'] = func_get_args(); $this->linkData[$linkId]['searchArgs'] = func_get_args();
@ -113,7 +114,7 @@ class Php54 implements IAdapter {
public function setReadArgs($link, string $baseDN, string $filter, array $attr): void { public function setReadArgs($link, string $baseDN, string $filter, array $attr): void {
$linkId = $this->getLinkId($link); $linkId = $this->getLinkId($link);
if(!isset($this->linkData[$linkId])) { if (!isset($this->linkData[$linkId])) {
$this->linkData[$linkId] = []; $this->linkData[$linkId] = [];
} }
$this->linkData[$linkId]['readArgs'] = func_get_args(); $this->linkData[$linkId]['readArgs'] = func_get_args();

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de> * @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
@ -50,7 +51,7 @@ class Php73 implements IAdapter {
$link = array_shift($originalArgs); $link = array_shift($originalArgs);
$linkId = $this->getLinkId($link); $linkId = $this->getLinkId($link);
if(!isset($this->linkData[$linkId])) { if (!isset($this->linkData[$linkId])) {
$this->linkData[$linkId] = []; $this->linkData[$linkId] = [];
} }
@ -85,7 +86,7 @@ class Php73 implements IAdapter {
public function setRequestParameters($link, int $pageSize, bool $isCritical): void { public function setRequestParameters($link, int $pageSize, bool $isCritical): void {
$linkId = $this->getLinkId($link); $linkId = $this->getLinkId($link);
if(!isset($this->linkData[$linkId])) { if (!isset($this->linkData[$linkId])) {
$this->linkData[$linkId] = []; $this->linkData[$linkId] = [];
} }
$this->linkData[$linkId]['requestArgs'] = []; $this->linkData[$linkId]['requestArgs'] = [];
@ -112,7 +113,7 @@ class Php73 implements IAdapter {
int $limit int $limit
): void { ): void {
$linkId = $this->getLinkId($link); $linkId = $this->getLinkId($link);
if(!isset($this->linkData[$linkId])) { if (!isset($this->linkData[$linkId])) {
$this->linkData[$linkId] = []; $this->linkData[$linkId] = [];
} }
@ -127,7 +128,7 @@ class Php73 implements IAdapter {
public function setReadArgs($link, string $baseDN, string $filter, array $attr): void { public function setReadArgs($link, string $baseDN, string $filter, array $attr): void {
$linkId = $this->getLinkId($link); $linkId = $this->getLinkId($link);
if(!isset($this->linkData[$linkId])) { if (!isset($this->linkData[$linkId])) {
$this->linkData[$linkId] = []; $this->linkData[$linkId] = [];
} }
@ -143,7 +144,7 @@ class Php73 implements IAdapter {
} }
protected function preparePagesResultsArgs(int $linkId, string $methodKey): void { protected function preparePagesResultsArgs(int $linkId, string $methodKey): void {
if(!isset($this->linkData[$linkId]['requestArgs'])) { if (!isset($this->linkData[$linkId]['requestArgs'])) {
return; return;
} }

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de> * @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
@ -24,12 +25,11 @@ declare(strict_types=1);
namespace OCA\User_LDAP\PagedResults; namespace OCA\User_LDAP\PagedResults;
trait TLinkId { trait TLinkId {
public function getLinkId($link) { public function getLinkId($link) {
if(is_resource($link)) { if (is_resource($link)) {
return (int)$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]; return (int)$link[0];
} }
throw new \RuntimeException('No resource provided'); throw new \RuntimeException('No resource provided');

View File

@ -1197,7 +1197,7 @@ class UserTest extends \Test\TestCase {
$this->access->expects($this->any()) $this->access->expects($this->any())
->method('search') ->method('search')
->willReturnCallback(function ($filter, $base) { ->willReturnCallback(function ($filter, $base) {
if($base === $this->dn) { if ($base === $this->dn) {
return [ return [
[ [
'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'], 'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'],
@ -1205,7 +1205,7 @@ class UserTest extends \Test\TestCase {
], ],
]; ];
} }
if($base === 'cn=default,ou=policies,dc=foo,dc=bar') { if ($base === 'cn=default,ou=policies,dc=foo,dc=bar') {
return [ return [
[ [
'pwdmaxage' => ['2592000'], 'pwdmaxage' => ['2592000'],
@ -1260,7 +1260,7 @@ class UserTest extends \Test\TestCase {
$this->access->expects($this->any()) $this->access->expects($this->any())
->method('search') ->method('search')
->willReturnCallback(function ($filter, $base) { ->willReturnCallback(function ($filter, $base) {
if($base === $this->dn) { if ($base === $this->dn) {
return [ return [
[ [
'pwdpolicysubentry' => ['cn=custom,ou=policies,dc=foo,dc=bar'], 'pwdpolicysubentry' => ['cn=custom,ou=policies,dc=foo,dc=bar'],

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com> * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>