Skip to content

Commit

Permalink
PHPStan level 9 for ./p/ and lib_rss.php (#5049)
Browse files Browse the repository at this point in the history
And app/FreshRSS.php
Contributes to #4112
  • Loading branch information
Alkarex committed Jan 29, 2023
1 parent 2303b29 commit 4f316b2
Show file tree
Hide file tree
Showing 12 changed files with 1,196 additions and 1,100 deletions.
24 changes: 14 additions & 10 deletions app/FreshRSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FreshRSS extends Minz_FrontController {
* - Init notifications
* - Enable user extensions (need all the other initializations)
*/
public function init() {
public function init(): void {
if (!isset($_SESSION)) {
Minz_Session::init('FreshRSS');
}
Expand Down Expand Up @@ -71,10 +71,10 @@ public function init() {
Minz_ExtensionManager::callHook('freshrss_init');
}

private static function initAuth() {
private static function initAuth(): void {
FreshRSS_Auth::init();
if (Minz_Request::isPost()) {
if (!(FreshRSS_Auth::isCsrfOk() ||
if (FreshRSS_Context::$system_conf == null || !(FreshRSS_Auth::isCsrfOk() ||
(Minz_Request::controllerName() === 'auth' && Minz_Request::actionName() === 'login') ||
(Minz_Request::controllerName() === 'user' && Minz_Request::actionName() === 'create' && !FreshRSS_Auth::hasAccess('admin')) ||
(Minz_Request::controllerName() === 'feed' && Minz_Request::actionName() === 'actualize'
Expand All @@ -92,7 +92,7 @@ private static function initAuth() {
}
}

private static function initI18n() {
private static function initI18n(): void {
$userLanguage = isset(FreshRSS_Context::$user_conf) ? FreshRSS_Context::$user_conf->language : null;
$systemLanguage = isset(FreshRSS_Context::$system_conf) ? FreshRSS_Context::$system_conf->language : null;
$language = Minz_Translate::getLanguage($userLanguage, Minz_Request::getPreferredLanguages(), $systemLanguage);
Expand All @@ -107,12 +107,15 @@ private static function initI18n() {
date_default_timezone_set($timezone);
}

private static function getThemeFileUrl($theme_id, $filename) {
private static function getThemeFileUrl(string $theme_id, string $filename): string {
$filetime = @filemtime(PUBLIC_PATH . '/themes/' . $theme_id . '/' . $filename);
return '/themes/' . $theme_id . '/' . $filename . '?' . $filetime;
}

public static function loadStylesAndScripts() {
public static function loadStylesAndScripts(): void {
if (FreshRSS_Context::$user_conf == null) {
return;
}
$theme = FreshRSS_Themes::load(FreshRSS_Context::$user_conf->theme);
if ($theme) {
foreach(array_reverse($theme['files']) as $file) {
Expand Down Expand Up @@ -146,22 +149,23 @@ public static function loadStylesAndScripts() {
FreshRSS_View::prependScript(Minz_Url::display('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js')));
}

private static function loadNotifications() {
private static function loadNotifications(): void {
$notif = Minz_Request::getNotification();
if ($notif) {
FreshRSS_View::_param('notification', $notif);
}
}

public static function preLayout() {
public static function preLayout(): void {
header("X-Content-Type-Options: nosniff");

FreshRSS_Share::load(join_path(APP_PATH, 'shares.php'));
self::loadStylesAndScripts();
}

private static function checkEmailValidated() {
$email_not_verified = FreshRSS_Auth::hasAccess() && FreshRSS_Context::$user_conf->email_validation_token !== '';
private static function checkEmailValidated(): void {
$email_not_verified = FreshRSS_Auth::hasAccess() &&
FreshRSS_Context::$user_conf !== null && FreshRSS_Context::$user_conf->email_validation_token !== '';
$action_is_allowed = (
Minz_Request::is('user', 'validateEmail') ||
Minz_Request::is('user', 'sendValidationEmail') ||
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ class FreshRSS_Entry extends Minz_Model {
*/
private $guid;

/** @var string */
private $title;
private $authors;
/** @var string */
private $content;
/** @var string */
private $link;
/** @var int */
private $date;
private $date_added = 0; //In microseconds
/**
Expand Down Expand Up @@ -298,6 +302,7 @@ public function thumbnail(bool $searchEnclosures = true) {
public function link(): string {
return $this->link;
}
/** @return string|int */
public function date(bool $raw = false) {
if ($raw) {
return $this->date;
Expand Down
13 changes: 8 additions & 5 deletions app/Models/EntryDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -1165,10 +1165,12 @@ public function listWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_
}
}

public function listByIds($ids, $order = 'DESC') {
/** @param array<string> $ids */
public function listByIds(array $ids, string $order = 'DESC') {
if (count($ids) < 1) {
yield false;
} elseif (count($ids) > FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER) {
return;
}
if (count($ids) > FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER) {
// Split a query with too many variables parameters
$idsChunks = array_chunk($ids, FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER);
foreach ($idsChunks as $idsChunk) {
Expand All @@ -1195,15 +1197,16 @@ public function listByIds($ids, $order = 'DESC') {

/**
* For API
* @return array<string>
*/
public function listIdsWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL,
$order = 'DESC', $limit = 1, $firstId = '', $filters = null) {
$order = 'DESC', $limit = 1, $firstId = '', $filters = null): array {
list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filters);

$stm = $this->pdo->prepare($sql);
$stm->execute($values);

return $stm->fetchAll(PDO::FETCH_COLUMN, 0);
return $stm->fetchAll(PDO::FETCH_COLUMN, 0) ?: [];
}

public function listHashForFeedGuids($id_feed, $guids) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Minz/ModelPdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Minz_ModelPdo {
private static $sharedCurrentUser;

/**
* @var Minz_Pdo|null
* @var Minz_Pdo
*/
protected $pdo;

Expand Down
4 changes: 2 additions & 2 deletions lib/Minz/Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public static function availableLanguages() {
* preferred languages then returns the default language
* @param string|null $user the connected user language (nullable)
* @param array<string> $preferred an array of the preferred languages
* @param string $default the preferred language to use
* @param string|null $default the preferred language to use
* @return string containing the language to use
*/
public static function getLanguage($user, $preferred, $default) {
public static function getLanguage(?string $user, array $preferred, ?string $default): string {
if (null !== $user) {
return $user;
}
Expand Down
Loading

0 comments on commit 4f316b2

Please sign in to comment.