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

[4.4] Converting from File::exists() to is_file() #40113

Merged
merged 4 commits into from
Mar 15, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ protected function updateManifestCaches()
$extensions = ExtensionHelper::getCoreExtensions();

// If we have the search package around, it may not have a manifest cache entry after upgrades from 3.x, so add it to the list
if (File::exists(JPATH_ROOT . '/administrator/manifests/packages/pkg_search.xml')) {
if (is_file(JPATH_ROOT . '/administrator/manifests/packages/pkg_search.xml')) {
$extensions[] = ['package', 'pkg_search', '', 0];
}

Expand Down Expand Up @@ -7938,7 +7938,7 @@ public function deleteUnexistingFiles($dryRun = false, $suppressOutput = false)
$status['folders_checked'] = $folders;

foreach ($files as $file) {
if ($fileExists = File::exists(JPATH_ROOT . $file)) {
if ($fileExists = is_file(JPATH_ROOT . $file)) {
$status['files_exist'][] = $file;

if ($dryRun === false) {
Expand Down Expand Up @@ -7976,8 +7976,8 @@ public function deleteUnexistingFiles($dryRun = false, $suppressOutput = false)
* but an update has put the files back. In that case it exists even if they don't believe in it!
*/
if (
!File::exists(JPATH_ROOT . '/administrator/components/com_search/search.php')
&& File::exists(JPATH_ROOT . '/administrator/manifests/packages/pkg_search.xml')
!is_file(JPATH_ROOT . '/administrator/components/com_search/search.php')
&& is_file(JPATH_ROOT . '/administrator/manifests/packages/pkg_search.xml')
) {
File::delete(JPATH_ROOT . '/administrator/manifests/packages/pkg_search.xml');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Joomla\Component\Config\Administrator\Field;

use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Form\Field\ListField;
use Joomla\CMS\Language\Text;
use Joomla\Utilities\ArrayHelper;
Expand Down Expand Up @@ -60,7 +59,7 @@ protected function getOptions()
// Load language
$extension = $item->value;

if (File::exists(JPATH_ADMINISTRATOR . '/components/' . $extension . '/config.xml')) {
if (is_file(JPATH_ADMINISTRATOR . '/components/' . $extension . '/config.xml')) {
$source = JPATH_ADMINISTRATOR . '/components/' . $extension;
$lang->load("$extension.sys", JPATH_ADMINISTRATOR)
|| $lang->load("$extension.sys", $source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function validateDbConnection($data)
return false;
}

if (!File::exists(Path::clean($data['dbsslca']))) {
if (!is_file(Path::clean($data['dbsslca']))) {
Factory::getApplication()->enqueueMessage(
Text::sprintf(
'COM_CONFIG_ERROR_DATABASE_ENCRYPTION_FILE_FIELD_BAD',
Expand Down Expand Up @@ -219,7 +219,7 @@ public function validateDbConnection($data)
return false;
}

if (!File::exists(Path::clean($data['dbsslkey']))) {
if (!is_file(Path::clean($data['dbsslkey']))) {
Factory::getApplication()->enqueueMessage(
Text::sprintf(
'COM_CONFIG_ERROR_DATABASE_ENCRYPTION_FILE_FIELD_BAD',
Expand All @@ -243,7 +243,7 @@ public function validateDbConnection($data)
return false;
}

if (!File::exists(Path::clean($data['dbsslcert']))) {
if (!is_file(Path::clean($data['dbsslcert']))) {
Factory::getApplication()->enqueueMessage(
Text::sprintf(
'COM_CONFIG_ERROR_DATABASE_ENCRYPTION_FILE_FIELD_BAD',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ public static function getFormFile(ContentType $typesTable)
// First, see if we have a file name in the $typesTable
$options = json_decode($typesTable->content_history_options);

if (is_object($options) && isset($options->formFile) && File::exists(JPATH_ROOT . '/' . $options->formFile)) {
if (is_object($options) && isset($options->formFile) && is_file(JPATH_ROOT . '/' . $options->formFile)) {
$result = JPATH_ROOT . '/' . $options->formFile;
} else {
$aliasArray = explode('.', $typesTable->type_alias);
$component = ($aliasArray[1] == 'category') ? 'com_categories' : $aliasArray[0];
$path = Folder::makeSafe(JPATH_ADMINISTRATOR . '/components/' . $component . '/models/forms/');
array_shift($aliasArray);
$file = File::makeSafe(implode('.', $aliasArray) . '.xml');
$result = File::exists($path . $file) ? $path . $file : false;
$result = is_file($path . $file) ? $path . $file : false;
}

return $result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use Joomla\CMS\Extension\ExtensionHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Installer\InstallerHelper;
Expand Down Expand Up @@ -563,7 +562,7 @@ protected function preparePreUpdate($update, $table)

$path = JPATH_ADMINISTRATOR . '/components/' . $table->element . '/helpers/' . $fname;

if (File::exists($path)) {
if (is_file($path)) {
require_once $path;

if (class_exists($cname) && is_callable([$cname, 'prepareUpdate'])) {
Expand All @@ -578,7 +577,7 @@ protected function preparePreUpdate($update, $table)
$cname = str_replace('_', '', $table->element) . 'Helper';
$path = ($table->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE) . '/modules/' . $table->element . '/helper.php';

if (File::exists($path)) {
if (is_file($path)) {
require_once $path;

if (class_exists($cname) && is_callable([$cname, 'prepareUpdate'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function finalizeUpdate(string $siteRoot, string $restorePath): void
*/
$namespaceMapFile = JPATH_ROOT . '/administrator/cache/autoload_psr4.php';

if (\Joomla\CMS\Filesystem\File::exists($namespaceMapFile)) {
if (is_file($namespaceMapFile)) {
\Joomla\CMS\Filesystem\File::delete($namespaceMapFile);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Joomla\Component\Joomlaupdate\Administrator\Controller;

use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\CMS\MVC\Controller\BaseController;
Expand Down Expand Up @@ -283,7 +282,7 @@ public function captive()
// Do I really have an update package?
$tempFile = $this->app->getUserState('com_joomlaupdate.temp_file', null);

if (empty($tempFile) || !File::exists($tempFile)) {
if (empty($tempFile) || !is_file($tempFile)) {
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public function download()
$response = [];

// Do we have a cached file?
$exists = File::exists($target);
$exists = is_file($target);

if (!$exists) {
// Not there, let's fetch it.
Expand Down Expand Up @@ -569,7 +569,7 @@ public function createUpdateFile($basename = null): bool
// Remove the old file, if it's there...
$configpath = JPATH_COMPONENT_ADMINISTRATOR . '/update.php';

if (File::exists($configpath)) {
if (is_file($configpath)) {
if (!File::delete($configpath)) {
File::invalidateFileCache($configpath);
@unlink($configpath);
Expand Down Expand Up @@ -844,22 +844,22 @@ public function cleanUp()
File::delete($tempdir . '/' . $file);

// Remove the update.php file used in Joomla 4.0.3 and later.
if (File::exists(JPATH_COMPONENT_ADMINISTRATOR . '/update.php')) {
if (is_file(JPATH_COMPONENT_ADMINISTRATOR . '/update.php')) {
File::delete(JPATH_COMPONENT_ADMINISTRATOR . '/update.php');
}

// Remove the legacy restoration.php file (when updating from Joomla 4.0.2 and earlier).
if (File::exists(JPATH_COMPONENT_ADMINISTRATOR . '/restoration.php')) {
if (is_file(JPATH_COMPONENT_ADMINISTRATOR . '/restoration.php')) {
File::delete(JPATH_COMPONENT_ADMINISTRATOR . '/restoration.php');
}

// Remove the legacy restore_finalisation.php file used in Joomla 4.0.2 and earlier.
if (File::exists(JPATH_COMPONENT_ADMINISTRATOR . '/restore_finalisation.php')) {
if (is_file(JPATH_COMPONENT_ADMINISTRATOR . '/restore_finalisation.php')) {
File::delete(JPATH_COMPONENT_ADMINISTRATOR . '/restore_finalisation.php');
}

// Remove joomla.xml from the site's root.
if (File::exists(JPATH_ROOT . '/joomla.xml')) {
if (is_file(JPATH_ROOT . '/joomla.xml')) {
File::delete(JPATH_ROOT . '/joomla.xml');
}

Expand Down Expand Up @@ -985,7 +985,7 @@ public function captiveFileExists()
{
$file = Factory::getApplication()->getUserState('com_joomlaupdate.temp_file', null);

if (empty($file) || !File::exists($file)) {
if (empty($file) || !is_file($file)) {
return false;
}

Expand All @@ -1007,7 +1007,7 @@ public function removePackageFiles()
];

foreach ($files as $file) {
if ($file !== null && File::exists($file)) {
if ($file !== null && is_file($file)) {
File::delete($file);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Joomla\Component\Postinstall\Administrator\Controller;

use Joomla\CMS\Filesystem\File;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\Component\Postinstall\Administrator\Helper\PostinstallHelper;
use Joomla\Component\Postinstall\Administrator\Model\MessagesModel;
Expand Down Expand Up @@ -158,7 +157,7 @@ public function action()
$helper = new PostinstallHelper();
$file = $helper->parsePath($item->action_file);

if (File::exists($file)) {
if (is_file($file)) {
require_once $file;

call_user_func($item->action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Joomla\CMS\Cache\Controller\CallbackController;
use Joomla\CMS\Extension\ExtensionHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
Expand Down Expand Up @@ -414,7 +413,7 @@ protected function onProcessList(&$resultArray)
$helper = new PostinstallHelper();
$file = $helper->parsePath($item->condition_file);

if (File::exists($file)) {
if (is_file($file)) {
require_once $file;

$result = call_user_func($item->condition_method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ public function copy()
$src = Path::clean($client->path . '/language/' . $languageFile);
$dst = Path::clean($toPath . '/' . $folder . '/' . $languageFile);

if (File::exists($src)) {
if (is_file($src)) {
File::copy($src, $dst);
}
}
Expand Down Expand Up @@ -784,7 +784,7 @@ protected function fixTemplateName()
// Edit XML file
$xmlFile = $this->getState('to_path') . '/templateDetails.xml';

if (File::exists($xmlFile)) {
if (is_file($xmlFile)) {
$contents = file_get_contents($xmlFile);
$pattern[] = '#<name>\s*' . $manifest->name . '\s*</name>#i';
$replace[] = '<name>' . $newName . '</name>';
Expand Down Expand Up @@ -1215,7 +1215,7 @@ public function createTemplateOverride($overridePath, $htmlPath)
$overrideFilePath = str_replace($overridePath, '', $file);
$htmlFilePath = $htmlPath . $overrideFilePath;

if (File::exists($htmlFilePath)) {
if (is_file($htmlFilePath)) {
// Generate new unique file name base on current time
$today = Factory::getDate();
$htmlFilePath = File::stripExt($htmlFilePath) . '-' . $today->format('Ymd-His') . '.' . File::getExt($htmlFilePath);
Expand Down Expand Up @@ -1890,7 +1890,7 @@ public function child()
// Edit XML file
$xmlFile = Path::clean($this->getState('to_path') . '/templateDetails.xml');

if (!File::exists($xmlFile)) {
if (!is_file($xmlFile)) {
$app->enqueueMessage(Text::_('COM_TEMPLATES_ERROR_INVALID_FROM_NAME'), 'error');

return false;
Expand Down
3 changes: 1 addition & 2 deletions components/com_config/tmpl/modules/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
Expand All @@ -28,7 +27,7 @@
$editorText = false;
$moduleXml = JPATH_SITE . '/modules/' . $this->item['module'] . '/' . $this->item['module'] . '.xml';

if (File::exists($moduleXml)) {
if (is_file($moduleXml)) {
$xml = simplexml_load_file($moduleXml);

if (isset($xml->customContent)) {
Expand Down
10 changes: 5 additions & 5 deletions installation/src/Helper/DatabaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public static function validateConnectionParameters($options)
return Text::sprintf('INSTL_DATABASE_ENCRYPTION_MSG_FILE_FIELD_EMPTY', Text::_('INSTL_DATABASE_ENCRYPTION_CA_LABEL'));
}

if (!File::exists(Path::clean($options->db_sslca))) {
if (!is_file(Path::clean($options->db_sslca))) {
return Text::sprintf('INSTL_DATABASE_ENCRYPTION_MSG_FILE_FIELD_BAD', Text::_('INSTL_DATABASE_ENCRYPTION_CA_LABEL'));
}
} else {
Expand All @@ -290,15 +290,15 @@ public static function validateConnectionParameters($options)
return Text::sprintf('INSTL_DATABASE_ENCRYPTION_MSG_FILE_FIELD_EMPTY', Text::_('INSTL_DATABASE_ENCRYPTION_KEY_LABEL'));
}

if (!File::exists(Path::clean($options->db_sslkey))) {
if (!is_file(Path::clean($options->db_sslkey))) {
return Text::sprintf('INSTL_DATABASE_ENCRYPTION_MSG_FILE_FIELD_BAD', Text::_('INSTL_DATABASE_ENCRYPTION_KEY_LABEL'));
}

if (empty($options->db_sslcert)) {
return Text::sprintf('INSTL_DATABASE_ENCRYPTION_MSG_FILE_FIELD_EMPTY', Text::_('INSTL_DATABASE_ENCRYPTION_CERT_LABEL'));
}

if (!File::exists(Path::clean($options->db_sslcert))) {
if (!is_file(Path::clean($options->db_sslcert))) {
return Text::sprintf('INSTL_DATABASE_ENCRYPTION_MSG_FILE_FIELD_BAD', Text::_('INSTL_DATABASE_ENCRYPTION_CERT_LABEL'));
}
} else {
Expand Down Expand Up @@ -403,7 +403,7 @@ public static function checkRemoteDbHost($options)

if (
Factory::getSession()->get('remoteDbFileWrittenByJoomla', false) === true
&& File::exists(JPATH_INSTALLATION . '/' . $remoteDbFile)
&& is_file(JPATH_INSTALLATION . '/' . $remoteDbFile)
) {
// Add the general message
Factory::getApplication()->enqueueMessage($generalRemoteDatabaseMessage, 'warning');
Expand All @@ -422,7 +422,7 @@ public static function checkRemoteDbHost($options)
return false;
}

if (Factory::getSession()->get('remoteDbFileUnwritable', false) === true && !File::exists(JPATH_INSTALLATION . '/' . $remoteDbFile)) {
if (Factory::getSession()->get('remoteDbFileUnwritable', false) === true && !is_file(JPATH_INSTALLATION . '/' . $remoteDbFile)) {
// Add the general message
Factory::getApplication()->enqueueMessage($generalRemoteDatabaseMessage, 'warning');

Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Log/Logger/FormattedtextLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ protected function generateFileHeader()
protected function initFile()
{
// We only need to make sure the file exists
if (File::exists($this->path)) {
if (is_file($this->path)) {
return;
}

Expand Down
6 changes: 1 addition & 5 deletions plugins/filesystem/local/src/Adapter/LocalAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public function updateFile(string $name, string $path, $data)
{
$localPath = $this->getLocalPath($path . '/' . $name);

if (!File::exists($localPath)) {
if (!is_file($localPath)) {
throw new FileNotFoundException();
}

Expand Down Expand Up @@ -324,10 +324,6 @@ public function delete(string $path)
$thumbnailPaths = $this->getLocalThumbnailPaths($localPath);

if (is_file($localPath)) {
if (!File::exists($localPath)) {
Hackwar marked this conversation as resolved.
Show resolved Hide resolved
throw new FileNotFoundException();
}

if ($this->thumbnails && !empty($thumbnailPaths['fs']) && is_file($thumbnailPaths['fs'])) {
File::delete($thumbnailPaths['fs']);
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/system/tasknotification/tasknotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
Expand Down Expand Up @@ -118,7 +117,9 @@ public function injectTaskNotificationFieldset(EventInterface $event): bool
return false;
}

if (!File::exists($formFile)) {
$formFile = Path::clean($formFile);

if (!is_file($formFile)) {
Hackwar marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

Expand Down Expand Up @@ -302,7 +303,6 @@ private function sendMail(string $template, array $data, string $attachment = ''

if (
!empty($attachment)
&& File::exists($attachment)
&& is_file($attachment)
Hackwar marked this conversation as resolved.
Show resolved Hide resolved
) {
// @todo we allow multiple files [?]
Expand Down