diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-04-10 14:19:56 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-04-10 14:19:56 +0200 |
commit | caff1023ea72bb2ea94130e18a2a6e2ccf819e5f (patch) | |
tree | 186d494c2aea5dea7255d3584ef5d595fc6e6194 /apps/provisioning_api | |
parent | edf8ce32cffdb920e8171207b342abbd7f1fbe73 (diff) | |
download | nextcloud-server-caff1023ea72bb2ea94130e18a2a6e2ccf819e5f.tar.gz nextcloud-server-caff1023ea72bb2ea94130e18a2a6e2ccf819e5f.zip |
Format control structures, classes, methods and function
To continue this formatting madness, here's a tiny patch that adds
unified formatting for control structures like if and loops as well as
classes, their methods and anonymous functions. This basically forces
the constructs to start on the same line. This is not exactly what PSR2
wants, but I think we can have a few exceptions with "our" style. The
starting of braces on the same line is pracrically standard for our
code.
This also removes and empty lines from method/function bodies at the
beginning and end.
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/provisioning_api')
11 files changed, 28 insertions, 45 deletions
diff --git a/apps/provisioning_api/lib/Controller/AUserData.php b/apps/provisioning_api/lib/Controller/AUserData.php index 3579202b36f..31a8322e4a7 100644 --- a/apps/provisioning_api/lib/Controller/AUserData.php +++ b/apps/provisioning_api/lib/Controller/AUserData.php @@ -100,14 +100,14 @@ abstract class AUserData extends OCSController { // Check if the target user exists $targetUserObject = $this->userManager->get($userId); - if($targetUserObject === null) { + if ($targetUserObject === null) { throw new OCSNotFoundException('User does not exist'); } // Should be at least Admin Or SubAdmin! if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { - $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true'; + $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true'; } else { // Check they are looking up themselves if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { @@ -167,7 +167,7 @@ abstract class AUserData extends OCSController { protected function getUserSubAdminGroupsData(string $userId): array { $user = $this->userManager->get($userId); // Check if the user exists - if($user === null) { + if ($user === null) { throw new OCSNotFoundException('User does not exist'); } @@ -215,5 +215,4 @@ abstract class AUserData extends OCSController { } return $data; } - } diff --git a/apps/provisioning_api/lib/Controller/AppsController.php b/apps/provisioning_api/lib/Controller/AppsController.php index d5a8de91772..e59440e5e8c 100644 --- a/apps/provisioning_api/lib/Controller/AppsController.php +++ b/apps/provisioning_api/lib/Controller/AppsController.php @@ -64,11 +64,11 @@ class AppsController extends OCSController { public function getApps(string $filter = null): DataResponse { $apps = (new OC_App())->listAllApps(); $list = []; - foreach($apps as $app) { + foreach ($apps as $app) { $list[] = $app['id']; } - if($filter){ - switch($filter){ + if ($filter) { + switch ($filter) { case 'enabled': return new DataResponse(['apps' => \OC_App::getEnabledApps()]); break; @@ -80,7 +80,6 @@ class AppsController extends OCSController { // Invalid filter variable throw new OCSException('', 101); } - } else { return new DataResponse(['apps' => $list]); } @@ -93,7 +92,7 @@ class AppsController extends OCSController { */ public function getAppInfo(string $app): DataResponse { $info = \OCP\App::getAppInfo($app); - if(!is_null($info)) { + if (!is_null($info)) { return new DataResponse(OC_App::getAppInfo($app)); } @@ -124,5 +123,4 @@ class AppsController extends OCSController { $this->appManager->disableApp($app); return new DataResponse(); } - } diff --git a/apps/provisioning_api/lib/Controller/GroupsController.php b/apps/provisioning_api/lib/Controller/GroupsController.php index 435f0410217..7f2da88a097 100644 --- a/apps/provisioning_api/lib/Controller/GroupsController.php +++ b/apps/provisioning_api/lib/Controller/GroupsController.php @@ -163,7 +163,7 @@ class GroupsController extends AUserData { } // Check subadmin has access to this group - if($this->groupManager->isAdmin($user->getUID()) + if ($this->groupManager->isAdmin($user->getUID()) || $isSubadminOfGroup) { $users = $this->groupManager->get($groupId)->getUsers(); $users = array_map(function ($user) { @@ -201,7 +201,7 @@ class GroupsController extends AUserData { } // Check subadmin has access to this group - if($this->groupManager->isAdmin($currentUser->getUID()) || $isSubadminOfGroup) { + if ($this->groupManager->isAdmin($currentUser->getUID()) || $isSubadminOfGroup) { $users = $group->searchUsers($search, $limit, $offset); // Extract required number @@ -219,7 +219,7 @@ class GroupsController extends AUserData { // only showing its id $usersDetails[$userId] = ['id' => $userId]; } - } catch(OCSNotFoundException $e) { + } catch (OCSNotFoundException $e) { // continue if a users ceased to exist. } } @@ -240,12 +240,12 @@ class GroupsController extends AUserData { */ public function addGroup(string $groupid): DataResponse { // Validate name - if(empty($groupid)) { + if (empty($groupid)) { $this->logger->error('Group name not supplied', ['app' => 'provisioning_api']); throw new OCSException('Invalid group name', 101); } // Check if it exists - if($this->groupManager->groupExists($groupid)){ + if ($this->groupManager->groupExists($groupid)) { throw new OCSException('group exists', 102); } $this->groupManager->createGroup($groupid); @@ -283,9 +283,9 @@ class GroupsController extends AUserData { */ public function deleteGroup(string $groupId): DataResponse { // Check it exists - if(!$this->groupManager->groupExists($groupId)){ + if (!$this->groupManager->groupExists($groupId)) { throw new OCSException('', 101); - } elseif($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){ + } elseif ($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()) { // Cannot delete admin group throw new OCSException('', 102); } @@ -301,7 +301,7 @@ class GroupsController extends AUserData { public function getSubAdminsOfGroup(string $groupId): DataResponse { // Check group exists $targetGroup = $this->groupManager->get($groupId); - if($targetGroup === null) { + if ($targetGroup === null) { throw new OCSException('Group does not exist', 101); } @@ -315,5 +315,4 @@ class GroupsController extends AUserData { return new DataResponse($uids); } - } diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index ff67a880c13..bd327ffe441 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -140,7 +140,7 @@ class UsersController extends AUserData { // Admin? Or SubAdmin? $uid = $user->getUID(); $subAdminManager = $this->groupManager->getSubAdmin(); - if ($this->groupManager->isAdmin($uid)){ + if ($this->groupManager->isAdmin($uid)) { $users = $this->userManager->search($search, $limit, $offset); } elseif ($subAdminManager->isSubAdmin($user)) { $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); @@ -173,7 +173,7 @@ class UsersController extends AUserData { // Admin? Or SubAdmin? $uid = $currentUser->getUID(); $subAdminManager = $this->groupManager->getSubAdmin(); - if ($this->groupManager->isAdmin($uid)){ + if ($this->groupManager->isAdmin($uid)) { $users = $this->userManager->search($search, $limit, $offset); $users = array_keys($users); } elseif ($subAdminManager->isSubAdmin($currentUser)) { @@ -250,7 +250,7 @@ class UsersController extends AUserData { $isAdmin = $this->groupManager->isAdmin($user->getUID()); $subAdminManager = $this->groupManager->getSubAdmin(); - if(empty($userid) && $this->config->getAppValue('core', 'newUser.generateUserID', 'no') === 'yes') { + if (empty($userid) && $this->config->getAppValue('core', 'newUser.generateUserID', 'no') === 'yes') { $userid = $this->createNewUserId(); } @@ -352,7 +352,6 @@ class UsersController extends AUserData { } return new DataResponse(['id' => $userid]); - } catch (HintException $e) { $this->logger->logException($e, [ 'message' => 'Failed addUser attempt with hint exception.', @@ -414,7 +413,6 @@ class UsersController extends AUserData { $data['display-name'] = $data['displayname']; unset($data['displayname']); return new DataResponse($data); - } throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); @@ -530,7 +528,7 @@ class UsersController extends AUserData { throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); } // Process the edit - switch($key) { + switch ($key) { case 'display': case AccountManager::PROPERTY_DISPLAYNAME: $targetUser->setDisplayName($value); @@ -755,7 +753,6 @@ class UsersController extends AUserData { throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); } } - } /** @@ -835,7 +832,6 @@ class UsersController extends AUserData { // Not an admin, so the user must be a subadmin of this group, but that is not allowed. throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105); } - } elseif (!$this->groupManager->isAdmin($loggedInUser->getUID())) { /** @var IGroup[] $subAdminGroups */ $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); @@ -973,7 +969,7 @@ class UsersController extends AUserData { try { $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false); $this->newUserMailHelper->sendMail($targetUser, $emailTemplate); - } catch(\Exception $e) { + } catch (\Exception $e) { $this->logger->logException($e, [ 'message' => "Can't send new user mail to $email", 'level' => ILogger::ERROR, diff --git a/apps/provisioning_api/lib/FederatedFileSharingFactory.php b/apps/provisioning_api/lib/FederatedFileSharingFactory.php index 63a0f0ff200..6a630542af5 100644 --- a/apps/provisioning_api/lib/FederatedFileSharingFactory.php +++ b/apps/provisioning_api/lib/FederatedFileSharingFactory.php @@ -40,5 +40,4 @@ class FederatedFileSharingFactory { public function get(): Application { return $this->serverContainer->query(Application::class); } - } diff --git a/apps/provisioning_api/tests/Controller/AppConfigControllerTest.php b/apps/provisioning_api/tests/Controller/AppConfigControllerTest.php index a87f69a25b3..50a00a1e93f 100644 --- a/apps/provisioning_api/tests/Controller/AppConfigControllerTest.php +++ b/apps/provisioning_api/tests/Controller/AppConfigControllerTest.php @@ -49,7 +49,6 @@ class AppConfigControllerTest extends TestCase { $this->config = $this->createMock(IConfig::class); $this->appConfig = $this->createMock(IAppConfig::class); - } /** @@ -105,7 +104,6 @@ class AppConfigControllerTest extends TestCase { * @param int $status */ public function testGetKeys($app, $keys, $throws, $status) { - $api = $this->getInstance(['verifyAppId']); if ($throws instanceof \Exception) { $api->expects($this->once()) @@ -153,7 +151,6 @@ class AppConfigControllerTest extends TestCase { * @param int $status */ public function testGetValue($app, $key, $default, $return, $throws, $status) { - $api = $this->getInstance(['verifyAppId']); if ($throws instanceof \Exception) { $api->expects($this->once()) @@ -202,7 +199,6 @@ class AppConfigControllerTest extends TestCase { * @param int $status */ public function testSetValue($app, $key, $value, $appThrows, $keyThrows, $status) { - $api = $this->getInstance(['verifyAppId', 'verifyConfigKey']); if ($appThrows instanceof \Exception) { $api->expects($this->once()) @@ -267,7 +263,6 @@ class AppConfigControllerTest extends TestCase { * @param int $status */ public function testDeleteValue($app, $key, $appThrows, $keyThrows, $status) { - $api = $this->getInstance(['verifyAppId', 'verifyConfigKey']); if ($appThrows instanceof \Exception) { $api->expects($this->once()) diff --git a/apps/provisioning_api/tests/Controller/AppsControllerTest.php b/apps/provisioning_api/tests/Controller/AppsControllerTest.php index bfc7a2f623a..28867f0b80b 100644 --- a/apps/provisioning_api/tests/Controller/AppsControllerTest.php +++ b/apps/provisioning_api/tests/Controller/AppsControllerTest.php @@ -102,7 +102,7 @@ class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase { $data = $result->getData(); $apps = (new \OC_App)->listAllApps(); $list = []; - foreach($apps as $app) { + foreach ($apps as $app) { $list[] = $app['id']; } $disabled = array_diff($list, \OC_App::getEnabledApps()); diff --git a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php index 70a920b743e..0ed6d58e217 100644 --- a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php +++ b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php @@ -219,7 +219,6 @@ class GroupsControllerTest extends \Test\TestCase { $result = $this->api->getGroups($search, $limit, $offset); $this->assertEquals(['groups' => ['group1', 'group2']], $result->getData()); - } /** @@ -260,7 +259,6 @@ class GroupsControllerTest extends \Test\TestCase { ] ]], $result->getData()); - } public function testGetGroupAsSubadmin() { diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index aff12547ec0..48b970e9687 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -440,7 +440,7 @@ class UsersControllerTest extends TestCase { ->expects($this->any()) ->method('getAppValue') ->willReturnCallback(function ($appid, $key, $default) { - if($key === 'newUser.generateUserID') { + if ($key === 'newUser.generateUserID') { return 'yes'; } return null; @@ -477,7 +477,9 @@ class UsersControllerTest extends TestCase { $this->secureRandom->expects($this->any()) ->method('generate') ->with(10) - ->willReturnCallback(function () { return (string)rand(1000000000, 9999999999); }); + ->willReturnCallback(function () { + return (string)rand(1000000000, 9999999999); + }); $this->assertTrue(key_exists( 'id', @@ -495,7 +497,7 @@ class UsersControllerTest extends TestCase { ->expects($this->any()) ->method('getAppValue') ->willReturnCallback(function ($appid, $key, $default) { - if($key === 'newUser.generateUserID') { + if ($key === 'newUser.generateUserID') { return 'yes'; } return null; @@ -538,7 +540,7 @@ class UsersControllerTest extends TestCase { ->expects($this->any()) ->method('getAppValue') ->willReturnCallback(function ($appid, $key, $default) { - if($key === 'newUser.requireEmail') { + if ($key === 'newUser.requireEmail') { return 'yes'; } return null; @@ -1590,7 +1592,6 @@ class UsersControllerTest extends TestCase { } public function testEditUserSelfEditChangeLanguage() { - $this->l10nFactory->expects($this->once()) ->method('findAvailableLanguages') ->willReturn(['en', 'de', 'sv']); @@ -1683,7 +1684,6 @@ class UsersControllerTest extends TestCase { } public function testEditUserAdminEditChangeLanguage() { - $this->l10nFactory->expects($this->once()) ->method('findAvailableLanguages') ->willReturn(['en', 'de', 'sv']); diff --git a/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php b/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php index 368fa40356f..b3b2184b2ba 100644 --- a/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php +++ b/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php @@ -118,6 +118,5 @@ class ProvisioningApiMiddlewareTest extends TestCase { $this->assertTrue($forwared); $this->assertSame($exception, $e); } - } } diff --git a/apps/provisioning_api/tests/TestCase.php b/apps/provisioning_api/tests/TestCase.php index f2495cdba62..7ddebfcf322 100644 --- a/apps/provisioning_api/tests/TestCase.php +++ b/apps/provisioning_api/tests/TestCase.php @@ -65,7 +65,7 @@ abstract class TestCase extends \Test\TestCase { } protected function tearDown(): void { - foreach($this->users as $user) { + foreach ($this->users as $user) { $user->delete(); } |