From 60c91bdc674e930cf41339c87828bf7cc8d972a1 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Thu, 24 Jun 2021 13:48:09 +0200 Subject: [PATCH] phpstormify Signed-off-by: Julien Veyssier --- lib/AppInfo/Application.php | 9 ++- lib/Controller/ConfigController.php | 55 ++++--------- lib/Controller/MoodleAPIController.php | 61 +++++++-------- lib/Dashboard/MoodleWidget.php | 20 +++-- lib/Search/MoodleSearchCoursesProvider.php | 18 +++-- lib/Search/MoodleSearchModulesProvider.php | 25 ++++-- lib/Search/MoodleSearchUpcomingProvider.php | 19 +++-- lib/Service/MoodleAPIService.php | 52 +++++++++---- lib/Settings/Admin.php | 33 +++----- lib/Settings/AdminSection.php | 11 +-- lib/Settings/Personal.php | 54 ++++++------- lib/Settings/PersonalSection.php | 86 ++++++++++----------- 12 files changed, 219 insertions(+), 224 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index c8fc292..0d013a2 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -9,16 +9,13 @@ namespace OCA\Moodle\AppInfo; -use OCP\IContainer; use OCP\IConfig; use OCP\AppFramework\App; -use OCP\AppFramework\IAppContainer; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; -use OCA\Moodle\Controller\PageController; use OCA\Moodle\Dashboard\MoodleWidget; use OCA\Moodle\Search\MoodleSearchCoursesProvider; use OCA\Moodle\Search\MoodleSearchModulesProvider; @@ -32,6 +29,10 @@ use OCA\Moodle\Search\MoodleSearchUpcomingProvider; class Application extends App implements IBootstrap { public const APP_ID = 'integration_moodle'; + /** + * @var mixed + */ + private $config; /** * Constructor @@ -42,7 +43,7 @@ class Application extends App implements IBootstrap { parent::__construct(self::APP_ID, $urlParams); $container = $this->getContainer(); - $this->config = $container->query(IConfig::class); + $this->config = $container->get(IConfig::class); } public function register(IRegistrationContext $context): void { diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php index c5a10ad..38deb9c 100644 --- a/lib/Controller/ConfigController.php +++ b/lib/Controller/ConfigController.php @@ -11,58 +11,31 @@ namespace OCA\Moodle\Controller; -use OCP\App\IAppManager; -use OCP\Files\IAppData; -use OCP\AppFramework\Http\DataDisplayResponse; - -use OCP\IURLGenerator; use OCP\IConfig; -use OCP\IServerContainer; -use OCP\IL10N; -use Psr\Log\LoggerInterface; - -use OCP\AppFramework\Http; -use OCP\AppFramework\Http\RedirectResponse; - -use OCP\AppFramework\Http\ContentSecurityPolicy; - use OCP\IRequest; -use OCP\IDBConnection; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Controller; -use OCA\Moodle\Service\MoodleAPIService; use OCA\Moodle\AppInfo\Application; class ConfigController extends Controller { - private $userId; + /** + * @var IConfig + */ private $config; - private $dbconnection; - private $dbtype; + /** + * @var string|null + */ + private $userId; - public function __construct($AppName, + public function __construct(string $appName, IRequest $request, - IServerContainer $serverContainer, IConfig $config, - IAppManager $appManager, - IAppData $appData, - IDBConnection $dbconnection, - IURLGenerator $urlGenerator, - IL10N $l, - LoggerInterface $logger, - MoodleAPIService $moodleAPIService, - $userId) { - parent::__construct($AppName, $request); - $this->l = $l; - $this->userId = $userId; - $this->appData = $appData; - $this->serverContainer = $serverContainer; + ?string $userId) { + parent::__construct($appName, $request); $this->config = $config; - $this->dbconnection = $dbconnection; - $this->urlGenerator = $urlGenerator; - $this->logger = $logger; - $this->moodleAPIService = $moodleAPIService; + $this->userId = $userId; } /** @@ -81,8 +54,7 @@ class ConfigController extends Controller { $this->config->deleteUserValue($this->userId, Application::APP_ID, 'user_name'); $this->config->deleteUserValue($this->userId, Application::APP_ID, 'privatetoken'); } - $response = new DataResponse(1); - return $response; + return new DataResponse(1); } /** @@ -95,7 +67,6 @@ class ConfigController extends Controller { foreach ($values as $key => $value) { $this->config->setAppValue(Application::APP_ID, $key, $value); } - $response = new DataResponse(1); - return $response; + return new DataResponse(1); } } diff --git a/lib/Controller/MoodleAPIController.php b/lib/Controller/MoodleAPIController.php index b3a0ed2..32dfdce 100644 --- a/lib/Controller/MoodleAPIController.php +++ b/lib/Controller/MoodleAPIController.php @@ -11,21 +11,8 @@ namespace OCA\Moodle\Controller; -use OCP\App\IAppManager; -use OCP\Files\IAppData; use OCP\AppFramework\Http\DataDisplayResponse; - -use OCP\IURLGenerator; use OCP\IConfig; -use OCP\IServerContainer; -use OCP\IL10N; - -use OCP\AppFramework\Http; -use OCP\AppFramework\Http\RedirectResponse; - -use OCP\AppFramework\Http\ContentSecurityPolicy; - -use Psr\Log\LoggerInterface; use OCP\IRequest; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Controller; @@ -35,32 +22,42 @@ use OCA\Moodle\AppInfo\Application; class MoodleAPIController extends Controller { - - private $userId; + /** + * @var IConfig + */ private $config; - private $dbconnection; - private $dbtype; + /** + * @var MoodleAPIService + */ + private $moodleAPIService; + /** + * @var string|null + */ + private $userId; + /** + * @var string + */ + private $accessToken; + /** + * @var string + */ + private $moodleUrl; + /** + * @var bool + */ + private $checkSsl; - public function __construct($AppName, + public function __construct(string $appName, IRequest $request, - IServerContainer $serverContainer, IConfig $config, - IL10N $l10n, - IAppManager $appManager, - IAppData $appData, - LoggerInterface $logger, MoodleAPIService $moodleAPIService, - $userId) { - parent::__construct($AppName, $request); - $this->userId = $userId; - $this->l10n = $l10n; - $this->appData = $appData; - $this->serverContainer = $serverContainer; + ?string $userId) { + parent::__construct($appName, $request); $this->config = $config; - $this->logger = $logger; $this->moodleAPIService = $moodleAPIService; - $this->accessToken = $this->config->getUserValue($this->userId, Application::APP_ID, 'token', ''); - $this->moodleUrl = $this->config->getUserValue($this->userId, Application::APP_ID, 'url', ''); + $this->userId = $userId; + $this->accessToken = $this->config->getUserValue($this->userId, Application::APP_ID, 'token'); + $this->moodleUrl = $this->config->getUserValue($this->userId, Application::APP_ID, 'url'); $this->checkSsl = $this->config->getUserValue($this->userId, Application::APP_ID, 'check_ssl', '1') === '1'; } diff --git a/lib/Dashboard/MoodleWidget.php b/lib/Dashboard/MoodleWidget.php index 198d487..136f073 100644 --- a/lib/Dashboard/MoodleWidget.php +++ b/lib/Dashboard/MoodleWidget.php @@ -27,16 +27,22 @@ use OCP\Dashboard\IWidget; use OCP\IL10N; use OCA\Moodle\AppInfo\Application; +use OCP\IURLGenerator; +use OCP\Util; class MoodleWidget implements IWidget { /** @var IL10N */ private $l10n; + /** + * @var IURLGenerator + */ + private $url; - public function __construct( - IL10N $l10n - ) { + public function __construct(IL10N $l10n, + IURLGenerator $url) { $this->l10n = $l10n; + $this->url = $url; } /** @@ -71,14 +77,14 @@ class MoodleWidget implements IWidget { * @inheritDoc */ public function getUrl(): ?string { - return \OC::$server->getURLGenerator()->linkToRoute('settings.PersonalSettings.index', ['section' => 'connected-accounts']); + return $this->url->linkToRoute('settings.PersonalSettings.index', ['section' => 'connected-accounts']); } /** * @inheritDoc */ public function load(): void { - \OC_Util::addScript(Application::APP_ID, Application::APP_ID . '-dashboard'); - \OC_Util::addStyle(Application::APP_ID, 'dashboard'); + Util::addScript(Application::APP_ID, Application::APP_ID . '-dashboard'); + Util::addStyle(Application::APP_ID, 'dashboard'); } -} \ No newline at end of file +} diff --git a/lib/Search/MoodleSearchCoursesProvider.php b/lib/Search/MoodleSearchCoursesProvider.php index c7536ed..bb5aa23 100644 --- a/lib/Search/MoodleSearchCoursesProvider.php +++ b/lib/Search/MoodleSearchCoursesProvider.php @@ -45,6 +45,14 @@ class MoodleSearchCoursesProvider implements IProvider { /** @var IURLGenerator */ private $urlGenerator; + /** + * @var IConfig + */ + private $config; + /** + * @var MoodleAPIService + */ + private $service; /** * CospendSearchProvider constructor. @@ -105,13 +113,13 @@ class MoodleSearchCoursesProvider implements IProvider { $offset = $query->getCursor(); $offset = $offset ? intval($offset) : 0; - $theme = $this->config->getUserValue($user->getUID(), 'accessibility', 'theme', ''); + $theme = $this->config->getUserValue($user->getUID(), 'accessibility', 'theme'); $thumbnailUrl = ($theme === 'dark') ? $this->urlGenerator->imagePath(Application::APP_ID, 'app.svg') : $this->urlGenerator->imagePath(Application::APP_ID, 'app-dark.svg'); - $moodleUrl = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'url', ''); - $accessToken = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'token', ''); + $moodleUrl = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'url'); + $accessToken = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'token'); $checkSsl = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'check_ssl', '1') === '1'; $searchCoursesEnabled = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'search_courses_enabled', '0') === '1'; if ($accessToken === '' || !$searchCoursesEnabled) { @@ -123,7 +131,7 @@ class MoodleSearchCoursesProvider implements IProvider { return SearchResult::paginated($this->getName(), [], 0); } - $formattedResults = \array_map(function (array $entry) use ($thumbnailUrl, $moodleUrl): MoodleSearchResultEntry { + $formattedResults = array_map(function (array $entry) use ($thumbnailUrl, $moodleUrl): MoodleSearchResultEntry { return new MoodleSearchResultEntry( $thumbnailUrl, $this->getMainText($entry), @@ -166,4 +174,4 @@ class MoodleSearchCoursesProvider implements IProvider { return $url . '/course/view.php?id=' . $entry['id']; } -} \ No newline at end of file +} diff --git a/lib/Search/MoodleSearchModulesProvider.php b/lib/Search/MoodleSearchModulesProvider.php index 3573f18..eb1061f 100644 --- a/lib/Search/MoodleSearchModulesProvider.php +++ b/lib/Search/MoodleSearchModulesProvider.php @@ -45,12 +45,21 @@ class MoodleSearchModulesProvider implements IProvider { /** @var IURLGenerator */ private $urlGenerator; + /** + * @var IConfig + */ + private $config; + /** + * @var MoodleAPIService + */ + private $service; /** * CospendSearchProvider constructor. * * @param IAppManager $appManager * @param IL10N $l10n + * @param IConfig $config * @param IURLGenerator $urlGenerator * @param MoodleAPIService $service */ @@ -105,13 +114,13 @@ class MoodleSearchModulesProvider implements IProvider { $offset = $query->getCursor(); $offset = $offset ? intval($offset) : 0; - $theme = $this->config->getUserValue($user->getUID(), 'accessibility', 'theme', ''); + $theme = $this->config->getUserValue($user->getUID(), 'accessibility', 'theme'); $thumbnailUrl = ($theme === 'dark') ? $this->urlGenerator->imagePath(Application::APP_ID, 'app.svg') : $this->urlGenerator->imagePath(Application::APP_ID, 'app-dark.svg'); - $moodleUrl = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'url', ''); - $accessToken = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'token', ''); + $moodleUrl = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'url'); + $accessToken = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'token'); $checkSsl = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'check_ssl', '1') === '1'; $searchModulesEnabled = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'search_modules_enabled', '0') === '1'; if ($accessToken === '' || !$searchModulesEnabled) { @@ -123,7 +132,7 @@ class MoodleSearchModulesProvider implements IProvider { return SearchResult::paginated($this->getName(), [], 0); } - $formattedResults = \array_map(function (array $entry) use ($thumbnailUrl, $moodleUrl): MoodleSearchResultEntry { + $formattedResults = array_map(function (array $entry) use ($thumbnailUrl, $moodleUrl): MoodleSearchResultEntry { return new MoodleSearchResultEntry( $this->getThumbnailUrl($entry, $thumbnailUrl), $this->getMainText($entry), @@ -183,8 +192,8 @@ class MoodleSearchModulesProvider implements IProvider { */ protected function getThumbnailurl(array $entry, string $thumbnailUrl): string { return $thumbnailUrl; - return $entry['modicon'] - ? $this->urlGenerator->linkToRoute('integration_moodle.moodleAPI.getMoodleAvatar', []) . '?url=' . urlencode($entry['modicon']) - : $thumbnailUrl; +// return $entry['modicon'] +// ? $this->urlGenerator->linkToRoute('integration_moodle.moodleAPI.getMoodleAvatar', []) . '?url=' . urlencode($entry['modicon']) +// : $thumbnailUrl; } -} \ No newline at end of file +} diff --git a/lib/Search/MoodleSearchUpcomingProvider.php b/lib/Search/MoodleSearchUpcomingProvider.php index 8a75064..847c006 100644 --- a/lib/Search/MoodleSearchUpcomingProvider.php +++ b/lib/Search/MoodleSearchUpcomingProvider.php @@ -45,12 +45,21 @@ class MoodleSearchUpcomingProvider implements IProvider { /** @var IURLGenerator */ private $urlGenerator; + /** + * @var IConfig + */ + private $config; + /** + * @var MoodleAPIService + */ + private $service; /** * CospendSearchProvider constructor. * * @param IAppManager $appManager * @param IL10N $l10n + * @param IConfig $config * @param IURLGenerator $urlGenerator * @param MoodleAPIService $service */ @@ -105,13 +114,13 @@ class MoodleSearchUpcomingProvider implements IProvider { $offset = $query->getCursor(); $offset = $offset ? intval($offset) : 0; - $theme = $this->config->getUserValue($user->getUID(), 'accessibility', 'theme', ''); + $theme = $this->config->getUserValue($user->getUID(), 'accessibility', 'theme'); $thumbnailUrl = ($theme === 'dark') ? $this->urlGenerator->imagePath(Application::APP_ID, 'app.svg') : $this->urlGenerator->imagePath(Application::APP_ID, 'app-dark.svg'); - $moodleUrl = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'url', ''); - $accessToken = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'token', ''); + $moodleUrl = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'url'); + $accessToken = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'token'); $checkSsl = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'check_ssl', '1') === '1'; $searchUpcomingEnabled = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'search_upcoming_enabled', '0') === '1'; if ($accessToken === '' || !$searchUpcomingEnabled) { @@ -123,7 +132,7 @@ class MoodleSearchUpcomingProvider implements IProvider { return SearchResult::paginated($this->getName(), [], 0); } - $formattedResults = \array_map(function (array $entry) use ($thumbnailUrl, $moodleUrl): MoodleSearchResultEntry { + $formattedResults = array_map(function (array $entry) use ($thumbnailUrl, $moodleUrl): MoodleSearchResultEntry { return new MoodleSearchResultEntry( $this->getThumbnailUrl($entry, $thumbnailUrl), $this->getMainText($entry), @@ -175,4 +184,4 @@ class MoodleSearchUpcomingProvider implements IProvider { ? $entry['course']['courseimage'] : $thumbnailUrl; } -} \ No newline at end of file +} diff --git a/lib/Service/MoodleAPIService.php b/lib/Service/MoodleAPIService.php index c3d56ad..2b77cec 100644 --- a/lib/Service/MoodleAPIService.php +++ b/lib/Service/MoodleAPIService.php @@ -11,36 +11,46 @@ namespace OCA\Moodle\Service; +use Exception; use OCP\IL10N; use Psr\Log\LoggerInterface; use OCP\Http\Client\IClientService; -use OCA\Moodle\AppInfo\Application; - class MoodleAPIService { - - private $l10n; + /** + * @var string + */ + private $appName; + /** + * @var LoggerInterface + */ private $logger; + /** + * @var IL10N + */ + private $l10n; + /** + * @var \OCP\Http\Client\IClient + */ + private $client; /** * Service to make requests to Moodle v1 API */ - public function __construct ( - string $appName, - LoggerInterface $logger, - IL10N $l10n, - IClientService $clientService - ) { + public function __construct (string $appName, + LoggerInterface $logger, + IL10N $l10n, + IClientService $clientService) { $this->appName = $appName; - $this->l10n = $l10n; $this->logger = $logger; - $this->clientService = $clientService; + $this->l10n = $l10n; $this->client = $clientService->newClient(); } /** * @param string $url * @param string $accessToken + * @param bool $checkSsl * @param ?int $recentSince * @return array */ @@ -57,7 +67,7 @@ class MoodleAPIService { } // sort recent items by date DESC - $a = usort($recentItems, function($a, $b) { + usort($recentItems, function($a, $b) { $ta = $a['timeaccess'] ?? 0; $tb = $b['timeaccess'] ?? 0; return ($ta > $tb) ? -1 : 1; @@ -87,7 +97,7 @@ class MoodleAPIService { } } // sort upcoming events by date ASC - $a = usort($upcomingEvents, function($a, $b) { + usort($upcomingEvents, function($a, $b) { $ta = $a['timestart'] ?? 0; $tb = $b['timestart'] ?? 0; return ($ta < $tb) ? -1 : 1; @@ -115,6 +125,7 @@ class MoodleAPIService { /** * @param string $url * @param string $accessToken + * @param bool $checkSsl * @param string $query * @param int $offset * @param int $limit @@ -160,8 +171,8 @@ class MoodleAPIService { if ($sections['exception'] || $sections['error']) { return $sections; } - foreach ($sections as $k => $section) { - foreach ($section['modules'] as $k => $module) { + foreach ($sections as $ks => $section) { + foreach ($section['modules'] as $km => $module) { $moduleName = strtolower($module['name']); if (strpos($moduleName, $query) !== false) { $module['section_name'] = $section['name']; @@ -181,6 +192,7 @@ class MoodleAPIService { /** * @param string $url * @param string $accessToken + * @param bool $checkSsl * @param string $query * @param int $offset * @param int $limit @@ -228,7 +240,9 @@ class MoodleAPIService { /** * @param string $url + * @param bool $checkSsl * @return string + * @throws Exception */ public function getMoodleAvatar(string $url, bool $checkSsl): string { if ($checkSsl) { @@ -255,6 +269,7 @@ class MoodleAPIService { /** * @param string $url * @param string $endPoint + * @param bool $checkSsl * @param array $params * @param string $method * @return array @@ -299,6 +314,8 @@ class MoodleAPIService { $response = $this->client->put($url, $options); } else if ($method === 'DELETE') { $response = $this->client->delete($url, $options); + } else { + return ['error' => $this->l10n->t('Bad HTTP method')]; } $body = $response->getBody(); $respCode = $response->getStatusCode(); @@ -308,7 +325,7 @@ class MoodleAPIService { } else { return json_decode($body, true); } - } catch (\Exception $e) { + } catch (Exception $e) { $this->logger->warning('Moodle API error : '.$e, array('app' => $this->appName)); return ['error' => $e->getMessage()]; } @@ -318,6 +335,7 @@ class MoodleAPIService { * @param string $moodleUrl * @param string $login * @param string $password + * @param bool $checkSsl * @return array */ public function getToken(string $moodleUrl, string $login, string $password, bool $checkSsl): array { diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index a53d1cf..c270074 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -2,38 +2,27 @@ namespace OCA\Moodle\Settings; use OCP\AppFramework\Http\TemplateResponse; -use OCP\IRequest; -use OCP\IL10N; +use OCP\AppFramework\Services\IInitialState; use OCP\IConfig; use OCP\Settings\ISettings; -use OCP\Util; -use OCP\IURLGenerator; -use OCP\IInitialStateService; use OCA\Moodle\AppInfo\Application; class Admin implements ISettings { - private $request; + /** + * @var IConfig + */ private $config; - private $dataDirPath; - private $urlGenerator; - private $l; + /** + * @var IInitialState + */ + private $initialStateService; - public function __construct(string $appName, - IL10N $l, - IRequest $request, - IConfig $config, - IURLGenerator $urlGenerator, - IInitialStateService $initialStateService, - $userId) { - $this->appName = $appName; - $this->urlGenerator = $urlGenerator; - $this->request = $request; - $this->l = $l; + public function __construct(IConfig $config, + IInitialState $initialStateService) { $this->config = $config; $this->initialStateService = $initialStateService; - $this->userId = $userId; } /** @@ -45,7 +34,7 @@ class Admin implements ISettings { $adminConfig = [ 'search_disabled' => $searchDisabled, ]; - $this->initialStateService->provideInitialState($this->appName, 'admin-config', $adminConfig); + $this->initialStateService->provideInitialState('admin-config', $adminConfig); return new TemplateResponse(Application::APP_ID, 'adminSettings'); } diff --git a/lib/Settings/AdminSection.php b/lib/Settings/AdminSection.php index f0b8bc8..b08f54d 100644 --- a/lib/Settings/AdminSection.php +++ b/lib/Settings/AdminSection.php @@ -13,13 +13,10 @@ class AdminSection implements IIconSection { /** @var IURLGenerator */ private $urlGenerator; - public function __construct(string $appName, - IURLGenerator $urlGenerator, - IL10N $l - ) { - $this->appName = $appName; - $this->l = $l; + public function __construct(IURLGenerator $urlGenerator, + IL10N $l) { $this->urlGenerator = $urlGenerator; + $this->l = $l; } /** @@ -57,4 +54,4 @@ class AdminSection implements IIconSection { return $this->urlGenerator->imagePath('core', 'categories/integration.svg'); } -} \ No newline at end of file +} diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php index 758a80e..856f5ec 100644 --- a/lib/Settings/Personal.php +++ b/lib/Settings/Personal.php @@ -2,51 +2,45 @@ namespace OCA\Moodle\Settings; use OCP\AppFramework\Http\TemplateResponse; -use OCP\IRequest; -use OCP\IL10N; +use OCP\AppFramework\Services\IInitialState; use OCP\IConfig; use OCP\Settings\ISettings; -use OCP\Util; -use OCP\IURLGenerator; -use OCP\IInitialStateService; use OCA\Moodle\AppInfo\Application; class Personal implements ISettings { - private $request; - private $config; - private $dataDirPath; - private $urlGenerator; - private $l; + /** + * @var IConfig + */ + private $config; + /** + * @var IInitialState + */ + private $initialStateService; + /** + * @var string|null + */ + private $userId; - public function __construct( - string $appName, - IL10N $l, - IRequest $request, - IConfig $config, - IURLGenerator $urlGenerator, - IInitialStateService $initialStateService, - $userId) { - $this->appName = $appName; - $this->urlGenerator = $urlGenerator; - $this->request = $request; - $this->l = $l; - $this->config = $config; - $this->initialStateService = $initialStateService; - $this->userId = $userId; - } + public function __construct(IConfig $config, + IInitialState $initialStateService, + ?string $userId) { + $this->config = $config; + $this->initialStateService = $initialStateService; + $this->userId = $userId; + } /** * @return TemplateResponse */ public function getForm(): TemplateResponse { - $token = $this->config->getUserValue($this->userId, Application::APP_ID, 'token', ''); - $url = $this->config->getUserValue($this->userId, Application::APP_ID, 'url', ''); + $token = $this->config->getUserValue($this->userId, Application::APP_ID, 'token'); + $url = $this->config->getUserValue($this->userId, Application::APP_ID, 'url'); $searchCoursesEnabled = $this->config->getUserValue($this->userId, Application::APP_ID, 'search_courses_enabled', '0'); $searchModulesEnabled = $this->config->getUserValue($this->userId, Application::APP_ID, 'search_modules_enabled', '0'); $searchUpcomingEnabled = $this->config->getUserValue($this->userId, Application::APP_ID, 'search_upcoming_enabled', '0'); - $userName = $this->config->getUserValue($this->userId, Application::APP_ID, 'user_name', ''); + $userName = $this->config->getUserValue($this->userId, Application::APP_ID, 'user_name'); $checkSsl = $this->config->getUserValue($this->userId, Application::APP_ID, 'check_ssl', '1') === '1'; $searchDisabled = $this->config->getAppValue(Application::APP_ID, 'search_disabled', '0') === '1'; @@ -61,7 +55,7 @@ class Personal implements ISettings { 'check_ssl' => $checkSsl, 'search_disabled' => $searchDisabled, ]; - $this->initialStateService->provideInitialState($this->appName, 'user-config', $userConfig); + $this->initialStateService->provideInitialState('user-config', $userConfig); return new TemplateResponse(Application::APP_ID, 'personalSettings'); } diff --git a/lib/Settings/PersonalSection.php b/lib/Settings/PersonalSection.php index ae55e69..0b497fd 100644 --- a/lib/Settings/PersonalSection.php +++ b/lib/Settings/PersonalSection.php @@ -7,54 +7,50 @@ use OCP\Settings\IIconSection; class PersonalSection implements IIconSection { - /** @var IL10N */ - private $l; + /** @var IL10N */ + private $l; - /** @var IURLGenerator */ - private $urlGenerator; + /** @var IURLGenerator */ + private $urlGenerator; - public function __construct(string $appName, - IURLGenerator $urlGenerator, - IL10N $l - ) { - $this->appName = $appName; - $this->l = $l; - $this->urlGenerator = $urlGenerator; - } + public function __construct(IURLGenerator $urlGenerator, + IL10N $l) { + $this->l = $l; + $this->urlGenerator = $urlGenerator; + } - /** - * returns the ID of the section. It is supposed to be a lower case string - * - * @returns string - */ - public function getID(): string { - return 'connected-accounts'; //or a generic id if feasible - } + /** + * returns the ID of the section. It is supposed to be a lower case string + * + * @returns string + */ + public function getID(): string { + return 'connected-accounts'; //or a generic id if feasible + } - /** - * returns the translated name as it should be displayed, e.g. 'LDAP / AD - * integration'. Use the L10N service to translate it. - * - * @return string - */ - public function getName(): string { - return $this->l->t('Connected accounts'); - } + /** + * returns the translated name as it should be displayed, e.g. 'LDAP / AD + * integration'. Use the L10N service to translate it. + * + * @return string + */ + public function getName(): string { + return $this->l->t('Connected accounts'); + } - /** - * @return int whether the form should be rather on the top or bottom of - * the settings navigation. The sections are arranged in ascending order of - * the priority values. It is required to return a value between 0 and 99. - */ - public function getPriority(): int { - return 80; - } + /** + * @return int whether the form should be rather on the top or bottom of + * the settings navigation. The sections are arranged in ascending order of + * the priority values. It is required to return a value between 0 and 99. + */ + public function getPriority(): int { + return 80; + } - /** - * @return ?string The relative path to a an icon describing the section - */ - public function getIcon(): ?string { - return $this->urlGenerator->imagePath('core', 'categories/integration.svg'); - } - -} \ No newline at end of file + /** + * @return ?string The relative path to a an icon describing the section + */ + public function getIcon(): ?string { + return $this->urlGenerator->imagePath('core', 'categories/integration.svg'); + } +}