Added more type-hints for "App" classes

This commit is contained in:
Roland Häder 2022-06-16 16:49:43 +02:00
parent 42b04f397b
commit 1edc6b3c3b
5 changed files with 42 additions and 34 deletions

View File

@ -78,7 +78,7 @@ class Arguments
/**
* @return string The whole command of this call
*/
public function getCommand()
public function getCommand(): string
{
return $this->command;
}
@ -94,7 +94,7 @@ class Arguments
/**
* @return array All arguments of this call
*/
public function getArgv()
public function getArgv(): array
{
return $this->argv;
}
@ -102,7 +102,7 @@ class Arguments
/**
* @return string The used HTTP method
*/
public function getMethod()
public function getMethod(): string
{
return $this->method;
}
@ -110,7 +110,7 @@ class Arguments
/**
* @return int The count of arguments of this call
*/
public function getArgc()
public function getArgc(): int
{
return $this->argc;
}
@ -145,7 +145,7 @@ class Arguments
*
* @return bool if the argument position exists
*/
public function has(int $position)
public function has(int $position): bool
{
return array_key_exists($position, $this->argv);
}
@ -158,7 +158,7 @@ class Arguments
*
* @return Arguments The determined arguments
*/
public function determine(array $server, array $get)
public function determine(array $server, array $get): Arguments
{
// removing leading / - maybe a nginx problem
$server['QUERY_STRING'] = ltrim($server['QUERY_STRING'] ?? '', '/');

View File

@ -107,7 +107,7 @@ class BaseURL
*
* @return string
*/
public function getHostname()
public function getHostname(): string
{
return $this->hostname;
}
@ -117,7 +117,7 @@ class BaseURL
*
* @return string
*/
public function getScheme()
public function getScheme(): string
{
return $this->scheme;
}
@ -127,7 +127,7 @@ class BaseURL
*
* @return int
*/
public function getSSLPolicy()
public function getSSLPolicy(): int
{
return $this->sslPolicy;
}
@ -137,7 +137,7 @@ class BaseURL
*
* @return string
*/
public function getUrlPath()
public function getUrlPath(): string
{
return $this->urlPath;
}
@ -151,7 +151,7 @@ class BaseURL
*
* @return string
*/
public function get($ssl = false)
public function get(bool $ssl = false): string
{
if ($this->sslPolicy === self::SSL_POLICY_SELFSIGN && $ssl) {
return Network::switchScheme($this->url);
@ -168,8 +168,9 @@ class BaseURL
* @param string? $urlPath
*
* @return bool true, if successful
* @TODO Find proper types
*/
public function save($hostname = null, $sslPolicy = null, $urlPath = null)
public function save($hostname = null, $sslPolicy = null, $urlPath = null): bool
{
$currHostname = $this->hostname;
$currSSLPolicy = $this->sslPolicy;
@ -224,11 +225,11 @@ class BaseURL
/**
* Save the current url as base URL
*
* @param $url
* @param string $url
*
* @return bool true, if the save was successful
*/
public function saveByURL($url)
public function saveByURL(string $url): bool
{
$parsed = @parse_url($url);
@ -421,7 +422,7 @@ class BaseURL
*
* @return string The cleaned url
*/
public function remove(string $origURL)
public function remove(string $origURL): string
{
// Remove the hostname from the url if it is an internal link
$nurl = Strings::normaliseLink($origURL);
@ -445,7 +446,7 @@ class BaseURL
*
* @throws HTTPException\InternalServerErrorException In Case the given URL is not relative to the Friendica node
*/
public function redirect($toUrl = '', $ssl = false)
public function redirect(string $toUrl = '', bool $ssl = false)
{
if (!empty(parse_url($toUrl, PHP_URL_SCHEME))) {
throw new HTTPException\InternalServerErrorException("'$toUrl is not a relative path, please use System::externalRedirectTo");
@ -458,8 +459,8 @@ class BaseURL
/**
* Returns the base url as string
*/
public function __toString()
public function __toString(): string
{
return $this->get();
return (string) $this->get();
}
}

View File

@ -130,7 +130,7 @@ class Mode
*
* @throws \Exception
*/
public function determine(BasePath $basepath, Database $database, Cache $configCache)
public function determine(BasePath $basepath, Database $database, Cache $configCache): Mode
{
$mode = 0;
@ -178,7 +178,7 @@ class Mode
*
* @return Mode returns the determined mode
*/
public function determineRunMode(bool $isBackend, array $server, Arguments $args, MobileDetect $mobileDetect)
public function determineRunMode(bool $isBackend, array $server, Arguments $args, MobileDetect $mobileDetect): Mode
{
foreach (self::BACKEND_CONTENT_TYPES as $type) {
if (strpos(strtolower($server['HTTP_ACCEPT'] ?? ''), $type) !== false) {
@ -201,7 +201,7 @@ class Mode
*
* @return bool returns true, if the mode is set
*/
public function has($mode)
public function has(int $mode): bool
{
return ($this->mode & $mode) > 0;
}
@ -227,7 +227,7 @@ class Mode
*
* @return int Execution Mode
*/
public function getExecutor()
public function getExecutor(): int
{
return $this->executor;
}
@ -235,9 +235,9 @@ class Mode
/**
* Install mode is when the local config file is missing or the DB schema hasn't been installed yet.
*
* @return bool
* @return bool Whether installation mode is active (local/database configuration files present or not)
*/
public function isInstall()
public function isInstall(): bool
{
return !$this->has(Mode::LOCALCONFIGPRESENT) ||
!$this->has(MODE::DBCONFIGAVAILABLE);
@ -248,7 +248,7 @@ class Mode
*
* @return bool
*/
public function isNormal()
public function isNormal(): bool
{
return $this->has(Mode::LOCALCONFIGPRESENT) &&
$this->has(Mode::DBAVAILABLE) &&
@ -261,7 +261,7 @@ class Mode
*
* @return bool Is it a backend call
*/
public function isBackend()
public function isBackend(): bool
{
return $this->isBackend;
}
@ -271,7 +271,7 @@ class Mode
*
* @return bool true if it was an AJAX request
*/
public function isAjax()
public function isAjax(): bool
{
return $this->isAjax;
}
@ -281,7 +281,7 @@ class Mode
*
* @return bool true if it was an mobile request
*/
public function isMobile()
public function isMobile(): bool
{
return $this->isMobile;
}
@ -291,7 +291,7 @@ class Mode
*
* @return bool true if it was an tablet request
*/
public function isTablet()
public function isTablet(): bool
{
return $this->isTablet;
}

View File

@ -195,7 +195,7 @@ class Page implements ArrayAccess
* @param string $media
* @see Page::initHead()
*/
public function registerStylesheet($path, string $media = 'screen')
public function registerStylesheet(string $path, string $media = 'screen')
{
$path = Network::appendQueryParam($path, ['v' => FRIENDICA_VERSION]);
@ -288,7 +288,7 @@ class Page implements ArrayAccess
*
* Taken from http://webcheatsheet.com/php/get_current_page_url.php
*/
private function curPageURL()
private function curPageURL(): string
{
$pageURL = 'http';
if (!empty($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on")) {

View File

@ -152,7 +152,7 @@ class Router
*
* @throws HTTPException\InternalServerErrorException In case of invalid configs
*/
public function loadRoutes(array $routes)
public function loadRoutes(array $routes): Router
{
$routeCollector = ($this->routeCollector ?? new RouteCollector(new Std(), new GroupCountBased()));
@ -166,6 +166,13 @@ class Router
return $this;
}
/**
* Adds multiple routes to a route collector
*
* @param RouteCollector $routeCollector Route collector instance
* @param array $routes Multiple routes to be added
* @throws HTTPException\InternalServerErrorException If route was wrong (somehow)
*/
private function addRoutes(RouteCollector $routeCollector, array $routes)
{
foreach ($routes as $route => $config) {
@ -221,7 +228,7 @@ class Router
*
* @return bool
*/
private function isRoute(array $config)
private function isRoute(array $config): bool
{
return
// The config array should at least have one entry
@ -253,7 +260,7 @@ class Router
* @throws HTTPException\MethodNotAllowedException If a rule matched but the method didn't
* @throws HTTPException\NotFoundException If no rule matched
*/
private function getModuleClass()
private function getModuleClass(): string
{
$cmd = $this->args->getCommand();
$cmd = '/' . ltrim($cmd, '/');