Merge pull request #11852 from Quix0r/fixes/double-quotes-single

Fixes/double quotes single
This commit is contained in:
Philipp 2022-08-19 19:18:21 +02:00 committed by GitHub
commit 59b4f2e993
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 145 additions and 84 deletions

View File

@ -107,6 +107,7 @@ class ApiResponse extends Response
*
* @param array $arr Array to be passed to template
* @param int $cid Contact ID of template
*
* @return array
*/
private function addRSSValues(array $arr, int $cid): array
@ -149,6 +150,7 @@ class ApiResponse extends Response
case 'atom':
case 'xml':
return $this->createXML($data, $root_element);
case 'json':
default:
return $data;
@ -219,6 +221,7 @@ class ApiResponse extends Response
case 'xml':
$this->setType(static::TYPE_XML);
break;
case 'json':
$this->setType(static::TYPE_JSON);
if (!empty($return)) {
@ -229,9 +232,11 @@ class ApiResponse extends Response
$return = $json;
}
break;
case 'rss':
$this->setType(static::TYPE_RSS);
break;
case 'atom':
$this->setType(static::TYPE_ATOM);
break;

View File

@ -43,6 +43,7 @@ class Download extends \Friendica\BaseModule
/**
* @param array $request
*
* @return void
* @throws \Exception
*/
@ -52,7 +53,7 @@ class Download extends \Friendica\BaseModule
$etag = 'W/"' . $hash . '"';
if (trim($_SERVER['HTTP_IF_NONE_MATCH'] ?? '') == $etag) {
header("HTTP/1.1 304 Not Modified");
header('HTTP/1.1 304 Not Modified');
System::exit();
}

View File

@ -27,6 +27,7 @@ class Mimetype
* Return mimetype based on file extension
*
* @param string $filename filename
*
* @return mixed array or string
*/
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)
*
* @param string $url The URL to be validated
*
* @return string|boolean The actual working URL, false else
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
@ -259,6 +260,7 @@ class Network
*
* @param string $domain
* @param array $domain_list
*
* @return boolean
*/
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
*
* @param string $url Any user-submitted URL that may contain tracking params
*
* @return string The same URL stripped of tracking parameters
*/
public static function stripTrackingQueryParams(string $url): string
@ -350,9 +353,10 @@ class Network
*
* @param string $url
* @param string $basepath
*
* @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))) {
return $url;
@ -372,6 +376,7 @@ class Network
*
* @param string $url1
* @param string $url2
*
* @return string The matching part or empty string on error
*/
public static function getUrlMatch(string $url1, string $url2): string
@ -459,6 +464,7 @@ class Network
* Glue url parts together
*
* @param array $parsed URL parts
*
* @return string|null The glued URL or null on error
* @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
*
* @param string $uri
*
* @return string
*/
public static function convertToIdn(string $uri): string
@ -514,6 +521,7 @@ class Network
* Switch the scheme of an url between http and https
*
* @param string $url
*
* @return string Switched URL
*/
public static function switchScheme(string $url): string
@ -537,6 +545,7 @@ class Network
*
* @param string $path
* @param array $additionalParams Associative array of parameters
*
* @return string
*/
public static function appendQueryParam(string $path, array $additionalParams): string
@ -563,6 +572,7 @@ class Network
*
* @param string $etag The page etag
* @param string $last_modified The page last modification UTC date
*
* @return void
* @throws \Exception
*/
@ -601,6 +611,7 @@ class Network
* Check if the given URL is a local link
*
* @param string $url
*
* @return bool
*/
public static function isLocalLink(string $url): bool

View File

@ -187,7 +187,7 @@ class ParseUrl
* </body>
* @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)) {
return [
@ -645,6 +645,7 @@ class ParseUrl
* Convert tags from CSV to an array
*
* @param string $string Tags
*
* @return array with formatted Hashtags
*/
public static function convertTagsToArray(string $string): array
@ -666,6 +667,7 @@ class ParseUrl
*
* @param string $tag The pure tag name
* @param int $k Counter for internal use
*
* @return void
*/
private static function arrAddHashes(string &$tag, int $k)
@ -729,6 +731,7 @@ class ParseUrl
*
* @param array $siteinfo
* @param array $jsonld
*
* @return array siteinfo
*/
private static function parseParts(array $siteinfo, array $jsonld): array
@ -774,6 +777,7 @@ class ParseUrl
*
* @param array $siteinfo
* @param array $jsonld
*
* @return array siteinfo
*/
private static function parseJsonLd(array $siteinfo, array $jsonld): array
@ -867,6 +871,7 @@ class ParseUrl
*
* @param array $siteinfo
* @param array $jsonld
*
* @return array siteinfo
*/
private static function parseJsonLdAuthor(array $siteinfo, array $jsonld): array
@ -951,6 +956,7 @@ class ParseUrl
*
* @param array $siteinfo
* @param array $jsonld
*
* @return array siteinfo
*/
private static function parseJsonLdArticle(array $siteinfo, array $jsonld): array
@ -1021,6 +1027,7 @@ class ParseUrl
*
* @param array $siteinfo
* @param array $jsonld
*
* @return array siteinfo
*/
private static function parseJsonLdWebPage(array $siteinfo, array $jsonld): array
@ -1060,6 +1067,7 @@ class ParseUrl
*
* @param array $siteinfo
* @param array $jsonld
*
* @return array siteinfo
*/
private static function parseJsonLdWebSite(array $siteinfo, array $jsonld): array
@ -1098,6 +1106,7 @@ class ParseUrl
*
* @param array $siteinfo
* @param array $jsonld
*
* @return array siteinfo
*/
private static function parseJsonLdWebOrganization(array $siteinfo, array $jsonld): array
@ -1144,6 +1153,7 @@ class ParseUrl
*
* @param array $siteinfo
* @param array $jsonld
*
* @return array siteinfo
*/
private static function parseJsonLdWebPerson(array $siteinfo, array $jsonld): array
@ -1189,6 +1199,7 @@ class ParseUrl
*
* @param array $siteinfo
* @param array $jsonld
*
* @return array siteinfo
*/
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
*/
static private function pidFromFile($file) {
private static function pidFromFile(string $file)
{
if (!file_exists($file)) {
return false;
}
@ -48,7 +49,8 @@ class PidFile
*
* @return boolean Is it running?
*/
static public function isRunningProcess($file) {
public static function isRunningProcess(string $file): bool
{
$pid = self::pidFromFile($file);
if (!$pid) {
@ -72,7 +74,8 @@ class PidFile
*
* @return boolean Was it killed successfully?
*/
static public function killProcess($file) {
public static function killProcess(string $file): bool
{
$pid = self::pidFromFile($file);
// 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
*/
static public function create(string $file)
public static function create(string $file)
{
$pid = self::pidFromFile($file);
@ -120,7 +123,7 @@ class PidFile
*
* @return boolean Is it running?
*/
static public function delete(string $file): bool
public static function delete(string $file): bool
{
return @unlink($file);
}

View File

@ -61,7 +61,7 @@ class Profiler implements ContainerInterface
*
* @return bool
*/
public function isRendertime()
public function isRendertime(): bool
{
return $this->rendertime;
}
@ -91,6 +91,7 @@ class Profiler implements ContainerInterface
* Start a profiler recording
*
* @param string $value
*
* @return void
*/
public function startRecording(string $value)
@ -106,6 +107,7 @@ class Profiler implements ContainerInterface
* Stop a profiler recording
*
* @param string $callstack
*
* @return void
*/
public function stopRecording(string $callstack = '')
@ -147,8 +149,10 @@ class Profiler implements ContainerInterface
* @param int $timestamp the Timestamp
* @param string $value A value to profile
* @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) {
return;
@ -176,6 +180,8 @@ class Profiler implements ContainerInterface
/**
* Resets the performance and callstack profiling
*
* @return void
*/
public function reset()
{
@ -185,6 +191,8 @@ class Profiler implements ContainerInterface
/**
* Resets the performance profiling data
*
* @return void
*/
public function resetPerformance()
{
@ -209,6 +217,8 @@ class Profiler implements ContainerInterface
/**
* Resets the callstack profiling data
*
* @return void
*/
public function resetCallstack()
{
@ -229,7 +239,7 @@ class Profiler implements ContainerInterface
*
* @return string the rendertime
*/
public function getRendertimeString(float $limit = 0)
public function getRendertimeString(float $limit = 0): string
{
$output = '';
@ -237,58 +247,62 @@ class Profiler implements ContainerInterface
return $output;
}
if (isset($this->callstack["database"])) {
if (isset($this->callstack['database'])) {
$output .= "\nDatabase Read:\n";
foreach ($this->callstack["database"] as $func => $time) {
foreach ($this->callstack['database'] as $func => $time) {
$time = round($time, 3);
if ($time > $limit) {
$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";
$output .= $func . ': ' . $time . "\n";
}
}
}
if (isset($this->callstack["rendering"])) {
$output .= "\nRendering:\n";
foreach ($this->callstack["rendering"] as $func => $time) {
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";
$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 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');
$logger->info(
@ -338,7 +354,7 @@ class Profiler implements ContainerInterface
*
* @return int Entry.
*/
public function get($id)
public function get(string $id): int
{
if (!$this->has($id)) {
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;
}
@ -363,7 +379,7 @@ class Profiler implements ContainerInterface
*
* @return bool
*/
public function has($id)
public function has(string $id): bool
{
return isset($this->performance[$id]);
}

View File

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

View File

@ -33,6 +33,7 @@ class Strings
* Generates a pseudo-random string of hexadecimal characters
*
* @param int $size Size of string (default: 64)
*
* @return string Pseudo-random string
* @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 $url The contact url
*
* @return string Formatted network name
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
@ -341,7 +343,8 @@ class Strings
* Check if the trimmed provided string is starting with one of the provided characters
*
* @param string $string
* @param array $chars
* @param array $chars
*
* @return 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
* @param string $string
* @param string $end
*
* @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 $return;
return (substr_compare($string, $end, -strlen($end)) === 0);
}
/**
@ -413,8 +415,9 @@ class Strings
/**
* Ensures a single path item doesn't contain any path-traversing characters
*
* @see https://stackoverflow.com/a/46097713
* @param string $pathItem
*
* @see https://stackoverflow.com/a/46097713
* @return string
*/
public static function sanitizeFilePathItem(string $pathItem): string
@ -436,6 +439,7 @@ class Strings
* @param string $replacement
* @param int $start
* @param int|null $length
*
* @return string
* @see substr_replace()
*/
@ -474,6 +478,7 @@ class Strings
* @param string $text
* @param string $regex
* @param callable $callback
*
* @return 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 $b
*
* @return int
*/
private static function timezoneCompareCallback($a, $b)
private static function timezoneCompareCallback(string $a, string $b): int
{
if (strstr($a, '/') && strstr($b, '/')) {
if (DI::l10n()->t($a) == DI::l10n()->t($b)) {
@ -63,9 +64,10 @@ class Temporal
* Emit a timezone selector grouped (primarily) by continent
*
* @param string $current Timezone
*
* @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();
@ -120,7 +122,7 @@ class Temporal
* @return string Parsed HTML
* @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 = str_replace('<select id="timezone_select" name="timezone">', '', $options);
@ -137,10 +139,11 @@ class Temporal
*
* @param string $dob Date of Birth
* @param string $timezone
*
* @return string Formatted HTML
* @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');
@ -182,7 +185,7 @@ class Temporal
* @return string Parsed HTML output.
* @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, '', '');
}
@ -197,7 +200,7 @@ class Temporal
* @return string Parsed HTML output.
* @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);
}
@ -227,12 +230,12 @@ class Temporal
DateTime $maxDate,
DateTime $defaultDate = null,
$label,
$id = 'datetimepicker',
$pickdate = true,
$picktime = true,
$minfrom = '',
$maxfrom = '',
$required = false)
string $id = 'datetimepicker',
bool $pickdate = true,
bool $picktime = true,
string $minfrom = '',
string $maxfrom = '',
bool $required = false): string
{
// First day of the week (0 = Sunday)
$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
if (!in_array($lang,
["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"])) {
['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'])) {
$lang = 'en';
}
@ -308,7 +311,7 @@ class Temporal
*
* @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';
@ -330,13 +333,14 @@ class Temporal
$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')],
7 * 24 * 60 * 60 => [DI::l10n()->t('week'), DI::l10n()->t('weeks')],
24 * 60 * 60 => [DI::l10n()->t('day'), DI::l10n()->t('days')],
60 * 60 => [DI::l10n()->t('hour'), DI::l10n()->t('hours')],
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) {
@ -395,7 +399,7 @@ class Temporal
*
* @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));
}
@ -411,7 +415,7 @@ class Temporal
* @return string day 0 = Sunday through 6 = Saturday
* @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));
@ -436,7 +440,7 @@ class Temporal
* @throws \Exception
* @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.
$mtab = [' ',