11<?php
2+ declare (strict_types=1 );
23/**
34 * @copyright Copyright (c) 2016, ownCloud, Inc.
45 *
3435
3536namespace OC ;
3637
37-
3838use OCP \ICacheFactory ;
3939use OCP \IConfig ;
4040use OCP \IRequest ;
4141use OCP \IURLGenerator ;
42- use OCP \Route \IRoute ;
4342use RuntimeException ;
4443
4544/**
@@ -74,10 +73,9 @@ public function __construct(IConfig $config,
7473 *
7574 * Returns a url to the given route.
7675 */
77- public function linkToRoute ($ route , $ parameters = array ()) {
76+ public function linkToRoute (string $ route , array $ parameters = array ()): string {
7877 // TODO: mock router
79- $ urlLinkTo = \OC ::$ server ->getRouter ()->generate ($ route , $ parameters );
80- return $ urlLinkTo ;
78+ return \OC ::$ server ->getRouter ()->generate ($ route , $ parameters );
8179 }
8280
8381 /**
@@ -88,7 +86,7 @@ public function linkToRoute($route, $parameters = array()) {
8886 *
8987 * Returns an absolute url to the given route.
9088 */
91- public function linkToRouteAbsolute ($ routeName , $ arguments = array ()) {
89+ public function linkToRouteAbsolute (string $ routeName , array $ arguments = array ()): string {
9290 return $ this ->getAbsoluteURL ($ this ->linkToRoute ($ routeName , $ arguments ));
9391 }
9492
@@ -102,20 +100,20 @@ public function linkToRouteAbsolute($routeName, $arguments = array()) {
102100 *
103101 * Returns a url to the given app and file.
104102 */
105- public function linkTo ( $ app , $ file , $ args = array () ) {
103+ public function linkTo (string $ app , string $ file , array $ args = array ()): string {
106104 $ frontControllerActive = ($ this ->config ->getSystemValue ('htaccess.IgnoreFrontController ' , false ) === true || getenv ('front_controller_active ' ) === 'true ' );
107105
108- if ( $ app != '' ) {
106+ if ( $ app !== '' ) {
109107 $ app_path = \OC_App::getAppPath ($ app );
110108 // Check if the app is in the app folder
111109 if ($ app_path && file_exists ($ app_path . '/ ' . $ file )) {
112- if (substr ($ file , -3 ) == 'php ' ) {
110+ if (substr ($ file , -3 ) === 'php ' ) {
113111
114112 $ urlLinkTo = \OC ::$ WEBROOT . '/index.php/apps/ ' . $ app ;
115113 if ($ frontControllerActive ) {
116114 $ urlLinkTo = \OC ::$ WEBROOT . '/apps/ ' . $ app ;
117115 }
118- $ urlLinkTo .= ($ file != 'index.php ' ) ? '/ ' . $ file : '' ;
116+ $ urlLinkTo .= ($ file !== 'index.php ' ) ? '/ ' . $ file : '' ;
119117 } else {
120118 $ urlLinkTo = \OC_App::getAppWebPath ($ app ) . '/ ' . $ file ;
121119 }
@@ -150,7 +148,7 @@ public function linkTo( $app, $file, $args = array() ) {
150148 *
151149 * Returns the path to the image.
152150 */
153- public function imagePath ($ app , $ image ) {
151+ public function imagePath (string $ app , string $ image ): string {
154152 $ cache = $ this ->cacheFactory ->createDistributed ('imagePath- ' .md5 ($ this ->getBaseUrl ()).'- ' );
155153 $ cacheKey = $ app .'- ' .$ image ;
156154 if ($ key = $ cache ->get ($ cacheKey )) {
@@ -210,9 +208,9 @@ public function imagePath($app, $image) {
210208 if ($ path !== '' ) {
211209 $ cache ->set ($ cacheKey , $ path );
212210 return $ path ;
213- } else {
214- throw new RuntimeException ('image not found: image: ' . $ image . ' webroot: ' . \OC ::$ WEBROOT . ' serverroot: ' . \OC ::$ SERVERROOT );
215211 }
212+
213+ throw new RuntimeException ('image not found: image: ' . $ image . ' webroot: ' . \OC ::$ WEBROOT . ' serverroot: ' . \OC ::$ SERVERROOT );
216214 }
217215
218216
@@ -221,15 +219,15 @@ public function imagePath($app, $image) {
221219 * @param string $url the url in the ownCloud host
222220 * @return string the absolute version of the url
223221 */
224- public function getAbsoluteURL ($ url ) {
222+ public function getAbsoluteURL (string $ url ): string {
225223 $ separator = $ url [0 ] === '/ ' ? '' : '/ ' ;
226224
227- if (\OC ::$ CLI && !defined ('PHPUNIT_RUN ' )) {
225+ if (\OC ::$ CLI && !\ defined ('PHPUNIT_RUN ' )) {
228226 return rtrim ($ this ->config ->getSystemValue ('overwrite.cli.url ' ), '/ ' ) . '/ ' . ltrim ($ url , '/ ' );
229227 }
230228 // The ownCloud web root can already be prepended.
231- if (substr ($ url , 0 , strlen (\OC ::$ WEBROOT )) === \OC ::$ WEBROOT ) {
232- $ url = substr ($ url , strlen (\OC ::$ WEBROOT ));
229+ if (substr ($ url , 0 , \ strlen (\OC ::$ WEBROOT )) === \OC ::$ WEBROOT ) {
230+ $ url = substr ($ url , \ strlen (\OC ::$ WEBROOT ));
233231 }
234232
235233 return $ this ->getBaseUrl () . $ separator . $ url ;
@@ -239,15 +237,15 @@ public function getAbsoluteURL($url) {
239237 * @param string $key
240238 * @return string url to the online documentation
241239 */
242- public function linkToDocs ($ key ) {
240+ public function linkToDocs (string $ key ): string {
243241 $ theme = \OC ::$ server ->getThemingDefaults ();
244242 return $ theme ->buildDocLinkToKey ($ key );
245243 }
246244
247245 /**
248246 * @return string base url of the current request
249247 */
250- public function getBaseUrl () {
248+ public function getBaseUrl (): string {
251249 return $ this ->request ->getServerProtocol () . ':// ' . $ this ->request ->getServerHost () . \OC ::$ WEBROOT ;
252250 }
253251}
0 commit comments