From 9c9cb1a6dbb8cc57923a6516bea451454a662622 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 28 Jul 2017 14:54:08 +0200 Subject: [PATCH] cleanup constructors Signed-off-by: Bjoern Schiessle --- .../lib/BackgroundJob/GetSharedSecret.php | 43 +++++++------------ .../lib/BackgroundJob/RequestSharedSecret.php | 43 ++++++++----------- 2 files changed, 33 insertions(+), 53 deletions(-) diff --git a/apps/federation/lib/BackgroundJob/GetSharedSecret.php b/apps/federation/lib/BackgroundJob/GetSharedSecret.php index 761ad951e7..d679fcb6aa 100644 --- a/apps/federation/lib/BackgroundJob/GetSharedSecret.php +++ b/apps/federation/lib/BackgroundJob/GetSharedSecret.php @@ -34,6 +34,7 @@ use OCA\Federation\TrustedServers; use OCP\AppFramework\Http; use OCP\BackgroundJob\IJobList; use OCP\Http\Client\IClient; +use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\ILogger; use OCP\IURLGenerator; @@ -82,7 +83,7 @@ class GetSharedSecret extends Job{ /** * RequestSharedSecret constructor. * - * @param IClient $httpClient + * @param IClientService $httpClientService * @param IURLGenerator $urlGenerator * @param IJobList $jobList * @param TrustedServers $trustedServers @@ -91,33 +92,21 @@ class GetSharedSecret extends Job{ * @param IDiscoveryService $ocsDiscoveryService */ public function __construct( - IClient $httpClient = null, - IURLGenerator $urlGenerator = null, - IJobList $jobList = null, - TrustedServers $trustedServers = null, - ILogger $logger = null, - DbHandler $dbHandler = null, - IDiscoveryService $ocsDiscoveryService = null + IClientService $httpClientService, + IURLGenerator $urlGenerator, + IJobList $jobList, + TrustedServers $trustedServers, + ILogger $logger, + DbHandler $dbHandler, + IDiscoveryService $ocsDiscoveryService ) { - $this->logger = $logger ? $logger : \OC::$server->getLogger(); - $this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient(); - $this->jobList = $jobList ? $jobList : \OC::$server->getJobList(); - $this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator(); - $this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation')); - $this->ocsDiscoveryService = $ocsDiscoveryService ? $ocsDiscoveryService : \OC::$server->query(\OCP\OCS\IDiscoveryService::class); - if ($trustedServers) { - $this->trustedServers = $trustedServers; - } else { - $this->trustedServers = new TrustedServers( - $this->dbHandler, - \OC::$server->getHTTPClientService(), - $this->logger, - $this->jobList, - \OC::$server->getSecureRandom(), - \OC::$server->getConfig(), - \OC::$server->getEventDispatcher() - ); - } + $this->logger = $logger; + $this->httpClient = $httpClientService->newClient(); + $this->jobList = $jobList; + $this->urlGenerator = $urlGenerator; + $this->dbHandler = $dbHandler; + $this->ocsDiscoveryService = $ocsDiscoveryService; + $this->trustedServers = $trustedServers; } /** diff --git a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php index 8a4bd8c499..0180c0dbf5 100644 --- a/apps/federation/lib/BackgroundJob/RequestSharedSecret.php +++ b/apps/federation/lib/BackgroundJob/RequestSharedSecret.php @@ -35,6 +35,7 @@ use OCA\Federation\TrustedServers; use OCP\AppFramework\Http; use OCP\BackgroundJob\IJobList; use OCP\Http\Client\IClient; +use OCP\Http\Client\IClientService; use OCP\ILogger; use OCP\IURLGenerator; use OCP\OCS\IDiscoveryService; @@ -82,40 +83,30 @@ class RequestSharedSecret extends Job { /** * RequestSharedSecret constructor. * - * @param IClient $httpClient + * @param IClientService $httpClientService * @param IURLGenerator $urlGenerator * @param IJobList $jobList * @param TrustedServers $trustedServers * @param DbHandler $dbHandler * @param IDiscoveryService $ocsDiscoveryService + * @param ILogger $logger */ public function __construct( - IClient $httpClient = null, - IURLGenerator $urlGenerator = null, - IJobList $jobList = null, - TrustedServers $trustedServers = null, - DbHandler $dbHandler = null, - IDiscoveryService $ocsDiscoveryService = null + IClientService $httpClientService, + IURLGenerator $urlGenerator, + IJobList $jobList, + TrustedServers $trustedServers, + DbHandler $dbHandler, + IDiscoveryService $ocsDiscoveryService, + ILogger $logger ) { - $this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient(); - $this->jobList = $jobList ? $jobList : \OC::$server->getJobList(); - $this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator(); - $this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation')); - $this->logger = \OC::$server->getLogger(); - $this->ocsDiscoveryService = $ocsDiscoveryService ? $ocsDiscoveryService : \OC::$server->query(\OCP\OCS\IDiscoveryService::class); - if ($trustedServers) { - $this->trustedServers = $trustedServers; - } else { - $this->trustedServers = new TrustedServers( - $this->dbHandler, - \OC::$server->getHTTPClientService(), - $this->logger, - $this->jobList, - \OC::$server->getSecureRandom(), - \OC::$server->getConfig(), - \OC::$server->getEventDispatcher() - ); - } + $this->httpClient = $httpClientService->newClient(); + $this->jobList = $jobList; + $this->urlGenerator = $urlGenerator; + $this->dbHandler = $dbHandler; + $this->logger = $logger; + $this->ocsDiscoveryService = $ocsDiscoveryService; + $this->trustedServers = $trustedServers; }