From 23ba48c71f0d41bbe012d668349f6516dad527b4 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Fri, 5 Sep 2025 09:56:46 -0400 Subject: Change how files are included (#7916) 1. `include`, `include_once`, `require` and `require_once` are expressions not functions, parentheses are not necessary. 2. to move up the directory tree, it's better to use the `dirname` function instead of relying on `/..`. --- app/Controllers/updateController.php | 6 +++--- app/Controllers/userController.php | 2 +- app/Models/DatabaseDAO.php | 4 ++-- app/Models/Feed.php | 4 ++-- app/Models/Search.php | 2 +- app/Models/Share.php | 2 +- app/Models/UserDAO.php | 4 ++-- app/actualize_script.php | 2 +- app/install.php | 4 ++-- cli/_cli.php | 10 +++++----- cli/actualize-user.php | 2 +- cli/check.translation.php | 6 +++--- cli/create-user.php | 2 +- cli/db-backup.php | 2 +- cli/db-optimize.php | 2 +- cli/db-restore.php | 2 +- cli/delete-user.php | 2 +- cli/do-install.php | 4 ++-- cli/export-opml-for-user.php | 2 +- cli/export-sqlite-for-user.php | 2 +- cli/export-zip-for-user.php | 2 +- cli/import-for-user.php | 2 +- cli/import-sqlite-for-user.php | 2 +- cli/list-users.php | 2 +- cli/manipulate.translation.php | 2 +- cli/prepare.php | 2 +- cli/reconfigure.php | 2 +- cli/update-user.php | 2 +- cli/user-info.php | 2 +- constants.php | 2 +- index.php | 2 +- lib/Minz/Configuration.php | 2 +- lib/Minz/Extension.php | 2 +- lib/Minz/ExtensionManager.php | 2 +- lib/Minz/Migrator.php | 2 +- lib/Minz/ModelArray.php | 2 +- lib/Minz/Paginator.php | 2 +- lib/Minz/Translate.php | 2 +- lib/http-conditional.php | 2 +- lib/lib_rss.php | 8 ++++---- p/api/fever.php | 6 +++--- p/api/greader.php | 4 ++-- p/api/index.php | 4 ++-- p/api/misc.php | 4 ++-- p/api/pshb.php | 4 ++-- p/api/query.php | 6 +++--- p/ext.php | 6 +++--- p/f.php | 8 ++++---- p/i/index.php | 8 ++++---- p/index.php | 4 ++-- tests/app/Models/SearchTest.php | 2 +- tests/bootstrap.php | 4 ++-- tests/cli/CliOptionsParserTest.php | 4 ++-- tests/cli/cli-parser-test.php | 4 ++-- tests/cli/i18n/I18nCompletionValidatorTest.php | 4 ++-- tests/cli/i18n/I18nDataTest.php | 4 ++-- tests/cli/i18n/I18nFileTest.php | 2 +- tests/cli/i18n/I18nUsageValidatorTest.php | 4 ++-- tests/cli/i18n/I18nValueTest.php | 2 +- 59 files changed, 98 insertions(+), 98 deletions(-) diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index d97b18c70..ba343c81e 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -128,7 +128,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { Minz_Error::error(403); } - include_once(LIB_PATH . '/lib_install.php'); + include_once LIB_PATH . '/lib_install.php'; invalidateHttpCache(); @@ -277,7 +277,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { if (self::isGit()) { $res = !self::hasGitUpdate(); } else { - require(UPDATE_FILENAME); + require UPDATE_FILENAME; // @phpstan-ignore function.notFound $res = do_post_update(); } @@ -299,7 +299,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { if (self::isGit()) { $res = self::gitPull(); } else { - require(UPDATE_FILENAME); + require UPDATE_FILENAME; if (Minz_Request::isPost()) { // @phpstan-ignore function.notFound save_info_update(); diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php index 67a97c45a..17879f3d0 100644 --- a/app/Controllers/userController.php +++ b/app/Controllers/userController.php @@ -288,7 +288,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController { $customUserConfigPath = join_path(DATA_PATH, 'config-user.custom.php'); if (file_exists($customUserConfigPath)) { - $customUserConfig = include($customUserConfigPath); + $customUserConfig = include $customUserConfigPath; if (is_array($customUserConfig)) { $userConfig = $customUserConfig; } diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php index 0062c23e8..8ec3ce3ca 100644 --- a/app/Models/DatabaseDAO.php +++ b/app/Models/DatabaseDAO.php @@ -21,7 +21,7 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { public const LENGTH_INDEX_UNICODE = 191; public function create(): string { - require_once(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php'); + require_once APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php'; $db = FreshRSS_Context::systemConf()->db; try { @@ -280,7 +280,7 @@ SQL; $catDAO = FreshRSS_Factory::createCategoryDao(); $catDAO->resetDefaultCategoryName(); - include_once(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php'); + include_once APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php'; if (!empty($GLOBALS['SQL_UPDATE_MINOR']) && is_string($GLOBALS['SQL_UPDATE_MINOR'])) { $sql = $GLOBALS['SQL_UPDATE_MINOR']; $isMariaDB = false; diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 26f85093e..f85db0f2f 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -177,7 +177,7 @@ class FreshRSS_Feed extends Minz_Model { $attributesOnly = $contents === null && $tmpPath === ''; - require_once(LIB_PATH . '/favicons.php'); + require_once LIB_PATH . '/favicons.php'; if (!$attributesOnly && !isImgMime(is_string($contents) ? $contents : '')) { throw new FreshRSS_UnsupportedImageFormat_Exception(); } @@ -401,7 +401,7 @@ class FreshRSS_Feed extends Minz_Model { } public function faviconPrepare(bool $force = false): void { - require_once(LIB_PATH . '/favicons.php'); + require_once LIB_PATH . '/favicons.php'; if ($this->customFavicon()) { return; } diff --git a/app/Models/Search.php b/app/Models/Search.php index 539fe2a12..e88f745ce 100644 --- a/app/Models/Search.php +++ b/app/Models/Search.php @@ -1,7 +1,7 @@ pdo->dbType() . '.php'); + require APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php'; try { $sql = $GLOBALS['SQL_CREATE_TABLES']; @@ -31,7 +31,7 @@ class FreshRSS_UserDAO extends Minz_ModelPdo { fwrite(STDERR, 'Deleting SQL data for user “' . $this->current_user . "”…\n"); } - require(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php'); + require APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php'; $sql = $GLOBALS['SQL_DROP_TABLES']; if (!is_string($sql)) { throw new Exception('SQL_DROP_TABLES is not a string!'); diff --git a/app/actualize_script.php b/app/actualize_script.php index d0ca72271..2be2a117a 100755 --- a/app/actualize_script.php +++ b/app/actualize_script.php @@ -1,7 +1,7 @@ #!/usr/bin/env php db['type'] ?? ''); diff --git a/cli/check.translation.php b/cli/check.translation.php index 151a6084f..01e90a631 100755 --- a/cli/check.translation.php +++ b/cli/check.translation.php @@ -6,7 +6,7 @@ require_once __DIR__ . '/i18n/I18nCompletionValidator.php'; require_once __DIR__ . '/i18n/I18nData.php'; require_once __DIR__ . '/i18n/I18nFile.php'; require_once __DIR__ . '/i18n/I18nUsageValidator.php'; -require_once __DIR__ . '/../constants.php'; +require_once dirname(__DIR__) . '/constants.php'; $cliOptions = new class extends CliOptionsParser { /** @var array $language */ @@ -104,7 +104,7 @@ function embedSvg(string $contents): string { if ($cliOptions->generateReadme) { $supportedFormats = ['txt', 'svg']; - $flagsDir = __DIR__ . '/../docs/i18n/flags'; + $flagsDir = dirname(__DIR__) . '/docs/i18n/flags'; $markdownImgStr = ''; foreach ($percentage as $lang => $value) { @@ -131,7 +131,7 @@ if ($cliOptions->generateReadme) { $template = '' . "\n"; if ($svg === '') { - $i18nGen = include __DIR__ . "/../app/i18n/$lang/gen.php"; + $i18nGen = include dirname(__DIR__) . "/app/i18n/$lang/gen.php"; if (!is_array($i18nGen) || !is_string($i18nGen['flag'] ?? null)) { echo 'Error: No Unicode flag found for language ' . $lang, PHP_EOL; exit(1); diff --git a/cli/create-user.php b/cli/create-user.php index 0276e80b3..4de0ced1d 100755 --- a/cli/create-user.php +++ b/cli/create-user.php @@ -1,7 +1,7 @@ #!/usr/bin/env php db['type'] ?? ''); $ok = true; diff --git a/cli/db-optimize.php b/cli/db-optimize.php index f6d3884b9..8f37dbca6 100755 --- a/cli/db-optimize.php +++ b/cli/db-optimize.php @@ -1,7 +1,7 @@ #!/usr/bin/env php db['type'] ?? ''); diff --git a/cli/db-restore.php b/cli/db-restore.php index 8e4ffcc12..0de624519 100755 --- a/cli/db-restore.php +++ b/cli/db-restore.php @@ -1,7 +1,7 @@ #!/usr/bin/env php db['type'] ?? ''); diff --git a/cli/delete-user.php b/cli/delete-user.php index 18efa4253..efb36a0ed 100755 --- a/cli/delete-user.php +++ b/cli/delete-user.php @@ -1,7 +1,7 @@ #!/usr/bin/env php db['type'] ?? ''); diff --git a/cli/do-install.php b/cli/do-install.php index cab4b1462..57a5121d4 100755 --- a/cli/do-install.php +++ b/cli/do-install.php @@ -1,7 +1,7 @@ #!/usr/bin/env php db['type'] ?? ''); diff --git a/cli/export-sqlite-for-user.php b/cli/export-sqlite-for-user.php index 98e05da22..01b364b51 100755 --- a/cli/export-sqlite-for-user.php +++ b/cli/export-sqlite-for-user.php @@ -1,7 +1,7 @@ #!/usr/bin/env php db['type'] ?? ''); diff --git a/cli/export-zip-for-user.php b/cli/export-zip-for-user.php index e030274d2..ca7de28fe 100755 --- a/cli/export-zip-for-user.php +++ b/cli/export-zip-for-user.php @@ -1,7 +1,7 @@ #!/usr/bin/env php db['type'] ?? ''); diff --git a/cli/import-for-user.php b/cli/import-for-user.php index 17dc9750e..26c69a118 100755 --- a/cli/import-for-user.php +++ b/cli/import-for-user.php @@ -1,7 +1,7 @@ #!/usr/bin/env php db['type'] ?? ''); diff --git a/cli/import-sqlite-for-user.php b/cli/import-sqlite-for-user.php index 2eb3e2965..f671151c2 100755 --- a/cli/import-sqlite-for-user.php +++ b/cli/import-sqlite-for-user.php @@ -1,7 +1,7 @@ #!/usr/bin/env php db['type'] ?? ''); diff --git a/cli/list-users.php b/cli/list-users.php index f9e63f4f6..b4c185e03 100755 --- a/cli/list-users.php +++ b/cli/list-users.php @@ -1,7 +1,7 @@ #!/usr/bin/env php getLock()) === false) { throw new Minz_PermissionDeniedException($this->filename); } else { - $data = include($this->filename); + $data = include $this->filename; $this->releaseLock($handle); if ($data === false) { diff --git a/lib/Minz/Paginator.php b/lib/Minz/Paginator.php index 265b0c2cb..52b170580 100644 --- a/lib/Minz/Paginator.php +++ b/lib/Minz/Paginator.php @@ -55,7 +55,7 @@ class Minz_Paginator { $view = APP_PATH . '/views/helpers/' . $view; if (file_exists($view)) { - include($view); + include $view; } } diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php index b57e90bcf..17290574c 100644 --- a/lib/Minz/Translate.php +++ b/lib/Minz/Translate.php @@ -172,7 +172,7 @@ class Minz_Translate { self::$translates[$key] = []; foreach (self::$lang_files[$key] as $lang_pathname) { - $i18n_array = include($lang_pathname); + $i18n_array = include $lang_pathname; if (!is_array($i18n_array)) { Minz_Log::warning('`' . $lang_pathname . '` does not contain a PHP array'); continue; diff --git a/lib/http-conditional.php b/lib/http-conditional.php index c08f72f75..e56732354 100644 --- a/lib/http-conditional.php +++ b/lib/http-conditional.php @@ -16,7 +16,7 @@ declare(strict_types=1); ```php salt; diff --git a/p/api/greader.php b/p/api/greader.php index 40fb5dc72..88afb3656 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -25,8 +25,8 @@ Server-side API compatible with Google Reader API layer 2 * https://github.com/bazqux/bazqux-api */ -require(__DIR__ . '/../../constants.php'); -require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader +require dirname(__DIR__, 2) . '/constants.php'; +require LIB_PATH . '/lib_rss.php'; //Includes class autoloader header("Content-Security-Policy: default-src 'none'; frame-ancestors 'none'; sandbox"); header('X-Content-Type-Options: nosniff'); diff --git a/p/api/index.php b/p/api/index.php index def8d4890..1db1273dc 100644 --- a/p/api/index.php +++ b/p/api/index.php @@ -13,8 +13,8 @@