Fix types for extensions (#5901)

* Fix types for extensions
To accompany https://github.com/FreshRSS/Extensions/pull/185

* Avoid bug redeclared function
This commit is contained in:
Alexandre Alapetite 2023-11-24 14:50:03 +01:00 committed by GitHub
parent bc9ef0d188
commit 76cbfadcdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 58 additions and 31 deletions

View File

@ -2,5 +2,7 @@
/bin/
/data/
/docs/
/extensions/node_modules/
/extensions/vendor/
/node_modules/
/vendor/

View File

@ -1,5 +1,5 @@
*.min.js
.git/
*.min.js
extensions/
node_modules/
p/scripts/vendor/

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
/bin/
/extensions/node_modules/
/extensions/vendor/
/node_modules/
/vendor/
/data.back/

View File

@ -1,4 +1,5 @@
.git/
extensions/
node_modules/
p/scripts/bcrypt.min.js
p/scripts/vendor/

View File

@ -1,4 +1,5 @@
.git/
extensions/
lib/marienfressinaud/
lib/phpgt/
lib/phpmailer/

View File

@ -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 dont redirect to http://.
# https://bz.apache.org/bugzilla/show_bug.cgi?id=61355#c13
} else {
return _url('auth', 'logout') ?: '';
}
}
}

View File

@ -5,7 +5,6 @@ class FreshRSS_javascript_Controller extends FreshRSS_ActionController {
/**
* @var FreshRSS_ViewJavascript
* @phpstan-ignore-next-line
*/
protected $view;

View File

@ -8,7 +8,6 @@ class FreshRSS_stats_Controller extends FreshRSS_ActionController {
/**
* @var FreshRSS_ViewStats
* @phpstan-ignore-next-line
*/
protected $view;

View File

@ -8,7 +8,6 @@ class FreshRSS_User_Mailer extends Minz_Mailer {
/**
* @var FreshRSS_View
* @phpstan-ignore-next-line
*/
protected $view;

View File

@ -5,7 +5,6 @@ class FreshRSS_ActionController extends Minz_ActionController {
/**
* @var FreshRSS_View
* @phpstan-ignore-next-line
*/
protected $view;
}

View File

@ -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 dont 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>

View File

@ -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.
*/

View File

@ -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();

View File

@ -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,
);
];
}
/**

View File

@ -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>

View File

@ -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