diff options
| author | 2023-11-24 14:50:03 +0100 | |
|---|---|---|
| committer | 2023-11-24 14:50:03 +0100 | |
| commit | 76cbfadcdfdcbf675b83f6162a229938aca3bbe1 (patch) | |
| tree | 01aa96c6774dcf2a692fd3062ae1ffccb0a8bfa0 | |
| parent | bc9ef0d188fa43d4a4d06835f74e2d94799b65c6 (diff) | |
Fix types for extensions (#5901)
* Fix types for extensions
To accompany https://github.com/FreshRSS/Extensions/pull/185
* Avoid bug redeclared function
| -rw-r--r-- | .dockerignore | 2 | ||||
| -rw-r--r-- | .eslintignore | 2 | ||||
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | .jshintignore | 1 | ||||
| -rw-r--r-- | .markdownlintignore | 1 | ||||
| -rw-r--r-- | app/Controllers/authController.php | 11 | ||||
| -rw-r--r-- | app/Controllers/javascriptController.php | 1 | ||||
| -rw-r--r-- | app/Controllers/statsController.php | 1 | ||||
| -rw-r--r-- | app/Mailers/UserMailer.php | 1 | ||||
| -rw-r--r-- | app/Models/ActionController.php | 1 | ||||
| -rw-r--r-- | app/layout/aside_configure.phtml | 13 | ||||
| -rw-r--r-- | lib/Minz/Extension.php | 2 | ||||
| -rw-r--r-- | lib/Minz/Mailer.php | 14 | ||||
| -rw-r--r-- | lib/Minz/View.php | 32 | ||||
| -rw-r--r-- | phpcs.xml | 1 | ||||
| -rw-r--r-- | phpstan.neon | 4 |
16 files changed, 58 insertions, 31 deletions
diff --git a/.dockerignore b/.dockerignore index 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/.eslintignore index a87ce6da9..055d0035c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,5 @@ -*.min.js .git/ +*.min.js extensions/ node_modules/ p/scripts/vendor/ diff --git a/.gitignore b/.gitignore index 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/.jshintignore index 6b43fb14f..cce6c8b81 100644 --- a/.jshintignore +++ b/.jshintignore @@ -1,4 +1,5 @@ .git/ +extensions/ node_modules/ p/scripts/bcrypt.min.js p/scripts/vendor/ diff --git a/.markdownlintignore b/.markdownlintignore index 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.php index 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.php index 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.php index 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.php index 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.php index 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.phtml index 1b2f0076e..b59293f21 100644 --- a/app/layout/aside_configure.phtml +++ b/app/layout/aside_configure.phtml @@ -1,16 +1,5 @@ <?php declare(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() ?>"> <?php echo _t('gen.auth.logout'); ?> <?= _i('logout') ?></a> </li> diff --git a/lib/Minz/Extension.php b/lib/Minz/Extension.php index 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.php index 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.php index 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, - ); + ]; } /** @@ -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.neon index 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: false strictRules: allRules: false booleansInConditions: false # TODO pass |
