Explorar el Código

applies several small optimizations (#5511)

declare(strict_types=1);
Co-authored-by: Luc <sanchezluc+freshrss@gmail.com>
Luc SANCHEZ hace 2 años
padre
commit
4a02352ccc

+ 1 - 0
app/Exceptions/ContextException.php

@@ -1,5 +1,6 @@
 <?php
 
+declare(strict_types=1);
 /**
  * An exception raised when a context is invalid
  */

+ 2 - 0
app/Exceptions/DAOException.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 class FreshRSS_DAO_Exception extends Exception {
 
 }

+ 2 - 0
app/Exceptions/EntriesGetterException.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 class FreshRSS_EntriesGetter_Exception extends Exception {
 
 }

+ 2 - 0
app/Exceptions/FeedException.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 class FreshRSS_Feed_Exception extends Exception {
 
 }

+ 2 - 0
app/Exceptions/ZipMissingException.php

@@ -1,4 +1,6 @@
 <?php
 
+declare(strict_types=1);
+
 class FreshRSS_ZipMissing_Exception extends Exception {
 }

+ 2 - 0
app/Models/ActionController.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 class FreshRSS_ActionController extends Minz_ActionController {
 
 	/**

+ 2 - 0
app/Models/Log.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 class FreshRSS_Log extends Minz_Model {
 	/** @var string */
 	private $date;

+ 3 - 0
app/Models/SystemConfiguration.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 /**
  * @property bool $allow_anonymous
  * @property bool $allow_anonymous_refresh
@@ -27,6 +29,7 @@
  */
 final class FreshRSS_SystemConfiguration extends Minz_Configuration {
 
+	/** @throws Minz_ConfigurationNamespaceException */
 	public static function init(string $config_filename, ?string $default_filename = null): FreshRSS_SystemConfiguration {
 		parent::register('system', $config_filename, $default_filename);
 		return parent::get('system');

+ 2 - 0
app/Models/TagDAOPGSQL.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 class FreshRSS_TagDAOPGSQL extends FreshRSS_TagDAO {
 
 	public function sqlIgnore(): string {

+ 3 - 0
app/Models/UserConfiguration.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 /**
  * @property string $apiPasswordHash
  * @property array<string,mixed> $archiving
@@ -71,6 +73,7 @@
  */
 final class FreshRSS_UserConfiguration extends Minz_Configuration {
 
+	/** @throws Minz_ConfigurationNamespaceException */
 	public static function init(string $config_filename, ?string $default_filename = null): FreshRSS_UserConfiguration {
 		parent::register('user', $config_filename, $default_filename);
 		return parent::get('user');

+ 2 - 0
app/Models/ViewJavascript.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 final class FreshRSS_ViewJavascript extends FreshRSS_View {
 
 	/** @var array<FreshRSS_Category> */

+ 2 - 0
app/Models/ViewStats.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 final class FreshRSS_ViewStats extends FreshRSS_View {
 
 	/** @var FreshRSS_Category|null */

+ 8 - 2
app/Utils/feverUtil.php

@@ -9,8 +9,11 @@ class FreshRSS_fever_Util {
 	 * @return bool true if the path is writable, false otherwise.
 	 */
 	public static function checkFeverPath(): bool {
-		if (!file_exists(self::FEVER_PATH)) {
-			@mkdir(self::FEVER_PATH, 0770, true);
+		if (!file_exists(self::FEVER_PATH) &&
+			!mkdir($concurrentDirectory = self::FEVER_PATH, 0770, true) &&
+			!is_dir($concurrentDirectory)
+		) {
+			throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
 		}
 
 		$ok = touch(self::FEVER_PATH . '/index.html');	// is_writable() is not reliable for a folder on NFS
@@ -22,6 +25,7 @@ class FreshRSS_fever_Util {
 
 	/**
 	 * Return the corresponding path for a fever key.
+	 * @throws FreshRSS_Context_Exception
 	 */
 	public static function getKeyPath(string $feverKey): string {
 		if (FreshRSS_Context::$system_conf === null) {
@@ -34,6 +38,7 @@ class FreshRSS_fever_Util {
 	/**
 	 * Update the fever key of a user.
 	 * @return string|false the Fever key, or false if the update failed
+	 * @throws FreshRSS_Context_Exception
 	 */
 	public static function updateKey(string $username, string $passwordPlain) {
 		if (!self::checkFeverPath()) {
@@ -56,6 +61,7 @@ class FreshRSS_fever_Util {
 	 * Delete the Fever key of a user.
 	 *
 	 * @return bool true if the deletion succeeded, else false.
+	 * @throws FreshRSS_Context_Exception
 	 */
 	public static function deleteKey(string $username): bool {
 		$userConfig = get_user_configuration($username);

+ 2 - 2
app/install.php

@@ -290,7 +290,7 @@ function freshrss_already_installed(): bool {
 	$system_conf = null;
 	try {
 		$system_conf = FreshRSS_SystemConfiguration::init($conf_path);
-	} catch (Minz_FileNotExistException $e) {
+	} catch (Minz_ConfigurationNamespaceException $e) {
 		return false;
 	}
 
@@ -298,7 +298,7 @@ function freshrss_already_installed(): bool {
 	$current_user = $system_conf->default_user;
 	try {
 		FreshRSS_UserConfiguration::init(USERS_PATH . '/' . $current_user . '/config.php');
-	} catch (Minz_FileNotExistException $e) {
+	} catch (Minz_ConfigurationNamespaceException $e) {
 		return false;
 	}
 

+ 2 - 0
app/shares.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 /*
  * This is a configuration file. You shouldn’t modify it unless you know what
  * you are doing. If you want to add a share type, this is where you need to do