Skip to content

Commit bf9a33e

Browse files
committed
composer run cs:fix
Signed-off-by: Côme Chilliet <[email protected]>
1 parent a0a9b2b commit bf9a33e

File tree

10 files changed

+50
-58
lines changed

10 files changed

+50
-58
lines changed

lib/Command/GroupAdminsToLdap.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
use Symfony\Component\Console\Input\InputOption;
3333
use Symfony\Component\Console\Output\OutputInterface;
3434

35-
3635
class GroupAdminsToLdap extends Command {
37-
3836
/**
3937
* This adds/removes group subadmins as ldap group owners
4038
*/
@@ -87,7 +85,6 @@ protected function configure() {
8785
}
8886

8987
protected function execute(InputInterface $input, OutputInterface $output): int {
90-
9188
if ($input->getOption('sim')) {
9289
$this->simulate = true;
9390
}
@@ -115,8 +112,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
115112
$currentNCAdmins = [];
116113
foreach ($allSubAdmins as $subAdmin) {
117114
$gid = $subAdmin['group']->getGID();
118-
if (!key_exists($gid,$currentNCAdmins)) $currentNCAdmins[$gid] = [];
119-
array_push($currentNCAdmins[$gid],$subAdmin['user']->getUID());
115+
if (!key_exists($gid, $currentNCAdmins)) {
116+
$currentNCAdmins[$gid] = [];
117+
}
118+
array_push($currentNCAdmins[$gid], $subAdmin['user']->getUID());
120119
}
121120

122121
$allLdapGroups = $access->fetchListOfGroups(
@@ -125,13 +124,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
125124
);
126125

127126
$currentLDAPAdmins = [];
128-
foreach($allLdapGroups as $ldapGroup) {
127+
foreach ($allLdapGroups as $ldapGroup) {
129128
$gid = $ldapGroup[$conn->ldapGroupDisplayName][0];
130-
if (key_exists('owner',$ldapGroup)) {
131-
if (!key_exists($gid,$currentLDAPAdmins)) $currentLDAPAdmins[$gid] = [];
129+
if (key_exists('owner', $ldapGroup)) {
130+
if (!key_exists($gid, $currentLDAPAdmins)) {
131+
$currentLDAPAdmins[$gid] = [];
132+
}
132133
foreach ($ldapGroup['owner'] as $ownerDN) {
133134
$uid = $access->getUserMapper()->getNameByDN($ownerDN);
134-
array_push($currentLDAPAdmins[$gid],$uid);
135+
array_push($currentLDAPAdmins[$gid], $uid);
135136
}
136137
}
137138
}
@@ -142,17 +143,18 @@ function diff_user_arrays($array1, $array2) {
142143
if (!isset($array2[$gid]) || !is_array($array2[$gid])) {
143144
$difference[$gid] = $users;
144145
} else {
145-
$diff = array_diff($array1[$gid],$array2[$gid]);
146-
if (count($diff)) $difference[$gid] = array_diff($array1[$gid],$array2[$gid]);
146+
$diff = array_diff($array1[$gid], $array2[$gid]);
147+
if (count($diff)) {
148+
$difference[$gid] = array_diff($array1[$gid], $array2[$gid]);
149+
}
147150
}
148-
149151
}
150152
return $difference;
151153
}
152154

153155

154-
$onlyInLDAP = diff_user_arrays($currentLDAPAdmins,$currentNCAdmins);
155-
$onlyInNC = diff_user_arrays($currentNCAdmins,$currentLDAPAdmins);
156+
$onlyInLDAP = diff_user_arrays($currentLDAPAdmins, $currentNCAdmins);
157+
$onlyInNC = diff_user_arrays($currentNCAdmins, $currentLDAPAdmins);
156158

157159

158160
foreach ($onlyInNC as $gid => $users) {
@@ -188,7 +190,6 @@ function diff_user_arrays($array1, $array2) {
188190
}
189191

190192
$output->writeln("As Pink Floyd says: 'This is the end....'");
191-
192193
} catch (Exception $e) {
193194
$output->writeln('<error>' . $e->getMessage(). '</error>');
194195
return 1;

lib/LDAPConnect.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public function connect() {
5757
$ldapHost .= ':' . $ldapPort;
5858
}
5959

60-
// Connecting to LDAP - TODO: connect directly via LDAP plugin
61-
$cr = ldap_connect($ldapHost);
62-
if(!is_resource($cr) && !is_object($cr)) {
60+
// Connecting to LDAP - TODO: connect directly via LDAP plugin
61+
$cr = ldap_connect($ldapHost);
62+
if (!is_resource($cr) && !is_object($cr)) {
6363
throw new ServerNotAvailableException('LDAP server not available');
6464
}
6565

@@ -81,50 +81,50 @@ public function connect() {
8181
]);
8282
return false;
8383
}
84-
}
84+
}
8585

8686
/**
8787
* @return bool|resource
8888
* @throws ServerNotAvailableException
8989
*/
9090
public function bind() {
91-
$ds = $this->connect();
92-
$dn = $this->ldapConfig->ldapAgentName;
93-
$secret = $this->ldapConfig->ldapAgentPassword;
91+
$ds = $this->connect();
92+
$dn = $this->ldapConfig->ldapAgentName;
93+
$secret = $this->ldapConfig->ldapAgentPassword;
9494

95-
if (!ldap_bind($ds,$dn,$secret)) {
95+
if (!ldap_bind($ds, $dn, $secret)) {
9696
$this->logger->error('Unable to bind to LDAP server',
9797
['app' => Application::APP_ID]
9898
);
9999
return false;
100-
} else {
100+
} else {
101101
$this->logger->debug('Bound to LDAP server using credentials for {dn}', [
102102
'app' => Application::APP_ID,
103103
'dn' => $dn,
104104
]);
105-
return $ds;
106-
}
107-
}
105+
return $ds;
106+
}
107+
}
108108

109109
/**
110110
* @return bool|resource
111111
* @throws ServerNotAvailableException
112112
*/
113113
public function getLDAPConnection() {
114-
return $this->bind();
114+
return $this->bind();
115115
}
116116

117117
public function getLDAPBaseUsers(): array {
118118
$bases = $this->ldapConfig->ldapBaseUsers;
119-
if(empty($bases)) {
119+
if (empty($bases)) {
120120
$bases = $this->ldapConfig->ldapBase;
121121
}
122122
return $bases;
123123
}
124124

125125
public function getLDAPBaseGroups(): array {
126126
$bases = $this->ldapConfig->ldapBaseGroups;
127-
if(empty($bases)) {
127+
if (empty($bases)) {
128128
$bases = $this->ldapConfig->ldapBase;
129129
}
130130
return $bases;

lib/LDAPGroupManager.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
use Psr\Log\LoggerInterface;
3636

3737
class LDAPGroupManager implements ILDAPGroupPlugin {
38-
3938
/** @var ILDAPProvider */
4039
private $ldapProvider;
4140

@@ -53,7 +52,7 @@ public function __construct(IGroupManager $groupManager, LDAPConnect $ldapConnec
5352
$this->logger = $logger;
5453
$this->ldapProvider = $LDAPProvider;
5554

56-
if($this->ldapConnect->groupsEnabled()) {
55+
if ($this->ldapConnect->groupsEnabled()) {
5756
$this->makeLdapBackendFirst();
5857
}
5958
}
@@ -68,7 +67,7 @@ public function __construct(IGroupManager $groupManager, LDAPConnect $ldapConnec
6867
* compared with OC_GROUP_BACKEND_CREATE_GROUP etc.
6968
*/
7069
public function respondToActions() {
71-
if(!$this->ldapConnect->groupsEnabled()) {
70+
if (!$this->ldapConnect->groupsEnabled()) {
7271
return 0;
7372
}
7473
return Backend::CREATE_GROUP |
@@ -82,7 +81,6 @@ public function respondToActions() {
8281
* @return string|null
8382
*/
8483
public function createGroup($gid) {
85-
8684
/**
8785
* FIXME could not create group using LDAPProvider, because its methods rely
8886
* on passing an already inserted [ug]id, which we do not have at this point.
@@ -245,5 +243,4 @@ public function makeLdapBackendFirst(): void {
245243
$this->groupManager->addBackend($backend);
246244
}
247245
}
248-
249246
}

lib/LDAPUserManager.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
use OCP\LDAP\ILDAPProvider;
4545
use Psr\Log\LoggerInterface;
4646

47-
4847
class LDAPUserManager implements ILDAPUserPlugin {
4948
/** @var ILDAPProvider */
5049
private $ldapProvider;
@@ -234,7 +233,7 @@ public function createUser($username, $password) {
234233

235234
$message = 'Create LDAP user \'{username}\' ({dn})';
236235
$logMethod = 'info';
237-
if($ret === false) {
236+
if ($ret === false) {
238237
$message = 'Unable to create LDAP user \'{username}\' ({dn})';
239238
$logMethod = 'error';
240239
}
@@ -271,13 +270,13 @@ public function createUser($username, $password) {
271270
} catch (\Exception $e) {
272271
$this->logger->logException($e, ['app' => Application::APP_ID]);
273272
}
274-
}
273+
}
275274
return $ret ? $newUserDN : false;
276275
}
277276

278277
public function ensureAttribute(array &$ldif, string $attribute, string $fallbackValue): void {
279278
$lowerCasedLDIF = array_change_key_case($ldif, CASE_LOWER);
280-
if(!isset($lowerCasedLDIF[strtolower($attribute)])) {
279+
if (!isset($lowerCasedLDIF[strtolower($attribute)])) {
281280
$ldif[$attribute] = $fallbackValue;
282281
}
283282
}
@@ -308,7 +307,7 @@ public function buildNewEntry($username, $password, $base): array {
308307
$value = trim($split[1]);
309308
if (!isset($entry[$key])) {
310309
$entry[$key] = $value;
311-
} else if (is_array($entry[$key])) {
310+
} elseif (is_array($entry[$key])) {
312311
$entry[$key][] = $value;
313312
} else {
314313
$entry[$key] = [$entry[$key], $value];
@@ -366,7 +365,7 @@ public function deleteUser($uid): bool {
366365
* Change the password of a user
367366
*/
368367
public function setPassword($uid, $password) {
369-
if(!function_exists('ldap_exop_passwd')) {
368+
if (!function_exists('ldap_exop_passwd')) {
370369
// since PHP 7.2 – respondToActions checked this already, this
371370
// method should not be called. Double check due to public scope.
372371
// This method can be removed when Nextcloud 16 compat is dropped.
@@ -444,7 +443,6 @@ public function changeUserHook(IUser $user, string $feature, $attr1, $attr2): vo
444443
//attr1 = new email ; attr2 = old email
445444
$this->changeEmail($user, $attr1);
446445
break;
447-
448446
}
449447
}
450448

lib/Listener/GroupBackendRegisteredListener.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
use OCP\EventDispatcher\IEventListener;
3333

3434
class GroupBackendRegisteredListener implements IEventListener {
35-
3635
/** @var IAppManager */
3736
private $appManager;
3837
/** @var LDAPGroupManager */

lib/Listener/UserBackendRegisteredListener.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
use OCP\EventDispatcher\IEventListener;
3333

3434
class UserBackendRegisteredListener implements IEventListener {
35-
3635
/** @var IAppManager */
3736
private $appManager;
3837
/** @var LDAPUserManager */

lib/Service/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34
/**
45
* @copyright Copyright (c) 2019 Arthur Schiwon <[email protected]>
@@ -28,7 +29,6 @@
2829
use OCP\IConfig;
2930

3031
class Configuration {
31-
3232
/** @var IConfig */
3333
private $config;
3434

lib/Settings/Admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34
/**
45
* @copyright Copyright (c) 2019 Arthur Schiwon <[email protected]>

tests/integration/features/bootstrap/BasicStructure.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
require __DIR__ . '/../../vendor/autoload.php';
4040

4141
trait BasicStructure {
42-
4342
/** @var string */
4443
private $currentUser = '';
4544

@@ -67,7 +66,6 @@ trait BasicStructure {
6766
protected $remoteBaseUrl;
6867

6968
public function __construct($baseUrl, $admin, $regular_user_password) {
70-
7169
// Initialize your context here
7270
$this->baseUrl = $baseUrl;
7371
$this->adminUser = $admin;
@@ -366,7 +364,7 @@ public function modifyTextOfFile($user, $filename, $text) {
366364
private function getDataDirectory() {
367365
// Based on "runOcc" from CommandLine trait
368366
$args = ['config:system:get', 'datadirectory'];
369-
$args = array_map(function($arg) {
367+
$args = array_map(function ($arg) {
370368
return escapeshellarg($arg);
371369
}, $args);
372370
$args[] = '--no-ansi --no-warnings';
@@ -514,11 +512,11 @@ public function cookiesAreReset() {
514512
* @throws \Exception
515513
*/
516514
public function theFollowingHeadersShouldBeSet(TableNode $table) {
517-
foreach($table->getTable() as $header) {
515+
foreach ($table->getTable() as $header) {
518516
$headerName = $header[0];
519517
$expectedHeaderValue = $header[1];
520518
$returnedHeader = $this->response->getHeader($headerName)[0];
521-
if($returnedHeader !== $expectedHeaderValue) {
519+
if ($returnedHeader !== $expectedHeaderValue) {
522520
throw new \Exception(
523521
sprintf(
524522
"Expected value '%s' for header '%s', got '%s'",

tests/integration/features/bootstrap/FeatureContext.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34
/**
45
* @copyright Copyright (c) 2019 Arthur Schiwon <[email protected]>
@@ -27,7 +28,6 @@
2728
use PHPUnit\Framework\Assert;
2829

2930
class FeatureContext extends LDAPContext implements Context {
30-
3131
/** @var string[] */
3232
private $userIdsToCleanUp = [];
3333
/** @var string[] */
@@ -40,20 +40,20 @@ class FeatureContext extends LDAPContext implements Context {
4040
*/
4141
public function deleteCreatedObjects() {
4242
$this->asAn('admin');
43-
while($uid = array_shift($this->userIdsToCleanUp)) {
43+
while ($uid = array_shift($this->userIdsToCleanUp)) {
4444
error_log("deleting user $uid");
4545
$this->deletingTheUser($uid);
4646
}
4747

48-
while($gid = array_shift($this->groupIdsToCleanUp)) {
48+
while ($gid = array_shift($this->groupIdsToCleanUp)) {
4949
error_log("deleting group $gid");
5050
$this->sendingTo('DELETE', '/cloud/groups/' . $gid);
5151
}
5252
}
5353

5454
public function resetAppConfigs() {
55-
$this->modifyServerConfig('core','newUser.generateUserID', 'no');
56-
$this->modifyServerConfig('core','newUser.requireEmail', 'no');
55+
$this->modifyServerConfig('core', 'newUser.generateUserID', 'no');
56+
$this->modifyServerConfig('core', 'newUser.requireEmail', 'no');
5757
}
5858

5959
/**
@@ -70,7 +70,7 @@ public function itYieldsResult($count) {
7070
public function creatingAUserWith(TableNode $args) {
7171
$this->sendingToWith('POST', '/cloud/users', $args);
7272
$xml = simplexml_load_string($this->getResponse()->getBody()->getContents());
73-
if($xml->data && $xml->data->id) {
73+
if ($xml->data && $xml->data->id) {
7474
$this->userIdsToCleanUp[(string)$xml->data->id] = (string)$xml->data->id;
7575
$this->recentlyCreatedUser = (string)$xml->data->id;
7676
}
@@ -91,7 +91,7 @@ public function creatingAGroupWithGid($gid) {
9191
$args = new TableNode([['groupid', $gid]]);
9292
$this->sendingToWith('POST', '/cloud/groups', $args);
9393
$xml = simplexml_load_string($this->getResponse()->getBody()->getContents());
94-
if($this->getOCSResponse($this->getResponse()) === 200) {
94+
if ($this->getOCSResponse($this->getResponse()) === 200) {
9595
$this->groupIdsToCleanUp[$gid] = $gid;
9696
}
9797
}
@@ -104,5 +104,4 @@ public function userExistsOnBackend($uid, $backendName) {
104104
$needle = '<backend>' . $backendName . '</backend>';
105105
Assert::assertNotFalse(strpos($this->getResponse()->getBody()->getContents(), $needle));
106106
}
107-
108107
}

0 commit comments

Comments
 (0)