- added missing type-hints
- first access level, then static
- reformatted code following code-style
This commit is contained in:
Roland Häder 2022-08-18 22:05:00 +02:00
parent b3906326a4
commit 4c6940583a
No known key found for this signature in database
GPG Key ID: C82EDE5DDFA0BA77
8 changed files with 138 additions and 83 deletions

View File

@ -27,6 +27,7 @@ class Mimetype
* Return mimetype based on file extension * Return mimetype based on file extension
* *
* @param string $filename filename * @param string $filename filename
*
* @return mixed array or string * @return mixed array or string
*/ */
public static function getContentType(string $filename) public static function getContentType(string $filename)

View File

@ -50,6 +50,7 @@ class Network
* and check DNS to see if it's real (or check if is a valid IP address) * and check DNS to see if it's real (or check if is a valid IP address)
* *
* @param string $url The URL to be validated * @param string $url The URL to be validated
*
* @return string|boolean The actual working URL, false else * @return string|boolean The actual working URL, false else
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
@ -259,6 +260,7 @@ class Network
* *
* @param string $domain * @param string $domain
* @param array $domain_list * @param array $domain_list
*
* @return boolean * @return boolean
*/ */
public static function isDomainAllowed(string $domain, array $domain_list): bool public static function isDomainAllowed(string $domain, array $domain_list): bool
@ -297,6 +299,7 @@ class Network
* Remove Google Analytics and other tracking platforms params from URL * Remove Google Analytics and other tracking platforms params from URL
* *
* @param string $url Any user-submitted URL that may contain tracking params * @param string $url Any user-submitted URL that may contain tracking params
*
* @return string The same URL stripped of tracking parameters * @return string The same URL stripped of tracking parameters
*/ */
public static function stripTrackingQueryParams(string $url): string public static function stripTrackingQueryParams(string $url): string
@ -350,9 +353,10 @@ class Network
* *
* @param string $url * @param string $url
* @param string $basepath * @param string $basepath
*
* @return string url * @return string url
*/ */
public static function addBasePath(string $url, string $basepath) public static function addBasePath(string $url, string $basepath): string
{ {
if (!empty(parse_url($url, PHP_URL_SCHEME)) || empty(parse_url($basepath, PHP_URL_SCHEME)) || empty($url) || empty(parse_url($url))) { if (!empty(parse_url($url, PHP_URL_SCHEME)) || empty(parse_url($basepath, PHP_URL_SCHEME)) || empty($url) || empty(parse_url($url))) {
return $url; return $url;
@ -372,6 +376,7 @@ class Network
* *
* @param string $url1 * @param string $url1
* @param string $url2 * @param string $url2
*
* @return string The matching part or empty string on error * @return string The matching part or empty string on error
*/ */
public static function getUrlMatch(string $url1, string $url2): string public static function getUrlMatch(string $url1, string $url2): string
@ -459,6 +464,7 @@ class Network
* Glue url parts together * Glue url parts together
* *
* @param array $parsed URL parts * @param array $parsed URL parts
*
* @return string|null The glued URL or null on error * @return string|null The glued URL or null on error
* @deprecated since version 2021.12, use GuzzleHttp\Psr7\Uri::fromParts($parts) instead * @deprecated since version 2021.12, use GuzzleHttp\Psr7\Uri::fromParts($parts) instead
*/ */
@ -490,6 +496,7 @@ class Network
* Convert an URI to an IDN compatible URI * Convert an URI to an IDN compatible URI
* *
* @param string $uri * @param string $uri
*
* @return string * @return string
*/ */
public static function convertToIdn(string $uri): string public static function convertToIdn(string $uri): string
@ -514,6 +521,7 @@ class Network
* Switch the scheme of an url between http and https * Switch the scheme of an url between http and https
* *
* @param string $url * @param string $url
*
* @return string Switched URL * @return string Switched URL
*/ */
public static function switchScheme(string $url): string public static function switchScheme(string $url): string
@ -537,6 +545,7 @@ class Network
* *
* @param string $path * @param string $path
* @param array $additionalParams Associative array of parameters * @param array $additionalParams Associative array of parameters
*
* @return string * @return string
*/ */
public static function appendQueryParam(string $path, array $additionalParams): string public static function appendQueryParam(string $path, array $additionalParams): string
@ -563,6 +572,7 @@ class Network
* *
* @param string $etag The page etag * @param string $etag The page etag
* @param string $last_modified The page last modification UTC date * @param string $last_modified The page last modification UTC date
*
* @return void * @return void
* @throws \Exception * @throws \Exception
*/ */
@ -601,6 +611,7 @@ class Network
* Check if the given URL is a local link * Check if the given URL is a local link
* *
* @param string $url * @param string $url
*
* @return bool * @return bool
*/ */
public static function isLocalLink(string $url): bool public static function isLocalLink(string $url): bool

View File

@ -187,7 +187,7 @@ class ParseUrl
* </body> * </body>
* @endverbatim * @endverbatim
*/ */
public static function getSiteinfo(string $url, bool $do_oembed = true, int $count = 1) public static function getSiteinfo(string $url, bool $do_oembed = true, int $count = 1): array
{ {
if (empty($url)) { if (empty($url)) {
return [ return [
@ -645,6 +645,7 @@ class ParseUrl
* Convert tags from CSV to an array * Convert tags from CSV to an array
* *
* @param string $string Tags * @param string $string Tags
*
* @return array with formatted Hashtags * @return array with formatted Hashtags
*/ */
public static function convertTagsToArray(string $string): array public static function convertTagsToArray(string $string): array
@ -666,6 +667,7 @@ class ParseUrl
* *
* @param string $tag The pure tag name * @param string $tag The pure tag name
* @param int $k Counter for internal use * @param int $k Counter for internal use
*
* @return void * @return void
*/ */
private static function arrAddHashes(string &$tag, int $k) private static function arrAddHashes(string &$tag, int $k)
@ -729,6 +731,7 @@ class ParseUrl
* *
* @param array $siteinfo * @param array $siteinfo
* @param array $jsonld * @param array $jsonld
*
* @return array siteinfo * @return array siteinfo
*/ */
private static function parseParts(array $siteinfo, array $jsonld): array private static function parseParts(array $siteinfo, array $jsonld): array
@ -774,6 +777,7 @@ class ParseUrl
* *
* @param array $siteinfo * @param array $siteinfo
* @param array $jsonld * @param array $jsonld
*
* @return array siteinfo * @return array siteinfo
*/ */
private static function parseJsonLd(array $siteinfo, array $jsonld): array private static function parseJsonLd(array $siteinfo, array $jsonld): array
@ -867,6 +871,7 @@ class ParseUrl
* *
* @param array $siteinfo * @param array $siteinfo
* @param array $jsonld * @param array $jsonld
*
* @return array siteinfo * @return array siteinfo
*/ */
private static function parseJsonLdAuthor(array $siteinfo, array $jsonld): array private static function parseJsonLdAuthor(array $siteinfo, array $jsonld): array
@ -951,6 +956,7 @@ class ParseUrl
* *
* @param array $siteinfo * @param array $siteinfo
* @param array $jsonld * @param array $jsonld
*
* @return array siteinfo * @return array siteinfo
*/ */
private static function parseJsonLdArticle(array $siteinfo, array $jsonld): array private static function parseJsonLdArticle(array $siteinfo, array $jsonld): array
@ -1021,6 +1027,7 @@ class ParseUrl
* *
* @param array $siteinfo * @param array $siteinfo
* @param array $jsonld * @param array $jsonld
*
* @return array siteinfo * @return array siteinfo
*/ */
private static function parseJsonLdWebPage(array $siteinfo, array $jsonld): array private static function parseJsonLdWebPage(array $siteinfo, array $jsonld): array
@ -1060,6 +1067,7 @@ class ParseUrl
* *
* @param array $siteinfo * @param array $siteinfo
* @param array $jsonld * @param array $jsonld
*
* @return array siteinfo * @return array siteinfo
*/ */
private static function parseJsonLdWebSite(array $siteinfo, array $jsonld): array private static function parseJsonLdWebSite(array $siteinfo, array $jsonld): array
@ -1098,6 +1106,7 @@ class ParseUrl
* *
* @param array $siteinfo * @param array $siteinfo
* @param array $jsonld * @param array $jsonld
*
* @return array siteinfo * @return array siteinfo
*/ */
private static function parseJsonLdWebOrganization(array $siteinfo, array $jsonld): array private static function parseJsonLdWebOrganization(array $siteinfo, array $jsonld): array
@ -1144,6 +1153,7 @@ class ParseUrl
* *
* @param array $siteinfo * @param array $siteinfo
* @param array $jsonld * @param array $jsonld
*
* @return array siteinfo * @return array siteinfo
*/ */
private static function parseJsonLdWebPerson(array $siteinfo, array $jsonld): array private static function parseJsonLdWebPerson(array $siteinfo, array $jsonld): array
@ -1189,6 +1199,7 @@ class ParseUrl
* *
* @param array $siteinfo * @param array $siteinfo
* @param array $jsonld * @param array $jsonld
*
* @return array siteinfo * @return array siteinfo
*/ */
private static function parseJsonLdMediaObject(array $siteinfo, array $jsonld, string $name): array private static function parseJsonLdMediaObject(array $siteinfo, array $jsonld, string $name): array

View File

@ -33,7 +33,8 @@ class PidFile
* *
* @return boolean|string PID or "false" if not existent * @return boolean|string PID or "false" if not existent
*/ */
static private function pidFromFile($file) { private static function pidFromFile(string $file)
{
if (!file_exists($file)) { if (!file_exists($file)) {
return false; return false;
} }
@ -48,7 +49,8 @@ class PidFile
* *
* @return boolean Is it running? * @return boolean Is it running?
*/ */
static public function isRunningProcess($file) { public static function isRunningProcess(string $file): bool
{
$pid = self::pidFromFile($file); $pid = self::pidFromFile($file);
if (!$pid) { if (!$pid) {
@ -72,7 +74,8 @@ class PidFile
* *
* @return boolean Was it killed successfully? * @return boolean Was it killed successfully?
*/ */
static public function killProcess($file) { public static function killProcess(string $file): bool
{
$pid = self::pidFromFile($file); $pid = self::pidFromFile($file);
// We don't have a process id? then we quit // We don't have a process id? then we quit
@ -97,7 +100,7 @@ class PidFile
* *
* @return boolean|string PID or "false" if not created * @return boolean|string PID or "false" if not created
*/ */
static public function create(string $file) public static function create(string $file)
{ {
$pid = self::pidFromFile($file); $pid = self::pidFromFile($file);
@ -120,7 +123,7 @@ class PidFile
* *
* @return boolean Is it running? * @return boolean Is it running?
*/ */
static public function delete(string $file): bool public static function delete(string $file): bool
{ {
return @unlink($file); return @unlink($file);
} }

View File

@ -61,7 +61,7 @@ class Profiler implements ContainerInterface
* *
* @return bool * @return bool
*/ */
public function isRendertime() public function isRendertime(): bool
{ {
return $this->rendertime; return $this->rendertime;
} }
@ -91,6 +91,7 @@ class Profiler implements ContainerInterface
* Start a profiler recording * Start a profiler recording
* *
* @param string $value * @param string $value
*
* @return void * @return void
*/ */
public function startRecording(string $value) public function startRecording(string $value)
@ -106,6 +107,7 @@ class Profiler implements ContainerInterface
* Stop a profiler recording * Stop a profiler recording
* *
* @param string $callstack * @param string $callstack
*
* @return void * @return void
*/ */
public function stopRecording(string $callstack = '') public function stopRecording(string $callstack = '')
@ -147,8 +149,10 @@ class Profiler implements ContainerInterface
* @param int $timestamp the Timestamp * @param int $timestamp the Timestamp
* @param string $value A value to profile * @param string $value A value to profile
* @param string $callstack A callstack string, generated if absent * @param string $callstack A callstack string, generated if absent
*
* @return void
*/ */
public function saveTimestamp($timestamp, $value, $callstack = '') public function saveTimestamp(int $timestamp, string $value, string $callstack = '')
{ {
if (!$this->enabled) { if (!$this->enabled) {
return; return;
@ -176,6 +180,8 @@ class Profiler implements ContainerInterface
/** /**
* Resets the performance and callstack profiling * Resets the performance and callstack profiling
*
* @return void
*/ */
public function reset() public function reset()
{ {
@ -185,6 +191,8 @@ class Profiler implements ContainerInterface
/** /**
* Resets the performance profiling data * Resets the performance profiling data
*
* @return void
*/ */
public function resetPerformance() public function resetPerformance()
{ {
@ -209,6 +217,8 @@ class Profiler implements ContainerInterface
/** /**
* Resets the callstack profiling data * Resets the callstack profiling data
*
* @return void
*/ */
public function resetCallstack() public function resetCallstack()
{ {
@ -229,7 +239,7 @@ class Profiler implements ContainerInterface
* *
* @return string the rendertime * @return string the rendertime
*/ */
public function getRendertimeString(float $limit = 0) public function getRendertimeString(float $limit = 0): string
{ {
$output = ''; $output = '';
@ -237,58 +247,62 @@ class Profiler implements ContainerInterface
return $output; return $output;
} }
if (isset($this->callstack["database"])) { if (isset($this->callstack['database'])) {
$output .= "\nDatabase Read:\n"; $output .= "\nDatabase Read:\n";
foreach ($this->callstack["database"] as $func => $time) { foreach ($this->callstack['database'] as $func => $time) {
$time = round($time, 3); $time = round($time, 3);
if ($time > $limit) { if ($time > $limit) {
$output .= $func . ": " . $time . "\n"; $output .= $func . ': ' . $time . "\n";
}
}
}
if (isset($this->callstack["database_write"])) {
$output .= "\nDatabase Write:\n";
foreach ($this->callstack["database_write"] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
$output .= $func . ": " . $time . "\n";
}
}
}
if (isset($this->callstack["cache"])) {
$output .= "\nCache Read:\n";
foreach ($this->callstack["cache"] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
$output .= $func . ": " . $time . "\n";
}
}
}
if (isset($this->callstack["cache_write"])) {
$output .= "\nCache Write:\n";
foreach ($this->callstack["cache_write"] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
$output .= $func . ": " . $time . "\n";
}
}
}
if (isset($this->callstack["network"])) {
$output .= "\nNetwork:\n";
foreach ($this->callstack["network"] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
$output .= $func . ": " . $time . "\n";
} }
} }
} }
if (isset($this->callstack["rendering"])) { if (isset($this->callstack['database_write'])) {
$output .= "\nRendering:\n"; $output .= "\nDatabase Write:\n";
foreach ($this->callstack["rendering"] as $func => $time) { foreach ($this->callstack['database_write'] as $func => $time) {
$time = round($time, 3); $time = round($time, 3);
if ($time > $limit) { if ($time > $limit) {
$output .= $func . ": " . $time . "\n"; $output .= $func . ': ' . $time . "\n";
}
}
}
if (isset($this->callstack['cache'])) {
$output .= "\nCache Read:\n";
foreach ($this->callstack['cache'] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
$output .= $func . ': ' . $time . "\n";
}
}
}
if (isset($this->callstack['cache_write'])) {
$output .= "\nCache Write:\n";
foreach ($this->callstack['cache_write'] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
$output .= $func . ': ' . $time . "\n";
}
}
}
if (isset($this->callstack['network'])) {
$output .= "\nNetwork:\n";
foreach ($this->callstack['network'] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
$output .= $func . ': ' . $time . "\n";
}
}
}
if (isset($this->callstack['rendering'])) {
$output .= "\nRendering:\n";
foreach ($this->callstack['rendering'] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
$output .= $func . ': ' . $time . "\n";
} }
} }
} }
@ -301,8 +315,10 @@ class Profiler implements ContainerInterface
* *
* @param LoggerInterface $logger The logger to save the current log * @param LoggerInterface $logger The logger to save the current log
* @param string $message Additional message for the log * @param string $message Additional message for the log
*
* @return void
*/ */
public function saveLog(LoggerInterface $logger, $message = '') public function saveLog(LoggerInterface $logger, string $message = '')
{ {
$duration = microtime(true) - $this->get('start'); $duration = microtime(true) - $this->get('start');
$logger->info( $logger->info(
@ -338,7 +354,7 @@ class Profiler implements ContainerInterface
* *
* @return int Entry. * @return int Entry.
*/ */
public function get($id) public function get(string $id): int
{ {
if (!$this->has($id)) { if (!$this->has($id)) {
return 0; return 0;
@ -347,7 +363,7 @@ class Profiler implements ContainerInterface
} }
} }
public function set($timestamp, $id) public function set($timestamp, string $id)
{ {
$this->performance[$id] = $timestamp; $this->performance[$id] = $timestamp;
} }
@ -363,7 +379,7 @@ class Profiler implements ContainerInterface
* *
* @return bool * @return bool
*/ */
public function has($id) public function has(string $id): bool
{ {
return isset($this->performance[$id]); return isset($this->performance[$id]);
} }

View File

@ -132,6 +132,7 @@ class Proxy
* proxy storage directory. * proxy storage directory.
* *
* @param string $html Un-proxified HTML code * @param string $html Un-proxified HTML code
*
* @return string Proxified HTML code * @return string Proxified HTML code
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
@ -146,6 +147,7 @@ class Proxy
* Checks if the URL is a local URL. * Checks if the URL is a local URL.
* *
* @param string $url * @param string $url
*
* @return boolean * @return boolean
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
@ -166,6 +168,7 @@ class Proxy
* Return the array of query string parameters from a URL * Return the array of query string parameters from a URL
* *
* @param string $url URL to parse * @param string $url URL to parse
*
* @return array Associative array of query string parameters * @return array Associative array of query string parameters
*/ */
private static function parseQuery(string $url): array private static function parseQuery(string $url): array
@ -182,6 +185,7 @@ class Proxy
* Call-back method to replace the UR * Call-back method to replace the UR
* *
* @param array $matches Matches from preg_replace_callback() * @param array $matches Matches from preg_replace_callback()
*
* @return string Proxified HTML image tag * @return string Proxified HTML image tag
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */

View File

@ -33,6 +33,7 @@ class Strings
* Generates a pseudo-random string of hexadecimal characters * Generates a pseudo-random string of hexadecimal characters
* *
* @param int $size Size of string (default: 64) * @param int $size Size of string (default: 64)
*
* @return string Pseudo-random string * @return string Pseudo-random string
* @throws \Exception * @throws \Exception
*/ */
@ -159,6 +160,7 @@ class Strings
* *
* @param string $network Network name of the contact (e.g. dfrn, rss and so on) * @param string $network Network name of the contact (e.g. dfrn, rss and so on)
* @param string $url The contact url * @param string $url The contact url
*
* @return string Formatted network name * @return string Formatted network name
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
@ -342,6 +344,7 @@ class Strings
* *
* @param string $string * @param string $string
* @param array $chars * @param array $chars
*
* @return bool * @return bool
*/ */
public static function startsWithChars(string $string, array $chars): bool public static function startsWithChars(string $string, array $chars): bool
@ -372,13 +375,12 @@ class Strings
* @see http://maettig.com/code/php/php-performance-benchmarks.php#endswith * @see http://maettig.com/code/php/php-performance-benchmarks.php#endswith
* @param string $string * @param string $string
* @param string $end * @param string $end
*
* @return bool * @return bool
*/ */
public static function endsWith(string $string, string $end): string public static function endsWith(string $string, string $end): bool
{ {
$return = substr_compare($string, $end, -strlen($end)) === 0; return (substr_compare($string, $end, -strlen($end)) === 0);
return $return;
} }
/** /**
@ -413,8 +415,9 @@ class Strings
/** /**
* Ensures a single path item doesn't contain any path-traversing characters * Ensures a single path item doesn't contain any path-traversing characters
* *
* @see https://stackoverflow.com/a/46097713
* @param string $pathItem * @param string $pathItem
*
* @see https://stackoverflow.com/a/46097713
* @return string * @return string
*/ */
public static function sanitizeFilePathItem(string $pathItem): string public static function sanitizeFilePathItem(string $pathItem): string
@ -436,6 +439,7 @@ class Strings
* @param string $replacement * @param string $replacement
* @param int $start * @param int $start
* @param int|null $length * @param int|null $length
*
* @return string * @return string
* @see substr_replace() * @see substr_replace()
*/ */
@ -474,6 +478,7 @@ class Strings
* @param string $text * @param string $text
* @param string $regex * @param string $regex
* @param callable $callback * @param callable $callback
*
* @return string * @return string
*/ */
public static function performWithEscapedBlocks(string $text, string $regex, callable $callback): string public static function performWithEscapedBlocks(string $text, string $regex, callable $callback): string

View File

@ -37,9 +37,10 @@ class Temporal
* *
* @param string $a * @param string $a
* @param string $b * @param string $b
*
* @return int * @return int
*/ */
private static function timezoneCompareCallback($a, $b) private static function timezoneCompareCallback(string $a, string $b): int
{ {
if (strstr($a, '/') && strstr($b, '/')) { if (strstr($a, '/') && strstr($b, '/')) {
if (DI::l10n()->t($a) == DI::l10n()->t($b)) { if (DI::l10n()->t($a) == DI::l10n()->t($b)) {
@ -63,9 +64,10 @@ class Temporal
* Emit a timezone selector grouped (primarily) by continent * Emit a timezone selector grouped (primarily) by continent
* *
* @param string $current Timezone * @param string $current Timezone
*
* @return string Parsed HTML output * @return string Parsed HTML output
*/ */
public static function getTimezoneSelect($current = 'America/Los_Angeles') public static function getTimezoneSelect(string $current = 'America/Los_Angeles'): string
{ {
$timezone_identifiers = DateTimeZone::listIdentifiers(); $timezone_identifiers = DateTimeZone::listIdentifiers();
@ -120,7 +122,7 @@ class Temporal
* @return string Parsed HTML * @return string Parsed HTML
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function getTimezoneField($name = 'timezone', $label = '', $current = 'America/Los_Angeles', $help = '') public static function getTimezoneField(string $name = 'timezone', string $label = '', string $current = 'America/Los_Angeles', string $help = ''): string
{ {
$options = self::getTimezoneSelect($current); $options = self::getTimezoneSelect($current);
$options = str_replace('<select id="timezone_select" name="timezone">', '', $options); $options = str_replace('<select id="timezone_select" name="timezone">', '', $options);
@ -137,10 +139,11 @@ class Temporal
* *
* @param string $dob Date of Birth * @param string $dob Date of Birth
* @param string $timezone * @param string $timezone
*
* @return string Formatted HTML * @return string Formatted HTML
* @throws \Exception * @throws \Exception
*/ */
public static function getDateofBirthField(string $dob, string $timezone = 'UTC') public static function getDateofBirthField(string $dob, string $timezone = 'UTC'): string
{ {
list($year, $month, $day) = sscanf($dob, '%4d-%2d-%2d'); list($year, $month, $day) = sscanf($dob, '%4d-%2d-%2d');
@ -182,7 +185,7 @@ class Temporal
* @return string Parsed HTML output. * @return string Parsed HTML output.
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function getDateField($min, $max, $default, $id = 'datepicker') public static function getDateField(DateTime $min, DateTime $max, DateTime $default, string $id = 'datepicker'): string
{ {
return self::getDateTimeField($min, $max, $default, '', $id, true, false, '', ''); return self::getDateTimeField($min, $max, $default, '', $id, true, false, '', '');
} }
@ -197,7 +200,7 @@ class Temporal
* @return string Parsed HTML output. * @return string Parsed HTML output.
* @throws \Exception * @throws \Exception
*/ */
public static function getTimeField($h, $m, $id = 'timepicker') public static function getTimeField(string $h, string $m, string $id = 'timepicker'): string
{ {
return self::getDateTimeField(new DateTime(), new DateTime(), new DateTime("$h:$m"), '', $id, false, true); return self::getDateTimeField(new DateTime(), new DateTime(), new DateTime("$h:$m"), '', $id, false, true);
} }
@ -227,12 +230,12 @@ class Temporal
DateTime $maxDate, DateTime $maxDate,
DateTime $defaultDate = null, DateTime $defaultDate = null,
$label, $label,
$id = 'datetimepicker', string $id = 'datetimepicker',
$pickdate = true, bool $pickdate = true,
$picktime = true, bool $picktime = true,
$minfrom = '', string $minfrom = '',
$maxfrom = '', string $maxfrom = '',
$required = false) bool $required = false): string
{ {
// First day of the week (0 = Sunday) // First day of the week (0 = Sunday)
$firstDay = DI::pConfig()->get(local_user(), 'system', 'first_day_of_week', 0); $firstDay = DI::pConfig()->get(local_user(), 'system', 'first_day_of_week', 0);
@ -241,8 +244,8 @@ class Temporal
// Check if the detected language is supported by the picker // Check if the detected language is supported by the picker
if (!in_array($lang, if (!in_array($lang,
["ar", "ro", "id", "bg", "fa", "ru", "uk", "en", "el", "de", "nl", "tr", "fr", "es", "th", "pl", "pt", "ch", "se", "kr", ['ar', 'ro', 'id', 'bg', 'fa', 'ru', 'uk', 'en', 'el', 'de', 'nl', 'tr', 'fr', 'es', 'th', 'pl', 'pt', 'ch', 'se', 'kr',
"it", "da", "no", "ja", "vi", "sl", "cs", "hu"])) { 'it', 'da', 'no', 'ja', 'vi', 'sl', 'cs', 'hu'])) {
$lang = 'en'; $lang = 'en';
} }
@ -308,7 +311,7 @@ class Temporal
* *
* @return string with relative date * @return string with relative date
*/ */
public static function getRelativeDate($posted_date, $format = null) public static function getRelativeDate(string $posted_date, string $format = null): string
{ {
$localtime = $posted_date . ' UTC'; $localtime = $posted_date . ' UTC';
@ -330,13 +333,14 @@ class Temporal
$isfuture = true; $isfuture = true;
} }
$a = [12 * 30 * 24 * 60 * 60 => [DI::l10n()->t('year'), DI::l10n()->t('years')], $a = [
12 * 30 * 24 * 60 * 60 => [DI::l10n()->t('year'), DI::l10n()->t('years')],
30 * 24 * 60 * 60 => [DI::l10n()->t('month'), DI::l10n()->t('months')], 30 * 24 * 60 * 60 => [DI::l10n()->t('month'), DI::l10n()->t('months')],
7 * 24 * 60 * 60 => [DI::l10n()->t('week'), DI::l10n()->t('weeks')], 7 * 24 * 60 * 60 => [DI::l10n()->t('week'), DI::l10n()->t('weeks')],
24 * 60 * 60 => [DI::l10n()->t('day'), DI::l10n()->t('days')], 24 * 60 * 60 => [DI::l10n()->t('day'), DI::l10n()->t('days')],
60 * 60 => [DI::l10n()->t('hour'), DI::l10n()->t('hours')], 60 * 60 => [DI::l10n()->t('hour'), DI::l10n()->t('hours')],
60 => [DI::l10n()->t('minute'), DI::l10n()->t('minutes')], 60 => [DI::l10n()->t('minute'), DI::l10n()->t('minutes')],
1 => [DI::l10n()->t('second'), DI::l10n()->t('seconds')] 1 => [DI::l10n()->t('second'), DI::l10n()->t('seconds')],
]; ];
foreach ($a as $secs => $str) { foreach ($a as $secs => $str) {
@ -395,7 +399,7 @@ class Temporal
* *
* @return int Number of days in the given month * @return int Number of days in the given month
*/ */
public static function getDaysInMonth($y, $m) public static function getDaysInMonth(int $y, int $m): int
{ {
return date('t', mktime(0, 0, 0, $m, 1, $y)); return date('t', mktime(0, 0, 0, $m, 1, $y));
} }
@ -411,7 +415,7 @@ class Temporal
* @return string day 0 = Sunday through 6 = Saturday * @return string day 0 = Sunday through 6 = Saturday
* @throws \Exception * @throws \Exception
*/ */
private static function getFirstDayInMonth($y, $m) private static function getFirstDayInMonth(int $y, int $m): string
{ {
$d = sprintf('%04d-%02d-01 00:00', intval($y), intval($m)); $d = sprintf('%04d-%02d-01 00:00', intval($y), intval($m));
@ -436,7 +440,7 @@ class Temporal
* @throws \Exception * @throws \Exception
* @todo Provide (prev, next) links, define class variations for different size calendars * @todo Provide (prev, next) links, define class variations for different size calendars
*/ */
public static function getCalendarTable($y = 0, $m = 0, $links = null, $class = '') public static function getCalendarTable(int $y = 0, int $m = 0, array $links = null, string $class = ''): string
{ {
// month table - start at 1 to match human usage. // month table - start at 1 to match human usage.
$mtab = [' ', $mtab = [' ',