Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix types for extensions #5901

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
/bin/
/data/
/docs/
/extensions/node_modules/
/extensions/vendor/
/node_modules/
/vendor/
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.min.js
.git/
*.min.js
extensions/
node_modules/
p/scripts/vendor/
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/bin/
/extensions/node_modules/
/extensions/vendor/
/node_modules/
/vendor/
/data.back/
Expand Down
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.git/
extensions/
node_modules/
p/scripts/bcrypt.min.js
p/scripts/vendor/
Expand Down
1 change: 1 addition & 0 deletions .markdownlintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.git/
extensions/
lib/marienfressinaud/
lib/phpgt/
lib/phpmailer/
Expand Down
11 changes: 11 additions & 0 deletions app/Controllers/authController.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,15 @@ public function registerAction(): void {
$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') ?: '';
}
}
}
1 change: 0 additions & 1 deletion app/Controllers/javascriptController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class FreshRSS_javascript_Controller extends FreshRSS_ActionController {

/**
* @var FreshRSS_ViewJavascript
* @phpstan-ignore-next-line
*/
protected $view;

Expand Down
1 change: 0 additions & 1 deletion app/Controllers/statsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class FreshRSS_stats_Controller extends FreshRSS_ActionController {

/**
* @var FreshRSS_ViewStats
* @phpstan-ignore-next-line
*/
protected $view;

Expand Down
1 change: 0 additions & 1 deletion app/Mailers/UserMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class FreshRSS_User_Mailer extends Minz_Mailer {

/**
* @var FreshRSS_View
* @phpstan-ignore-next-line
*/
protected $view;

Expand Down
1 change: 0 additions & 1 deletion app/Models/ActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class FreshRSS_ActionController extends Minz_ActionController {

/**
* @var FreshRSS_View
* @phpstan-ignore-next-line
*/
protected $view;
}
13 changes: 1 addition & 12 deletions app/layout/aside_configure.phtml
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion lib/Minz/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private function setType(string $type): void {
* 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.
*/
Expand Down
14 changes: 11 additions & 3 deletions lib/Minz/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
32 changes: 22 additions & 10 deletions lib/Minz/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function helperToString(string $helper): string {

/**
* 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) {
Expand Down Expand Up @@ -205,7 +205,7 @@ public static function appendTitle(string $title): void {
*/
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'] . '" />';
Expand All @@ -220,10 +220,13 @@ public static function headStyle(): string {
* @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,
));
]);
}

/**
Expand All @@ -233,10 +236,13 @@ public static function prependStyle(string $url, string $media = 'all', bool $co
* @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,
);
];
}

/**
Expand Down Expand Up @@ -298,12 +304,15 @@ public static function headScript(): string {
* @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,
));
]);
}

/**
Expand All @@ -315,12 +324,15 @@ public static function prependScript(string $url, bool $cond = false, bool $defe
* @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,
);
];
}

/**
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ parameters:
- vendor/*
analyseAndScan:
- .git/*
- extensions/node_modules
- extensions/symbolic
- extensions/vendor
- node_modules/*
bootstrapFiles:
- cli/_cli.php
Expand All @@ -32,6 +35,7 @@ parameters:
- STDOUT
- TMP_PATH
- USERS_PATH
reportMaybesInPropertyPhpDocTypes: false
strictRules:
allRules: false
booleansInConditions: false # TODO pass
Expand Down