summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-01-14 14:10:21 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2018-01-14 21:18:48 +0100
commita3b33bea037278f1fab6e5c23f6ae6f092bcb407 (patch)
tree5645c682bb75e9f44c1131ba22da669364dff35e
parent2ed4bea18f207b6bb498cfa67e04652c3d5e69da (diff)
downloadnextcloud-server-a3b33bea037278f1fab6e5c23f6ae6f092bcb407.tar.gz
nextcloud-server-a3b33bea037278f1fab6e5c23f6ae6f092bcb407.zip
Make the URLGenerator strict
* Add scalar argument types * Add return types * Make strict * General phpstorm cleanup Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r--lib/private/URLGenerator.php36
-rw-r--r--lib/public/IURLGenerator.php23
-rw-r--r--tests/Settings/Mailer/NewUserMailHelperTest.php2
3 files changed, 27 insertions, 34 deletions
diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php
index f7d80d41b4f..c72c2255179 100644
--- a/lib/private/URLGenerator.php
+++ b/lib/private/URLGenerator.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -34,12 +35,10 @@
namespace OC;
-
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
-use OCP\Route\IRoute;
use RuntimeException;
/**
@@ -74,10 +73,9 @@ class URLGenerator implements IURLGenerator {
*
* Returns a url to the given route.
*/
- public function linkToRoute($route, $parameters = array()) {
+ public function linkToRoute(string $route, array $parameters = array()): string {
// TODO: mock router
- $urlLinkTo = \OC::$server->getRouter()->generate($route, $parameters);
- return $urlLinkTo;
+ return \OC::$server->getRouter()->generate($route, $parameters);
}
/**
@@ -88,7 +86,7 @@ class URLGenerator implements IURLGenerator {
*
* 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 @@ class URLGenerator implements IURLGenerator {
*
* 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 @@ class URLGenerator implements IURLGenerator {
*
* 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 @@ class URLGenerator implements IURLGenerator {
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 @@ class URLGenerator implements IURLGenerator {
* @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 @@ class URLGenerator implements IURLGenerator {
* @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 @@ class URLGenerator implements IURLGenerator {
/**
* @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 944029914e8..ebf35967551 100644
--- a/lib/public/IURLGenerator.php
+++ b/lib/public/IURLGenerator.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -24,14 +25,6 @@
*
*/
-/**
- * Public interface of ownCloud for apps to use.
- * URL generator interface
- *
- */
-
-// use OCP namespace for all classes that are considered public.
-// This means that they should be used by apps instead of the internal ownCloud classes
namespace OCP;
/**
@@ -46,7 +39,7 @@ interface IURLGenerator {
* @return string the url
* @since 6.0.0
*/
- public function linkToRoute($routeName, $arguments = array());
+ public function linkToRoute(string $routeName, array $arguments = array()): string;
/**
* Returns the absolute URL for a route
@@ -55,7 +48,7 @@ interface IURLGenerator {
* @return string the absolute url
* @since 8.0.0
*/
- public function linkToRouteAbsolute($routeName, $arguments = array());
+ public function linkToRouteAbsolute(string $routeName, array $arguments = array()): string;
/**
* Returns an URL for an image or file
@@ -66,7 +59,7 @@ interface IURLGenerator {
* @return string the url
* @since 6.0.0
*/
- public function linkTo($appName, $file, $args = array());
+ public function linkTo(string $appName, string $file, array $args = array()): string;
/**
* Returns the link to an image, like linkTo but only with prepending img/
@@ -75,7 +68,7 @@ interface IURLGenerator {
* @return string the url
* @since 6.0.0
*/
- public function imagePath($appName, $file);
+ public function imagePath(string $appName, string $file): string;
/**
@@ -84,18 +77,18 @@ interface IURLGenerator {
* @return string the absolute version of the url
* @since 6.0.0
*/
- public function getAbsoluteURL($url);
+ public function getAbsoluteURL(string $url): string;
/**
* @param string $key
* @return string url to the online documentation
* @since 8.0.0
*/
- public function linkToDocs($key);
+ public function linkToDocs(string $key): string;
/**
* @return string base url of the current request
* @since 13.0.0
*/
- public function getBaseUrl();
+ public function getBaseUrl(): string;
}
diff --git a/tests/Settings/Mailer/NewUserMailHelperTest.php b/tests/Settings/Mailer/NewUserMailHelperTest.php
index 84553cc9007..6d6c6bf15c6 100644
--- a/tests/Settings/Mailer/NewUserMailHelperTest.php
+++ b/tests/Settings/Mailer/NewUserMailHelperTest.php
@@ -60,6 +60,8 @@ class NewUserMailHelperTest extends TestCase {
parent::setUp();
$this->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);