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

Use strict_types #5830

1 change: 1 addition & 0 deletions app/Controllers/apiController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* This controller manage API-related features.
Expand Down
5 changes: 3 additions & 2 deletions app/Controllers/authController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* This controller handles action about authentication.
Expand Down Expand Up @@ -116,11 +117,11 @@ public function formLoginAction(): void {
$limits = FreshRSS_Context::$system_conf->limits;
$this->view->cookie_days = (int)round($limits['cookie_duration'] / 86400, 1);

$isPOST = Minz_Request::isPost() && !Minz_Session::param('POST_to_GET');
$isPOST = Minz_Request::isPost() && !Minz_Session::paramBoolean('POST_to_GET');
Minz_Session::_param('POST_to_GET');

if ($isPOST) {
$nonce = Minz_Session::param('nonce', '');
$nonce = Minz_Session::paramString('nonce');
$username = Minz_Request::paramString('username');
$challenge = Minz_Request::paramString('challenge');

Expand Down
1 change: 1 addition & 0 deletions app/Controllers/categoryController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Controller to handle actions relative to categories.
Expand Down
1 change: 1 addition & 0 deletions app/Controllers/configureController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Controller to handle every configuration options.
Expand Down
1 change: 1 addition & 0 deletions app/Controllers/entryController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Controller to handle every entry actions.
Expand Down
6 changes: 4 additions & 2 deletions app/Controllers/errorController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Controller to handle error page.
Expand All @@ -14,8 +15,9 @@ class FreshRSS_error_Controller extends FreshRSS_ActionController {
* - error_logs (default: array())
*/
public function indexAction(): void {
$code_int = Minz_Session::param('error_code', 404);
$error_logs = Minz_Session::param('error_logs', []);
$code_int = Minz_Session::paramInt('error_code') ?: 404;
/** @var array<string> */
$error_logs = Minz_Session::paramArray('error_logs');
Minz_Session::_params([
'error_code' => false,
'error_logs' => false,
Expand Down
1 change: 1 addition & 0 deletions app/Controllers/extensionController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* The controller to manage extensions.
Expand Down
1 change: 1 addition & 0 deletions app/Controllers/feedController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Controller to handle every feed actions.
Expand Down
1 change: 1 addition & 0 deletions app/Controllers/importExportController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Controller to handle every import and export actions.
Expand Down
1 change: 1 addition & 0 deletions app/Controllers/indexController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* This class handles main actions of FreshRSS.
Expand Down
1 change: 1 addition & 0 deletions app/Controllers/javascriptController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_javascript_Controller extends FreshRSS_ActionController {

Expand Down
1 change: 1 addition & 0 deletions app/Controllers/statsController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Controller to handle application statistics.
Expand Down
1 change: 1 addition & 0 deletions app/Controllers/subscriptionController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Controller to handle subscription actions.
Expand Down
1 change: 1 addition & 0 deletions app/Controllers/tagController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Controller to handle every tag actions.
Expand Down
1 change: 1 addition & 0 deletions app/Controllers/updateController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_update_Controller extends FreshRSS_ActionController {

Expand Down
3 changes: 2 additions & 1 deletion app/Controllers/userController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Controller to handle user actions.
Expand Down Expand Up @@ -536,7 +537,7 @@ public function deleteAction(): void {
$ok = true;
if ($self_deletion) {
// We check the password if it’s a self-destruction
$nonce = Minz_Session::param('nonce', '');
$nonce = Minz_Session::paramString('nonce');
$challenge = Minz_Request::paramString('challenge');

$ok &= FreshRSS_FormAuth::checkCredentials(
Expand Down
1 change: 1 addition & 0 deletions app/Exceptions/AlreadySubscribedException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not make many PRs with partial changes, so let's start by deciding where we should have that in production (pros and cons) and then apply on everything we have decided (and tested!) at once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any disadvantages or problems. on the contrary, the code is more robust because it does what it says.

Copy link
Member

@Alkarex Alkarex Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will probably add those lines (it is the right time now, that we have just added PHP 7.4 typed properties), but examples of disadvantages are increased risks of crash in production, and tiny impact on performance (due to additional checks at runtime)...


class FreshRSS_AlreadySubscribed_Exception extends Exception {

Expand Down
1 change: 1 addition & 0 deletions app/Exceptions/BadUrlException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_BadUrl_Exception extends FreshRSS_Feed_Exception {

Expand Down
2 changes: 1 addition & 1 deletion app/Exceptions/ContextException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);

/**
* An exception raised when a context is invalid
*/
Expand Down
1 change: 0 additions & 1 deletion app/Exceptions/DAOException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

class FreshRSS_DAO_Exception extends Exception {
Expand Down
1 change: 0 additions & 1 deletion app/Exceptions/EntriesGetterException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

class FreshRSS_EntriesGetter_Exception extends Exception {
Expand Down
1 change: 0 additions & 1 deletion app/Exceptions/FeedException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

class FreshRSS_Feed_Exception extends Exception {
Expand Down
1 change: 1 addition & 0 deletions app/Exceptions/FeedNotAddedException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_FeedNotAdded_Exception extends Exception {

Expand Down
1 change: 1 addition & 0 deletions app/Exceptions/ZipException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_Zip_Exception extends Exception {

Expand Down
1 change: 0 additions & 1 deletion app/Exceptions/ZipMissingException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

class FreshRSS_ZipMissing_Exception extends Exception {
Expand Down
1 change: 1 addition & 0 deletions app/FreshRSS.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS extends Minz_FrontController {
/**
Expand Down
1 change: 1 addition & 0 deletions app/Mailers/UserMailer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Manage the emails sent to the users.
Expand Down
1 change: 0 additions & 1 deletion app/Models/ActionController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

class FreshRSS_ActionController extends Minz_ActionController {
Expand Down
9 changes: 5 additions & 4 deletions app/Models/Auth.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* This class handles all authentication process.
Expand All @@ -20,7 +21,7 @@ public static function init(): bool {
self::removeAccess();
}

self::$login_ok = Minz_Session::param('loginOk', false);
self::$login_ok = Minz_Session::paramBoolean('loginOk');
$current_user = Minz_User::name();
if ($current_user === null) {
$current_user = FreshRSS_Context::$system_conf->default_user;
Expand Down Expand Up @@ -109,7 +110,7 @@ public static function giveAccess(): bool {

switch (FreshRSS_Context::$system_conf->auth_type) {
case 'form':
self::$login_ok = Minz_Session::param('passwordHash') === FreshRSS_Context::$user_conf->passwordHash;
self::$login_ok = Minz_Session::paramString('passwordHash') === FreshRSS_Context::$user_conf->passwordHash;
break;
case 'http_auth':
$current_user = Minz_User::name();
Expand Down Expand Up @@ -212,7 +213,7 @@ public static function accessNeedsAction(): bool {
}

public static function csrfToken(): string {
$csrf = Minz_Session::param('csrf');
$csrf = Minz_Session::paramString('csrf');
if ($csrf == '') {
$salt = FreshRSS_Context::$system_conf->salt;
$csrf = sha1($salt . uniqid('' . random_int(0, mt_getrandmax()), true));
Expand All @@ -222,7 +223,7 @@ public static function csrfToken(): string {
}

public static function isCsrfOk(?string $token = null): bool {
$csrf = Minz_Session::param('csrf');
$csrf = Minz_Session::paramString('csrf');
if ($token === null) {
$token = $_POST['_csrf'] ?? '';
}
Expand Down
5 changes: 3 additions & 2 deletions app/Models/BooleanSearch.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Contains Boolean search from the search form.
Expand Down Expand Up @@ -67,7 +68,7 @@ private function parseUserQueryNames(string $input): string {
$name = trim($matches['search'][$i]);
if (!empty($queries[$name])) {
$fromS[] = $matches[0][$i];
$toS[] = '(' . trim($queries[$name]->getSearch()) . ')';
$toS[] = '(' . trim($queries[$name]->getSearch()->getRawInput()) . ')';
}
}
}
Expand Down Expand Up @@ -110,7 +111,7 @@ private function parseUserQueryIds(string $input): string {
$id = (int)(trim($matches['search'][$i])) - 1;
if (!empty($queries[$id])) {
$fromS[] = $matches[0][$i];
$toS[] = '(' . trim($queries[$id]->getSearch()) . ')';
$toS[] = '(' . trim($queries[$id]->getSearch()->getRawInput()) . ')';
}
}
}
Expand Down
1 change: 1 addition & 0 deletions app/Models/Category.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_Category extends Minz_Model {

Expand Down
1 change: 1 addition & 0 deletions app/Models/CategoryDAO.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_CategoryDAO extends Minz_ModelPdo {

Expand Down
1 change: 1 addition & 0 deletions app/Models/CategoryDAOSQLite.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_CategoryDAOSQLite extends FreshRSS_CategoryDAO {

Expand Down
1 change: 1 addition & 0 deletions app/Models/Context.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* The context object handles the current configuration file and different
Expand Down
1 change: 1 addition & 0 deletions app/Models/DatabaseDAO.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* This class is used to test database is well-constructed.
Expand Down
1 change: 1 addition & 0 deletions app/Models/DatabaseDAOPGSQL.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* This class is used to test database is well-constructed.
Expand Down
1 change: 1 addition & 0 deletions app/Models/DatabaseDAOSQLite.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* This class is used to test database is well-constructed (SQLite).
Expand Down
1 change: 0 additions & 1 deletion app/Models/Days.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

class FreshRSS_Days {
Expand Down
11 changes: 8 additions & 3 deletions app/Models/Entry.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_Entry extends Minz_Model {
public const STATE_READ = 1;
Expand Down Expand Up @@ -437,7 +438,11 @@ public function _hash(string $value): string {
return $this->hash;
}

public function _id(string $value): void {
/** @param int|string $value String is for compatibility with 32-bit platforms */
public function _id($value): void {
if (is_int($value)) {
$value = (string)$value;
}
$this->id = $value;
if ($this->date_added == 0) {
$this->date_added = $value;
Expand Down Expand Up @@ -741,11 +746,11 @@ public static function getContentByParsing(string $url, string $path, array $att
}

$content = '';
$nodes = $xpath->query(new Gt\CssXPath\Translator($path));
$nodes = $xpath->query((new Gt\CssXPath\Translator($path))->asXPath());
if ($nodes != false) {
foreach ($nodes as $node) {
if (!empty($attributes['path_entries_filter'])) {
$filterednodes = $xpath->query(new Gt\CssXPath\Translator($attributes['path_entries_filter']), $node) ?: [];
$filterednodes = $xpath->query((new Gt\CssXPath\Translator($attributes['path_entries_filter']))->asXPath(), $node) ?: [];
foreach ($filterednodes as $filterednode) {
$filterednode->parentNode->removeChild($filterednode);
}
Expand Down
1 change: 1 addition & 0 deletions app/Models/EntryDAO.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_EntryDAO extends Minz_ModelPdo {

Expand Down
1 change: 1 addition & 0 deletions app/Models/EntryDAOPGSQL.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_EntryDAOPGSQL extends FreshRSS_EntryDAOSQLite {

Expand Down
1 change: 1 addition & 0 deletions app/Models/EntryDAOSQLite.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {

Expand Down
1 change: 1 addition & 0 deletions app/Models/Factory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_Factory {

Expand Down
1 change: 1 addition & 0 deletions app/Models/Feed.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_Feed extends Minz_Model {

Expand Down
1 change: 1 addition & 0 deletions app/Models/FeedDAO.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_FeedDAO extends Minz_ModelPdo {

Expand Down
1 change: 1 addition & 0 deletions app/Models/FeedDAOSQLite.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_FeedDAOSQLite extends FreshRSS_FeedDAO {

Expand Down
1 change: 1 addition & 0 deletions app/Models/FilterAction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

class FreshRSS_FilterAction {

Expand Down