A free, self-hostable news aggregator…
Fix types for extensions (#5901)
Alexandre Alapetite76cbfadcdfdc
diff --git a/.dockerignore b/.dockerignoreindex 9f71b21bb..296253d4d 100644--- a/.dockerignore+++ b/.dockerignore@@ -2,5 +2,7 @@/bin//data//docs/+/extensions/node_modules/+/extensions/vendor//node_modules//vendor/diff --git a/.eslintignore b/.eslintignoreindex a87ce6da9..055d0035c 100644--- a/.eslintignore+++ b/.eslintignore@@ -1,5 +1,5 @@-*.min.js.git/+*.min.jsextensions/node_modules/p/scripts/vendor/diff --git a/.gitignore b/.gitignoreindex 76cec5ad2..2eff18708 100644--- a/.gitignore+++ b/.gitignore@@ -1,4 +1,6 @@/bin/+/extensions/node_modules/+/extensions/vendor//node_modules//vendor//data.back/diff --git a/.jshintignore b/.jshintignoreindex 6b43fb14f..cce6c8b81 100644--- a/.jshintignore+++ b/.jshintignore@@ -1,4 +1,5 @@.git/+extensions/node_modules/p/scripts/bcrypt.min.jsp/scripts/vendor/diff --git a/.markdownlintignore b/.markdownlintignoreindex fa771b056..f89df1470 100644--- a/.markdownlintignore+++ b/.markdownlintignore@@ -1,4 +1,5 @@.git/+extensions/lib/marienfressinaud/lib/phpgt/lib/phpmailer/diff --git a/app/Controllers/authController.php b/app/Controllers/authController.phpindex 73a640748..06eca7d9e 100644--- a/app/Controllers/authController.php+++ b/app/Controllers/authController.php@@ -246,4 +246,15 @@ class FreshRSS_auth_Controller extends FreshRSS_ActionController {$this->view->preferred_language = Minz_Translate::getLanguage(null, Minz_Request::getPreferredLanguages(), FreshRSS_Context::$system_conf->language);FreshRSS_View::prependTitle(_t('gen.auth.registration.title') . ' · ');}++ public static function getLogoutUrl(): string {+ if (($_SERVER['AUTH_TYPE'] ?? '') === 'openid-connect') {+ $url_string = urlencode(Minz_Request::guessBaseUrl());+ return './oidc/?logout=' . $url_string . '/';+ # The trailing slash is necessary so that we don’t redirect to http://.+ # https://bz.apache.org/bugzilla/show_bug.cgi?id=61355#c13+ } else {+ return _url('auth', 'logout') ?: '';+ }+ }}diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.phpindex 5d402fa67..6dd36dd72 100644--- a/app/Controllers/javascriptController.php+++ b/app/Controllers/javascriptController.php@@ -5,7 +5,6 @@ class FreshRSS_javascript_Controller extends FreshRSS_ActionController {/*** @var FreshRSS_ViewJavascript- * @phpstan-ignore-next-line*/protected $view;diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.phpindex 6e6a2720f..6be9040e9 100644--- a/app/Controllers/statsController.php+++ b/app/Controllers/statsController.php@@ -8,7 +8,6 @@ class FreshRSS_stats_Controller extends FreshRSS_ActionController {/*** @var FreshRSS_ViewStats- * @phpstan-ignore-next-line*/protected $view;diff --git a/app/Mailers/UserMailer.php b/app/Mailers/UserMailer.phpindex 6e54caa4b..a78ab9b32 100644--- a/app/Mailers/UserMailer.php+++ b/app/Mailers/UserMailer.php@@ -8,7 +8,6 @@ class FreshRSS_User_Mailer extends Minz_Mailer {/*** @var FreshRSS_View- * @phpstan-ignore-next-line*/protected $view;diff --git a/app/Models/ActionController.php b/app/Models/ActionController.phpindex a840ccc6d..69ee72b52 100644--- a/app/Models/ActionController.php+++ b/app/Models/ActionController.php@@ -5,7 +5,6 @@ class FreshRSS_ActionController extends Minz_ActionController {/*** @var FreshRSS_View- * @phpstan-ignore-next-line*/protected $view;}diff --git a/app/layout/aside_configure.phtml b/app/layout/aside_configure.phtmlindex 1b2f0076e..b59293f21 100644--- a/app/layout/aside_configure.phtml+++ b/app/layout/aside_configure.phtml@@ -1,16 +1,5 @@<?phpdeclare(strict_types=1);-- function get_logout_url(): string {- if (($_SERVER['AUTH_TYPE'] ?? '') === 'openid-connect') {- $url_string = urlencode(Minz_Request::guessBaseUrl());- return './oidc/?logout=' . $url_string . '/';- # The trailing slash is necessary so that we don’t redirect to http://.- # https://bz.apache.org/bugzilla/show_bug.cgi?id=61355#c13- } else {- return _url('auth', 'logout') ?: '';- }- }?><nav class="nav nav-list aside" id="aside_feed"><a class="toggle_aside" href="#close"><?= _i('close') ?></a>@@ -23,7 +12,7 @@<a href="<?= _url('user', 'profile') ?>"><?= _t('gen.menu.user_profile') ?></a></li><li class="item">- <a class="signout" href="<?= get_logout_url() ?>">+ <a class="signout" href="<?= FreshRSS_auth_Controller::getLogoutUrl() ?>"><?phpecho _t('gen.auth.logout'); ?> <?= _i('logout') ?></a></li>diff --git a/lib/Minz/Extension.php b/lib/Minz/Extension.phpindex e227eb964..a8f883eb6 100644--- a/lib/Minz/Extension.php+++ b/lib/Minz/Extension.php@@ -164,7 +164,7 @@ abstract class Minz_Extension {* Return the url for a given file.** @param string $filename name of the file to serve.- * @param 'css'|'js' $type the type (js or css) of the file to serve.+ * @param 'css'|'js'|'svg' $type the type (js or css or svg) of the file to serve.* @param bool $isStatic indicates if the file is a static file or a user file. Default is static.* @return string url corresponding to the file.*/diff --git a/lib/Minz/Mailer.php b/lib/Minz/Mailer.phpindex bd5e97ceb..86c5c33da 100644--- a/lib/Minz/Mailer.php+++ b/lib/Minz/Mailer.php@@ -39,10 +39,18 @@ class Minz_Mailer {private int $debug_level;/**- * Constructor.+ * @phpstan-param class-string|'' $viewType+ * @param string $viewType Name of the class (inheriting from Minz_View) to use for the view model*/- public function __construct () {- $this->view = new Minz_View();+ public function __construct(string $viewType = '') {+ $view = null;+ if ($viewType !== '' && class_exists($viewType)) {+ $view = new $viewType();+ if (!($view instanceof Minz_View)) {+ $view = null;+ }+ }+ $this->view = $view ?? new Minz_View();$this->view->_layout(null);$this->view->attributeParams();diff --git a/lib/Minz/View.php b/lib/Minz/View.phpindex da6e55a23..f67cf6277 100644--- a/lib/Minz/View.php+++ b/lib/Minz/View.php@@ -157,7 +157,7 @@ class Minz_View {/*** Choose the current view layout.- * @param string|null $layout the layout name to use, false to use no layouts.+ * @param string|null $layout the layout name to use, null to use no layouts.*/public function _layout(?string $layout): void {if ($layout != null) {@@ -205,7 +205,7 @@ class Minz_View {*/public static function headStyle(): string {$styles = '';- foreach(self::$styles as $style) {+ foreach (self::$styles as $style) {$styles .= '<link rel="stylesheet" ' .($style['media'] === 'all' ? '' : 'media="' . $style['media'] . '" ') .'href="' . $style['url'] . '" />';@@ -220,10 +220,13 @@ class Minz_View {* @param bool $cond Conditional comment for IE, now deprecated and ignored @deprecated*/public static function prependStyle(string $url, string $media = 'all', bool $cond = false): void {- array_unshift (self::$styles, array (+ if ($url === '') {+ return;+ }+ array_unshift(self::$styles, ['url' => $url,'media' => $media,- ));+ ]);}/**@@ -233,10 +236,13 @@ class Minz_View {* @param bool $cond Conditional comment for IE, now deprecated and ignored @deprecated*/public static function appendStyle(string $url, string $media = 'all', bool $cond = false): void {- self::$styles[] = array (+ if ($url === '') {+ return;+ }+ self::$styles[] = ['url' => $url,'media' => $media,- );+ ];}/**@@ -298,12 +304,15 @@ class Minz_View {* @param string $id Add a script `id` attribute*/public static function prependScript(string $url, bool $cond = false, bool $defer = true, bool $async = true, string $id = ''): void {- array_unshift(self::$scripts, array (+ if ($url === '') {+ return;+ }+ array_unshift(self::$scripts, ['url' => $url,'defer' => $defer,'async' => $async,'id' => $id,- ));+ ]);}/**@@ -315,12 +324,15 @@ class Minz_View {* @param string $id Add a script `id` attribute*/public static function appendScript(string $url, bool $cond = false, bool $defer = true, bool $async = true, string $id = ''): void {- self::$scripts[] = array (+ if ($url === '') {+ return;+ }+ self::$scripts[] = ['url' => $url,'defer' => $defer,'async' => $async,'id' => $id,- );+ ];}/**diff --git a/phpcs.xml b/phpcs.xmlindex 838302e52..bc9610e6c 100644--- a/phpcs.xml+++ b/phpcs.xml@@ -11,6 +11,7 @@<exclude-pattern>./lib/http-conditional.php</exclude-pattern><exclude-pattern>./node_modules/</exclude-pattern><exclude-pattern>./data/config.php</exclude-pattern>+ <exclude-pattern>./data/update.php</exclude-pattern><exclude-pattern>./data/users/*/config.php</exclude-pattern><exclude-pattern>./extensions/</exclude-pattern><exclude-pattern>./p/scripts/vendor/</exclude-pattern>diff --git a/phpstan.neon b/phpstan.neonindex e9c37e44e..e262ad984 100644--- a/phpstan.neon+++ b/phpstan.neon@@ -16,6 +16,9 @@ parameters:- vendor/*analyseAndScan:- .git/*+ - extensions/node_modules+ - extensions/symbolic+ - extensions/vendor- node_modules/*bootstrapFiles:- cli/_cli.php@@ -32,6 +35,7 @@ parameters:- STDOUT- TMP_PATH- USERS_PATH+ reportMaybesInPropertyPhpDocTypes: falsestrictRules:allRules: falsebooleansInConditions: false # TODO pass