diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php index f7d80d41b4fa6..c72c225517974 100644 --- a/lib/private/URLGenerator.php +++ b/lib/private/URLGenerator.php @@ -1,4 +1,5 @@ getRouter()->generate($route, $parameters); - return $urlLinkTo; + return \OC::$server->getRouter()->generate($route, $parameters); } /** @@ -88,7 +86,7 @@ public function linkToRoute($route, $parameters = array()) { * * Returns an absolute url to the given route. */ - public function linkToRouteAbsolute($routeName, $arguments = array()) { + public function linkToRouteAbsolute(string $routeName, array $arguments = array()): string { return $this->getAbsoluteURL($this->linkToRoute($routeName, $arguments)); } @@ -102,20 +100,20 @@ public function linkToRouteAbsolute($routeName, $arguments = array()) { * * Returns a url to the given app and file. */ - public function linkTo( $app, $file, $args = array() ) { + public function linkTo(string $app, string $file, array $args = array()): string { $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); - if( $app != '' ) { + if( $app !== '' ) { $app_path = \OC_App::getAppPath($app); // Check if the app is in the app folder if ($app_path && file_exists($app_path . '/' . $file)) { - if (substr($file, -3) == 'php') { + if (substr($file, -3) === 'php') { $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app; if ($frontControllerActive) { $urlLinkTo = \OC::$WEBROOT . '/apps/' . $app; } - $urlLinkTo .= ($file != 'index.php') ? '/' . $file : ''; + $urlLinkTo .= ($file !== 'index.php') ? '/' . $file : ''; } else { $urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file; } @@ -150,7 +148,7 @@ public function linkTo( $app, $file, $args = array() ) { * * Returns the path to the image. */ - public function imagePath($app, $image) { + public function imagePath(string $app, string $image): string { $cache = $this->cacheFactory->createDistributed('imagePath-'.md5($this->getBaseUrl()).'-'); $cacheKey = $app.'-'.$image; if($key = $cache->get($cacheKey)) { @@ -210,9 +208,9 @@ public function imagePath($app, $image) { if($path !== '') { $cache->set($cacheKey, $path); return $path; - } else { - throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT); } + + throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT); } @@ -221,15 +219,15 @@ public function imagePath($app, $image) { * @param string $url the url in the ownCloud host * @return string the absolute version of the url */ - public function getAbsoluteURL($url) { + public function getAbsoluteURL(string $url): string { $separator = $url[0] === '/' ? '' : '/'; - if (\OC::$CLI && !defined('PHPUNIT_RUN')) { + if (\OC::$CLI && !\defined('PHPUNIT_RUN')) { return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/'); } // The ownCloud web root can already be prepended. - if(substr($url, 0, strlen(\OC::$WEBROOT)) === \OC::$WEBROOT) { - $url = substr($url, strlen(\OC::$WEBROOT)); + if(substr($url, 0, \strlen(\OC::$WEBROOT)) === \OC::$WEBROOT) { + $url = substr($url, \strlen(\OC::$WEBROOT)); } return $this->getBaseUrl() . $separator . $url; @@ -239,7 +237,7 @@ public function getAbsoluteURL($url) { * @param string $key * @return string url to the online documentation */ - public function linkToDocs($key) { + public function linkToDocs(string $key): string { $theme = \OC::$server->getThemingDefaults(); return $theme->buildDocLinkToKey($key); } @@ -247,7 +245,7 @@ public function linkToDocs($key) { /** * @return string base url of the current request */ - public function getBaseUrl() { + public function getBaseUrl(): string { return $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . \OC::$WEBROOT; } } diff --git a/lib/public/IURLGenerator.php b/lib/public/IURLGenerator.php index 944029914e805..ebf35967551cc 100644 --- a/lib/public/IURLGenerator.php +++ b/lib/public/IURLGenerator.php @@ -1,4 +1,5 @@ defaults = $this->createMock(Defaults::class); + $this->defaults->method('getLogo') + ->willReturn('myLogo'); $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->l10n = $this->createMock(IL10N::class); $this->mailer = $this->createMock(IMailer::class);