fix phpstan warnings in classes/plugin-template.php

This commit is contained in:
Andrew Dolgov 2021-11-13 18:26:11 +03:00
parent 70051742af
commit f2323bda81
2 changed files with 30 additions and 22 deletions

View File

@ -5,53 +5,57 @@ abstract class PluginTemplate {
/** @var PDO $pdo */ /** @var PDO $pdo */
protected $pdo; protected $pdo;
abstract function init(PluginHost $host); abstract function init(PluginHost $host) : void;
abstract function about(); /** @return array<float|string|bool> */
abstract function about() : array;
// return array(1.0, "plugin", "No description", "No author", false); // return array(1.0, "plugin", "No description", "No author", false);
function __construct() { function __construct() {
$this->pdo = Db::pdo(); $this->pdo = Db::pdo();
} }
function flags() { /** @return array<string,int> */
function flags() : array {
/* associative array, possible keys: /* associative array, possible keys:
needs_curl = boolean needs_curl = boolean
*/ */
return array(); return array();
} }
function is_public_method($method) { function is_public_method(string $method) : bool {
return false; return false;
} }
function csrf_ignore($method) { function csrf_ignore(string $method) : bool {
return false; return false;
} }
function get_js() { function get_js() : string {
return ""; return "";
} }
function get_prefs_js() { function get_prefs_js() : string {
return ""; return "";
} }
function api_version() { function api_version() : int {
return Plugin::API_VERSION_COMPAT; return Plugin::API_VERSION_COMPAT;
} }
/* gettext-related helpers */ /* gettext-related helpers */
function __($msgid) { function __(string $msgid) : string {
/** @var Plugin $this -- this is a strictly template-related hack */
return _dgettext(PluginHost::object_to_domain($this), $msgid); return _dgettext(PluginHost::object_to_domain($this), $msgid);
} }
function _ngettext($singular, $plural, $number) { function _ngettext(string $singular, string $plural, int $number) : string {
/** @var Plugin $this -- this is a strictly template-related hack */
return _dngettext(PluginHost::object_to_domain($this), $singular, $plural, $number); return _dngettext(PluginHost::object_to_domain($this), $singular, $plural, $number);
} }
function T_sprintf() { function T_sprintf() : string {
$args = func_get_args(); $args = func_get_args();
$msgid = array_shift($args); $msgid = array_shift($args);

View File

@ -5,53 +5,57 @@ abstract class Plugin {
/** @var PDO $pdo */ /** @var PDO $pdo */
protected $pdo; protected $pdo;
abstract function init(PluginHost $host); abstract function init(PluginHost $host) : void;
abstract function about(); /** @return array<float|string|bool> */
abstract function about() : array;
// return array(1.0, "plugin", "No description", "No author", false); // return array(1.0, "plugin", "No description", "No author", false);
function __construct() { function __construct() {
$this->pdo = Db::pdo(); $this->pdo = Db::pdo();
} }
function flags() { /** @return array<string,int> */
function flags() : array {
/* associative array, possible keys: /* associative array, possible keys:
needs_curl = boolean needs_curl = boolean
*/ */
return array(); return array();
} }
function is_public_method($method) { function is_public_method(string $method) : bool {
return false; return false;
} }
function csrf_ignore($method) { function csrf_ignore(string $method) : bool {
return false; return false;
} }
function get_js() { function get_js() : string {
return ""; return "";
} }
function get_prefs_js() { function get_prefs_js() : string {
return ""; return "";
} }
function api_version() { function api_version() : int {
return Plugin::API_VERSION_COMPAT; return Plugin::API_VERSION_COMPAT;
} }
/* gettext-related helpers */ /* gettext-related helpers */
function __($msgid) { function __(string $msgid) : string {
/** @var Plugin $this -- this is a strictly template-related hack */
return _dgettext(PluginHost::object_to_domain($this), $msgid); return _dgettext(PluginHost::object_to_domain($this), $msgid);
} }
function _ngettext($singular, $plural, $number) { function _ngettext(string $singular, string $plural, int $number) : string {
/** @var Plugin $this -- this is a strictly template-related hack */
return _dngettext(PluginHost::object_to_domain($this), $singular, $plural, $number); return _dngettext(PluginHost::object_to_domain($this), $singular, $plural, $number);
} }
function T_sprintf() { function T_sprintf() : string {
$args = func_get_args(); $args = func_get_args();
$msgid = array_shift($args); $msgid = array_shift($args);