Merge branch 'feature/php84-explicit-nullable-params' into 'master'

Make implicitly nullable parameters explicitly nullable.

See merge request tt-rss/tt-rss!26
This commit is contained in:
Andrew Dolgov 2024-03-26 17:11:56 +00:00
commit 435c321caa
9 changed files with 26 additions and 26 deletions

View File

@ -15,11 +15,11 @@ class Counters {
}
/**
* @param array<int> $feed_ids
* @param array<int> $label_ids
* @param array<int>|null $feed_ids
* @param array<int>|null $label_ids
* @return array<int, array<string, int|string>>
*/
static function get_conditional(array $feed_ids = null, array $label_ids = null): array {
static function get_conditional(?array $feed_ids = null, ?array $label_ids = null): array {
return [
...self::get_global(),
...self::get_virt(),
@ -52,10 +52,10 @@ class Counters {
}
/**
* @param array<int> $cat_ids
* @param array<int>|null $cat_ids
* @return array<int, array<string, int|string>>
*/
private static function get_cats(array $cat_ids = null): array {
private static function get_cats(?array $cat_ids = null): array {
$ret = [];
/* Labels category */
@ -141,10 +141,10 @@ class Counters {
}
/**
* @param array<int> $feed_ids
* @param array<int>|null $feed_ids
* @return array<int, array<string, int|string>>
*/
private static function get_feeds(array $feed_ids = null): array {
private static function get_feeds(?array $feed_ids = null): array {
$span = Tracer::start(__METHOD__);
$ret = [];
@ -300,10 +300,10 @@ class Counters {
}
/**
* @param array<int> $label_ids
* @param array<int>|null $label_ids
* @return array<int, array<string, int|string>>
*/
static function get_labels(array $label_ids = null): array {
static function get_labels(?array $label_ids = null): array {
$span = Tracer::start(__METHOD__);
$ret = [];

View File

@ -2127,7 +2127,7 @@ class Feeds extends Handler_Protected {
$cat->delete();
}
static function _add_cat(string $title, int $owner_uid, int $parent_cat = null, int $order_id = 0): bool {
static function _add_cat(string $title, int $owner_uid, ?int $parent_cat = null, int $order_id = 0): bool {
$cat = ORM::for_table('ttrss_feed_categories')
->where('owner_uid', $owner_uid)

View File

@ -429,7 +429,7 @@ class PluginHost {
/**
* @param PluginHost::KIND_* $kind
*/
function load_all(int $kind, int $owner_uid = null, bool $skip_init = false): void {
function load_all(int $kind, ?int $owner_uid = null, bool $skip_init = false): void {
$span = Tracer::start(__METHOD__);
$span->setAttribute('func.args', json_encode(func_get_args()));
@ -447,7 +447,7 @@ class PluginHost {
/**
* @param PluginHost::KIND_* $kind
*/
function load(string $classlist, int $kind, int $owner_uid = null, bool $skip_init = false): void {
function load(string $classlist, int $kind, ?int $owner_uid = null, bool $skip_init = false): void {
$span = Tracer::start(__METHOD__);
$span->setAttribute('func.args', json_encode(func_get_args()));

View File

@ -1511,7 +1511,7 @@ class RSSUtils {
*
* @return array<int, array<string, string>> An array of filter action arrays with keys "type" and "param"
*/
static function get_article_filters(array $filters, string $title, string $content, string $link, string $author, array $tags, array &$matched_rules = null, array &$matched_filters = null): array {
static function get_article_filters(array $filters, string $title, string $content, string $link, string $author, array $tags, ?array &$matched_rules = null, ?array &$matched_filters = null): array {
$span = Tracer::start(__METHOD__);
$matches = array();

View File

@ -62,7 +62,7 @@ class Sanitizer {
*
* @return false|string The HTML, or false if an error occurred.
*/
public static function sanitize(string $str, ?bool $force_remove_images = false, int $owner = null, string $site_url = null, array $highlight_words = null, int $article_id = null) {
public static function sanitize(string $str, ?bool $force_remove_images = false, ?int $owner = null, ?string $site_url = null, ?array $highlight_words = null, ?int $article_id = null) {
$span = OpenTelemetry\API\Trace\Span::getCurrent();
$span->addEvent("Sanitizer::sanitize");

View File

@ -1,7 +1,7 @@
<?php
class TimeHelper {
static function smart_date_time(int $timestamp, int $tz_offset = 0, int $owner_uid = null, bool $eta_min = false): string {
static function smart_date_time(int $timestamp, int $tz_offset = 0, ?int $owner_uid = null, bool $eta_min = false): string {
if (!$owner_uid) $owner_uid = $_SESSION['uid'];
if ($eta_min && time() + $tz_offset - $timestamp < 3600) {
@ -21,7 +21,7 @@ class TimeHelper {
}
}
static function make_local_datetime(?string $timestamp, bool $long, int $owner_uid = null,
static function make_local_datetime(?string $timestamp, bool $long, ?int $owner_uid = null,
bool $no_smart_dt = false, bool $eta_min = false): string {
if (!$owner_uid) $owner_uid = $_SESSION['uid'];

View File

@ -58,7 +58,7 @@ class UserHelper {
}
}
static function authenticate(string $login = null, string $password = null, bool $check_only = false, string $service = null): bool {
static function authenticate(?string $login = null, ?string $password = null, bool $check_only = false, ?string $service = null): bool {
if (!Config::get(Config::SINGLE_USER_MODE)) {
$user_id = false;
$auth_module = false;
@ -130,7 +130,7 @@ class UserHelper {
}
}
static function load_user_plugins(int $owner_uid, PluginHost $pluginhost = null): void {
static function load_user_plugins(int $owner_uid, ?PluginHost $pluginhost = null): void {
if (!$pluginhost) $pluginhost = PluginHost::getInstance();

View File

@ -155,8 +155,8 @@
/**
* @param array<string, mixed> $attributes
*/
function select_feeds_cats(string $name, int $default_id = null, array $attributes = [],
bool $include_all_cats = true, string $root_id = null, int $nest_level = 0, string $id = ""): string {
function select_feeds_cats(string $name, ?int $default_id = null, array $attributes = [],
bool $include_all_cats = true, ?string $root_id = null, int $nest_level = 0, string $id = ""): string {
$ret = "";

View File

@ -41,7 +41,7 @@
*
* @deprecated by Prefs::get()
*/
function get_pref(string $pref_name, int $owner_uid = null) {
function get_pref(string $pref_name, ?int $owner_uid = null) {
return Prefs::get($pref_name, $owner_uid ? $owner_uid : $_SESSION["uid"], $_SESSION["profile"] ?? null);
}
@ -50,7 +50,7 @@
*
* @deprecated by Prefs::set()
*/
function set_pref(string $pref_name, $value, int $owner_uid = null, bool $strip_tags = true): bool {
function set_pref(string $pref_name, $value, ?int $owner_uid = null, bool $strip_tags = true): bool {
return Prefs::set($pref_name, $value, $owner_uid ? $owner_uid : $_SESSION["uid"], $_SESSION["profile"] ?? null, $strip_tags);
}
@ -212,7 +212,7 @@
*
* @return false|string The HTML, or false if an error occurred.
*/
function sanitize(string $str, bool $force_remove_images = false, int $owner = null, string $site_url = null, array $highlight_words = null, int $article_id = null) {
function sanitize(string $str, bool $force_remove_images = false, ?int $owner = null, ?string $site_url = null, ?array $highlight_words = null, ?int $article_id = null) {
return Sanitizer::sanitize($str, $force_remove_images, $owner, $site_url, $highlight_words, $article_id);
}
@ -251,17 +251,17 @@
}
/** @deprecated by UserHelper::authenticate() */
function authenticate_user(string $login = null, string $password = null, bool $check_only = false, string $service = null): bool {
function authenticate_user(?string $login = null, ?string $password = null, bool $check_only = false, ?string $service = null): bool {
return UserHelper::authenticate($login, $password, $check_only, $service);
}
/** @deprecated by TimeHelper::smart_date_time() */
function smart_date_time(int $timestamp, int $tz_offset = 0, int $owner_uid = null, bool $eta_min = false): string {
function smart_date_time(int $timestamp, int $tz_offset = 0, ?int $owner_uid = null, bool $eta_min = false): string {
return TimeHelper::smart_date_time($timestamp, $tz_offset, $owner_uid, $eta_min);
}
/** @deprecated by TimeHelper::make_local_datetime() */
function make_local_datetime(string $timestamp, bool $long, int $owner_uid = null, bool $no_smart_dt = false, bool $eta_min = false): string {
function make_local_datetime(string $timestamp, bool $long, ?int $owner_uid = null, bool $no_smart_dt = false, bool $eta_min = false): string {
return TimeHelper::make_local_datetime($timestamp, $long, $owner_uid, $no_smart_dt, $eta_min);
}