diff --git a/.drone.yml b/.drone.yml index 05e1bc2b74dd3..d51c1cca0e045 100644 --- a/.drone.yml +++ b/.drone.yml @@ -28,7 +28,6 @@ steps: commands: - echo $(date) - ./libraries/vendor/bin/php-cs-fixer fix -vvv --dry-run --diff - - ./libraries/vendor/bin/phpcs --extensions=php -p --standard=ruleset.xml . - echo $(date) - name: phpstan diff --git a/administrator/components/com_actionlogs/src/Controller/ActionlogsController.php b/administrator/components/com_actionlogs/src/Controller/ActionlogsController.php index 80873249fb37a..9e045dd68afec 100644 --- a/administrator/components/com_actionlogs/src/Controller/ActionlogsController.php +++ b/administrator/components/com_actionlogs/src/Controller/ActionlogsController.php @@ -84,10 +84,10 @@ public function exportLogs() // Get the logs data $data = $model->getLogDataAsIterator($pks); - if (\count($data)) { + if (\count($data) > 0) { try { $rows = ActionlogsHelper::getCsvData($data); - } catch (\InvalidArgumentException $exception) { + } catch (\InvalidArgumentException) { $this->setMessage(Text::_('COM_ACTIONLOGS_ERROR_COULD_NOT_EXPORT_DATA'), 'error'); $this->setRedirect(Route::_('index.php?option=com_actionlogs&view=actionlogs', false)); diff --git a/administrator/components/com_actionlogs/src/Field/ExtensionField.php b/administrator/components/com_actionlogs/src/Field/ExtensionField.php index 49ec4a0a6d123..8e0565c31ff5d 100644 --- a/administrator/components/com_actionlogs/src/Field/ExtensionField.php +++ b/administrator/components/com_actionlogs/src/Field/ExtensionField.php @@ -41,7 +41,7 @@ class ExtensionField extends ListField * * @since 3.9.0 */ - public function getOptions() + protected function getOptions() { $db = $this->getDatabase(); $query = $db->getQuery(true) diff --git a/administrator/components/com_actionlogs/src/Field/LogtypeField.php b/administrator/components/com_actionlogs/src/Field/LogtypeField.php index 6aae799f0c2b2..1053a73ee1d75 100644 --- a/administrator/components/com_actionlogs/src/Field/LogtypeField.php +++ b/administrator/components/com_actionlogs/src/Field/LogtypeField.php @@ -42,7 +42,7 @@ class LogtypeField extends ListField * * @since 3.9.0 */ - public function getOptions() + protected function getOptions() { $db = $this->getDatabase(); $query = $db->getQuery(true) diff --git a/administrator/components/com_actionlogs/src/Field/UserlogtypeField.php b/administrator/components/com_actionlogs/src/Field/UserlogtypeField.php index c821e5fb67a4e..41b7cee042877 100644 --- a/administrator/components/com_actionlogs/src/Field/UserlogtypeField.php +++ b/administrator/components/com_actionlogs/src/Field/UserlogtypeField.php @@ -41,7 +41,7 @@ class UserlogtypeField extends ListField * * @since 5.1.0 */ - public function getOptions() + protected function getOptions() { $db = $this->getDatabase(); $user = Factory::getApplication()->getIdentity(); @@ -57,7 +57,7 @@ public function getOptions() $globalExt = $params->get('loggable_extensions', []); if (!empty($extensions)) { - $userExt = substr($extensions[0], 2); + $userExt = substr((string) $extensions[0], 2); $userExt = substr($userExt, 0, -2); $userExt = explode('","', $userExt); } diff --git a/administrator/components/com_actionlogs/src/Helper/ActionlogsHelper.php b/administrator/components/com_actionlogs/src/Helper/ActionlogsHelper.php index 68cab09bbc17a..e2c8610547f2c 100644 --- a/administrator/components/com_actionlogs/src/Helper/ActionlogsHelper.php +++ b/administrator/components/com_actionlogs/src/Helper/ActionlogsHelper.php @@ -56,7 +56,7 @@ public static function getCsvData($data): \Generator \sprintf( '%s() requires an array or object implementing the Traversable interface, a %s was given.', __METHOD__, - \is_object($data) ? \get_class($data) : \gettype($data) + get_debug_type($data) ) ); } @@ -134,12 +134,12 @@ public static function loadTranslationFiles($extension) break; } - $lang->load($extension, JPATH_ADMINISTRATOR) - || $lang->load($extension, $source); + if (!$lang->load($extension, JPATH_ADMINISTRATOR)) { + $lang->load($extension, $source); + } - if (!$lang->hasKey(strtoupper($extension))) { - $lang->load($extension . '.sys', JPATH_ADMINISTRATOR) - || $lang->load($extension . '.sys', $source); + if (!$lang->hasKey(strtoupper($extension)) && !$lang->load($extension . '.sys', JPATH_ADMINISTRATOR)) { + $lang->load($extension . '.sys', $source); } $cache[$extension] = true; @@ -208,7 +208,7 @@ public static function getHumanReadableLogMessage($log, $generateLinks = true) foreach ($messageData as $key => $value) { // Escape any markup in the values to prevent XSS attacks - $value = $value !== null ? htmlspecialchars($value, ENT_QUOTES, 'UTF-8') : ''; + $value = $value !== null ? htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8') : ''; // Convert relative url to absolute url so that it is clickable in action logs notification email if ($generateLinks && StringHelper::strpos($value, 'index.php?') === 0) { @@ -310,7 +310,7 @@ public static function loadActionLogPluginsLanguage() try { $rows = $db->loadObjectList(); - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { $rows = []; } @@ -329,8 +329,9 @@ public static function loadActionLogPluginsLanguage() continue; } - $lang->load($extension, JPATH_ADMINISTRATOR) - || $lang->load($extension, JPATH_PLUGINS . '/' . $type . '/' . $name); + if (!$lang->load($extension, JPATH_ADMINISTRATOR)) { + $lang->load($extension, JPATH_PLUGINS . '/' . $type . '/' . $name); + } } // Load plg_system_actionlogs too @@ -362,7 +363,7 @@ protected static function escapeCsvFormula($value) } if (\in_array($value[0], self::$characters, true)) { - $value = ' ' . $value; + return ' ' . $value; } return $value; diff --git a/administrator/components/com_actionlogs/src/Model/ActionlogModel.php b/administrator/components/com_actionlogs/src/Model/ActionlogModel.php index f11c3bf87c034..67563a838a4af 100644 --- a/administrator/components/com_actionlogs/src/Model/ActionlogModel.php +++ b/administrator/components/com_actionlogs/src/Model/ActionlogModel.php @@ -55,7 +55,7 @@ public function addLog($messages, $messageLanguageKey, $context, $userId = 0) @trigger_error(\sprintf('User ID must be an integer in %s.', __METHOD__), E_USER_DEPRECATED); } - $user = $userId ? $this->getUserFactory()->loadUserById($userId) : $this->getCurrentUser(); + $user = $userId !== 0 ? $this->getUserFactory()->loadUserById($userId) : $this->getCurrentUser(); $db = $this->getDatabase(); $date = Factory::getDate(); $params = ComponentHelper::getComponent('com_actionlogs')->getParams(); @@ -85,7 +85,7 @@ public function addLog($messages, $messageLanguageKey, $context, $userId = 0) try { $db->insertObject('#__action_logs', $logMessage); $loggedMessages[] = $logMessage; - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { // Ignore it } } @@ -93,7 +93,7 @@ public function addLog($messages, $messageLanguageKey, $context, $userId = 0) try { // Send notification email to users who choose to be notified about the action logs $this->sendNotificationEmails($loggedMessages, $user->name, $context); - } catch (MailDisabledException | phpMailerException $e) { + } catch (MailDisabledException | phpMailerException) { // Ignore it } } @@ -143,7 +143,7 @@ protected function sendNotificationEmails($messages, $username, $context) } } - if (empty($recipients)) { + if ($recipients === []) { return; } diff --git a/administrator/components/com_actionlogs/src/Model/ActionlogsModel.php b/administrator/components/com_actionlogs/src/Model/ActionlogsModel.php index f3883d9e06245..b7a07d93be01e 100644 --- a/administrator/components/com_actionlogs/src/Model/ActionlogsModel.php +++ b/administrator/components/com_actionlogs/src/Model/ActionlogsModel.php @@ -147,12 +147,12 @@ protected function getListQuery() $search = $this->getState('filter.search'); if (!empty($search)) { - if (stripos($search, 'id:') === 0) { - $ids = (int) substr($search, 3); + if (stripos((string) $search, 'id:') === 0) { + $ids = (int) substr((string) $search, 3); $query->where($db->quoteName('a.id') . ' = :id') ->bind(':id', $ids, ParameterType::INTEGER); - } elseif (stripos($search, 'item_id:') === 0) { - $ids = (int) substr($search, 8); + } elseif (stripos((string) $search, 'item_id:') === 0) { + $ids = (int) substr((string) $search, 8); $query->where($db->quoteName('a.item_id') . ' = :itemid') ->bind(':itemid', $ids, ParameterType::INTEGER); } else { @@ -313,7 +313,7 @@ private function getLogDataQuery($pks = null) ->from($db->quoteName('#__action_logs', 'a')) ->join('INNER', $db->quoteName('#__users', 'u') . ' ON ' . $db->quoteName('a.user_id') . ' = ' . $db->quoteName('u.id')); - if (\is_array($pks) && \count($pks) > 0) { + if (\is_array($pks) && $pks !== []) { $pks = ArrayHelper::toInteger($pks); $query->whereIn($db->quoteName('a.id'), $pks); } @@ -341,8 +341,8 @@ public function delete(&$pks) try { $db->execute(); - } catch (\RuntimeException $e) { - $this->setError($e->getMessage()); + } catch (\RuntimeException $runtimeException) { + $this->setError($runtimeException->getMessage()); return false; } @@ -363,7 +363,7 @@ public function purge() { try { $this->getDatabase()->truncateTable('#__action_logs'); - } catch (\Exception $e) { + } catch (\Exception) { return false; } diff --git a/administrator/components/com_actionlogs/src/Plugin/ActionLogPlugin.php b/administrator/components/com_actionlogs/src/Plugin/ActionLogPlugin.php index 946ec21d2a156..3b2ca52e3a3db 100644 --- a/administrator/components/com_actionlogs/src/Plugin/ActionLogPlugin.php +++ b/administrator/components/com_actionlogs/src/Plugin/ActionLogPlugin.php @@ -10,7 +10,11 @@ namespace Joomla\Component\Actionlogs\Administrator\Plugin; +use Joomla\CMS\Application\CMSApplication; +use Joomla\CMS\Application\CMSApplicationInterface; use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\Component\Actionlogs\Administrator\Model\ActionlogModel; +use Joomla\Database\DatabaseDriver; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -26,7 +30,7 @@ abstract class ActionLogPlugin extends CMSPlugin /** * Application object. * - * @var \Joomla\CMS\Application\CMSApplication + * @var CMSApplication * @since 3.9.0 * * @deprecated 5.1.0 will be removed in 7.0 use $this->getApplication() instead @@ -36,7 +40,7 @@ abstract class ActionLogPlugin extends CMSPlugin /** * Database object. * - * @var \Joomla\Database\DatabaseDriver + * @var DatabaseDriver * @since 3.9.0 * * @deprecated 5.1.0 will be removed in 7.0 use $this->getDatabase() instead @@ -67,7 +71,7 @@ abstract class ActionLogPlugin extends CMSPlugin */ protected function addLog($messages, $messageLanguageKey, $context, $userId = null) { - $app = $this->getApplication() ?: $this->app; + $app = $this->getApplication() instanceof CMSApplicationInterface ? $this->getApplication() : $this->app; $user = $app->getIdentity(); foreach ($messages as $index => $message) { @@ -84,17 +88,17 @@ protected function addLog($messages, $messageLanguageKey, $context, $userId = nu } if (\array_key_exists('type', $message)) { - $message['type'] = strtoupper($message['type']); + $message['type'] = strtoupper((string) $message['type']); } if (\array_key_exists('app', $message)) { - $message['app'] = strtoupper($message['app']); + $message['app'] = strtoupper((string) $message['app']); } $messages[$index] = $message; } - /** @var \Joomla\Component\Actionlogs\Administrator\Model\ActionlogModel $model */ + /** @var ActionlogModel $model */ $model = $app->bootComponent('com_actionlogs') ->getMVCFactory()->createModel('Actionlog', 'Administrator', ['ignore_request' => true]); diff --git a/administrator/components/com_actionlogs/src/View/Actionlogs/HtmlView.php b/administrator/components/com_actionlogs/src/View/Actionlogs/HtmlView.php index 6e20d3a76dac2..fbad86b85a23b 100644 --- a/administrator/components/com_actionlogs/src/View/Actionlogs/HtmlView.php +++ b/administrator/components/com_actionlogs/src/View/Actionlogs/HtmlView.php @@ -111,7 +111,7 @@ public function display($tpl = null) $this->showIpColumn = (bool) $params->get('ip_logging', 0); $this->dateRelative = (bool) $params->get('date_relative', 1); - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_admin/postinstall/behindproxy.php b/administrator/components/com_admin/postinstall/behindproxy.php index d784ab7d2e339..13992ee69d9dc 100644 --- a/administrator/components/com_admin/postinstall/behindproxy.php +++ b/administrator/components/com_admin/postinstall/behindproxy.php @@ -37,12 +37,7 @@ function admin_postinstall_behindproxy_condition() if (\array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { return true; } - - if (\array_key_exists('HTTP_CLIENT_IP', $_SERVER) && !empty($_SERVER['HTTP_CLIENT_IP'])) { - return true; - } - - return false; + return \array_key_exists('HTTP_CLIENT_IP', $_SERVER) && !empty($_SERVER['HTTP_CLIENT_IP']); } diff --git a/administrator/components/com_admin/postinstall/languageaccess340.php b/administrator/components/com_admin/postinstall/languageaccess340.php index 32ec165e056c0..fe8e5aa27db00 100644 --- a/administrator/components/com_admin/postinstall/languageaccess340.php +++ b/administrator/components/com_admin/postinstall/languageaccess340.php @@ -36,13 +36,9 @@ function admin_postinstall_languageaccess340_condition() ->where($db->quoteName('access') . ' = ' . $db->quote('0')); $db->setQuery($query); $db->execute(); - $numRows = $db->getNumRows(); - - if (isset($numRows) && $numRows != 0) { - // We have rows here so we have at minimum one row with access set to 0 - return true; - } + $numRows = $db->getNumRows(); // All good the query return nothing. - return false; + // We have rows here so we have at minimum one row with access set to 0 + return isset($numRows) && $numRows != 0; } diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index c480ed3e7f6c6..8cf849ec924c5 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -17,8 +17,12 @@ use Joomla\CMS\Installer\Installer; use Joomla\CMS\Language\Text; use Joomla\CMS\Log\Log; +use Joomla\CMS\Table\Asset; use Joomla\CMS\Table\Table; use Joomla\CMS\Uri\Uri; +use Joomla\Component\Cache\Administrator\Model\CacheModel; +use Joomla\Component\Scheduler\Administrator\Extension\SchedulerComponent; +use Joomla\Component\Scheduler\Administrator\Model\TaskModel; use Joomla\Database\ParameterType; use Joomla\Filesystem\File; use Joomla\Filesystem\Folder; @@ -41,7 +45,7 @@ class JoomlaInstallerScript * @var string * @since 3.7 */ - protected $fromVersion = null; + protected $fromVersion; /** * Callback for collecting errors. Like function(string $context, \Throwable $error){}; @@ -130,16 +134,16 @@ public function update($installer) try { Log::add(Text::_('COM_JOOMLAUPDATE_UPDATE_LOG_UNINSTALL_EXTENSIONS'), Log::INFO, 'Update'); $this->uninstallExtensions(); - } catch (\Throwable $e) { - $this->collectError('uninstallExtensions', $e); + } catch (\Throwable $throwable) { + $this->collectError('uninstallExtensions', $throwable); } // Remove old files try { Log::add(Text::_('COM_JOOMLAUPDATE_UPDATE_LOG_DELETE_FILES'), Log::INFO, 'Update'); $this->deleteUnexistingFiles(); - } catch (\Throwable $e) { - $this->collectError('deleteUnexistingFiles', $e); + } catch (\Throwable $throwable) { + $this->collectError('deleteUnexistingFiles', $throwable); } // Further update @@ -148,15 +152,15 @@ public function update($installer) $this->updateDatabase(); $this->updateAssets($installer); $this->clearStatsCache(); - } catch (\Throwable $e) { - $this->collectError('Further update', $e); + } catch (\Throwable $throwable) { + $this->collectError('Further update', $throwable); } // Clean cache try { $this->cleanJoomlaCache(); - } catch (\Throwable $e) { - $this->collectError('cleanJoomlaCache', $e); + } catch (\Throwable $throwable) { + $this->collectError('cleanJoomlaCache', $throwable); } } @@ -181,13 +185,13 @@ protected function clearStatsCache() ->where($db->quoteName('folder') . ' = ' . $db->quote('system')) ->where($db->quoteName('element') . ' = ' . $db->quote('stats')) )->loadResult(); - } catch (Exception $e) { - $this->collectError(__METHOD__, $e); + } catch (Exception $exception) { + $this->collectError(__METHOD__, $exception); return; } - $params = json_decode($params, true); + $params = json_decode((string) $params, true); // Reset the last run parameter if (isset($params['lastrun'])) { @@ -205,8 +209,8 @@ protected function clearStatsCache() try { $db->setQuery($query)->execute(); - } catch (Exception $e) { - $this->collectError(__METHOD__, $e); + } catch (Exception $exception) { + $this->collectError(__METHOD__, $exception); return; } @@ -237,8 +241,8 @@ protected function updateDatabaseMysql() try { $results = $db->loadObjectList(); - } catch (Exception $e) { - $this->collectError(__METHOD__, $e); + } catch (Exception $exception) { + $this->collectError(__METHOD__, $exception); return; } @@ -252,8 +256,8 @@ protected function updateDatabaseMysql() try { $db->execute(); - } catch (Exception $e) { - $this->collectError(__METHOD__, $e); + } catch (Exception $exception) { + $this->collectError(__METHOD__, $exception); return; } @@ -343,6 +347,7 @@ protected function uninstallExtensions() throw $e; } } + return null; } /** @@ -387,10 +392,10 @@ private function migrateLogRotationPlugin($data) return; } - /** @var \Joomla\Component\Scheduler\Administrator\Extension\SchedulerComponent $component */ + /** @var SchedulerComponent $component */ $component = Factory::getApplication()->bootComponent('com_scheduler'); - /** @var \Joomla\Component\Scheduler\Administrator\Model\TaskModel $model */ + /** @var TaskModel $model */ $model = $component->getMVCFactory()->createModel('Task', 'Administrator', ['ignore_request' => true]); // Get the timeout, as configured in plg_system_logrotation @@ -433,10 +438,10 @@ private function migrateSessionGCPlugin($data) // Get the plugin parameters $params = new Registry($data->params); - /** @var \Joomla\Component\Scheduler\Administrator\Extension\SchedulerComponent $component */ + /** @var SchedulerComponent $component */ $component = Factory::getApplication()->bootComponent('com_scheduler'); - /** @var \Joomla\Component\Scheduler\Administrator\Model\TaskModel $model */ + /** @var TaskModel $model */ $model = $component->getMVCFactory()->createModel('Task', 'Administrator', ['ignore_request' => true]); $task = [ 'title' => 'Session GC', @@ -478,10 +483,10 @@ private function migrateUpdatenotificationPlugin($data) $params = new Registry($data->params); $lastrun = (int) $params->get('lastrun', time()); - /** @var \Joomla\Component\Scheduler\Administrator\Extension\SchedulerComponent $component */ + /** @var SchedulerComponent $component */ $component = Factory::getApplication()->bootComponent('com_scheduler'); - /** @var \Joomla\Component\Scheduler\Administrator\Model\TaskModel $model */ + /** @var TaskModel $model */ $model = $component->getMVCFactory()->createModel('Task', 'Administrator', ['ignore_request' => true]); $task = [ 'title' => 'Update Notification', @@ -530,8 +535,8 @@ protected function updateManifestCaches() try { $extensions = $db->loadObjectList(); - } catch (Exception $e) { - $this->collectError(__METHOD__, $e); + } catch (Exception $exception) { + $this->collectError(__METHOD__, $exception); return; } @@ -2702,7 +2707,7 @@ public function updateAssets($installer) ]; foreach ($newComponents as $component) { - /** @var \Joomla\CMS\Table\Asset $asset */ + /** @var Asset $asset */ $asset = Table::getInstance('Asset'); if ($asset->loadByName($component)) { @@ -2737,7 +2742,7 @@ public function updateAssets($installer) */ private function cleanJoomlaCache() { - /** @var \Joomla\Component\Cache\Administrator\Model\CacheModel $model */ + /** @var CacheModel $model */ $model = Factory::getApplication()->bootComponent('com_cache')->getMVCFactory() ->createModel('Cache', 'Administrator', ['ignore_request' => true]); @@ -2811,8 +2816,8 @@ private function migrateDeleteActionlogsConfiguration(): bool ->where($db->quoteName('folder') . ' = ' . $db->quote('system')) ->where($db->quoteName('element') . ' = ' . $db->quote('actionlogs')) )->loadObject(); - } catch (Exception $e) { - $this->collectError(__METHOD__, $e); + } catch (Exception $exception) { + $this->collectError(__METHOD__, $exception); return false; } @@ -2829,10 +2834,10 @@ private function migrateDeleteActionlogsConfiguration(): bool return true; } - /** @var \Joomla\Component\Scheduler\Administrator\Extension\SchedulerComponent $component */ + /** @var SchedulerComponent $component */ $component = Factory::getApplication()->bootComponent('com_scheduler'); - /** @var \Joomla\Component\Scheduler\Administrator\Model\TaskModel $model */ + /** @var TaskModel $model */ $model = $component->getMVCFactory()->createModel('Task', 'Administrator', ['ignore_request' => true]); $task = [ 'title' => 'Delete Action Logs', @@ -2851,8 +2856,8 @@ private function migrateDeleteActionlogsConfiguration(): bool try { $model->save($task); - } catch (Exception $e) { - $this->collectError(__METHOD__, $e); + } catch (Exception $exception) { + $this->collectError(__METHOD__, $exception); return false; } @@ -2880,8 +2885,8 @@ private function migratePrivacyconsentConfiguration(): bool ->where($db->quoteName('folder') . ' = ' . $db->quote('system')) ->where($db->quoteName('element') . ' = ' . $db->quote('privacyconsent')) )->loadObject(); - } catch (Exception $e) { - $this->collectError(__METHOD__, $e); + } catch (Exception $exception) { + $this->collectError(__METHOD__, $exception); return false; } @@ -2898,10 +2903,10 @@ private function migratePrivacyconsentConfiguration(): bool return true; } - /** @var \Joomla\Component\Scheduler\Administrator\Extension\SchedulerComponent $component */ + /** @var SchedulerComponent $component */ $component = Factory::getApplication()->bootComponent('com_scheduler'); - /** @var \Joomla\Component\Scheduler\Administrator\Model\TaskModel $model */ + /** @var TaskModel $model */ $model = $component->getMVCFactory()->createModel('Task', 'Administrator', ['ignore_request' => true]); $task = [ 'title' => 'Privacy Consent', @@ -2921,8 +2926,8 @@ private function migratePrivacyconsentConfiguration(): bool try { $model->save($task); - } catch (Exception $e) { - $this->collectError(__METHOD__, $e); + } catch (Exception $exception) { + $this->collectError(__METHOD__, $exception); return false; } @@ -2954,13 +2959,13 @@ private function migrateTinymceConfiguration(): bool ->where($db->quoteName('folder') . ' = ' . $db->quote('editors')) ->where($db->quoteName('element') . ' = ' . $db->quote('tinymce')) )->loadResult(); - } catch (Exception $e) { - $this->collectError(__METHOD__, $e); + } catch (Exception $exception) { + $this->collectError(__METHOD__, $exception); return false; } - $params = json_decode($params, true); + $params = json_decode((string) $params, true); // If there are no toolbars there is nothing to migrate if (!isset($params['configuration']['toolbars'])) { @@ -3028,8 +3033,8 @@ private function migrateTinymceConfiguration(): bool try { $db->setQuery($query)->execute(); - } catch (Exception $e) { - $this->collectError(__METHOD__, $e); + } catch (Exception $exception) { + $this->collectError(__METHOD__, $exception); return false; } @@ -3046,7 +3051,7 @@ private function migrateTinymceConfiguration(): bool */ private function setGuidedToursUid() { - /** @var \Joomla\Component\Cache\Administrator\Model\CacheModel $model */ + /** @var CacheModel $model */ $model = Factory::getApplication()->bootComponent('com_guidedtours')->getMVCFactory() ->createModel('Tours', 'Administrator', ['ignore_request' => true]); @@ -3148,11 +3153,9 @@ protected function fixFilenameCasing() File::move(JPATH_ROOT . $old, JPATH_ROOT . $old . '.tmp'); File::move(JPATH_ROOT . $old . '.tmp', JPATH_ROOT . $expected); } - } else { + } elseif (is_file(JPATH_ROOT . $old)) { // On Unix with both files: Delete the incorrectly cased file. - if (is_file(JPATH_ROOT . $old)) { - File::delete(JPATH_ROOT . $old); - } + File::delete(JPATH_ROOT . $old); } } } @@ -3196,7 +3199,7 @@ protected function fixFilesystemPermissions() try { // Using hard-coded string because a new language string would not be available in all cases Log::add('Fixing permissions for files and folders.', Log::INFO, 'Update'); - } catch (\RuntimeException $exception) { + } catch (\RuntimeException) { // Informational log only } diff --git a/administrator/components/com_admin/src/Model/HelpModel.php b/administrator/components/com_admin/src/Model/HelpModel.php index 2198e6430e801..18ecf16120ef0 100644 --- a/administrator/components/com_admin/src/Model/HelpModel.php +++ b/administrator/components/com_admin/src/Model/HelpModel.php @@ -34,7 +34,7 @@ class HelpModel extends BaseDatabaseModel * @var string * @since 1.6 */ - protected $help_search = null; + protected $help_search; /** * The page to be viewed @@ -42,7 +42,7 @@ class HelpModel extends BaseDatabaseModel * @var string * @since 1.6 */ - protected $page = null; + protected $page; /** * The ISO language tag @@ -50,7 +50,7 @@ class HelpModel extends BaseDatabaseModel * @var string * @since 1.6 */ - protected $lang_tag = null; + protected $lang_tag; /** * Table of contents @@ -66,7 +66,7 @@ class HelpModel extends BaseDatabaseModel * @var string * @since 1.6 */ - protected $latest_version_check = null; + protected $latest_version_check; /** * Method to get the help search string @@ -128,7 +128,7 @@ public function getLangTag() */ public function &getToc() { - if (\count($this->toc)) { + if (\count($this->toc) !== 0) { return $this->toc; } @@ -157,13 +157,13 @@ public function &getToc() foreach ($files as $file) { $buffer = file_get_contents(JPATH_BASE . '/help/' . $lang_tag . '/' . $file); - if (!preg_match('#(.*?)#', $buffer, $m)) { + if (\in_array(preg_match('#(.*?)#', $buffer, $m), [0, false], true)) { continue; } $title = trim($m[1]); - if (!$title) { + if ($title === '' || $title === '0') { continue; } @@ -171,7 +171,7 @@ public function &getToc() $title = Text::_($title); // Strip the extension - $file = preg_replace('#\.xml$|\.html$#', '', $file); + $file = preg_replace('#\.xml$|\.html$#', '', (string) $file); if ($help_search && StringHelper::strpos(StringHelper::strtolower(strip_tags($buffer)), StringHelper::strtolower($help_search)) === false) { continue; diff --git a/administrator/components/com_admin/src/Model/SysinfoModel.php b/administrator/components/com_admin/src/Model/SysinfoModel.php index 2bd59bc01ee70..b1250cd6b99bd 100644 --- a/administrator/components/com_admin/src/Model/SysinfoModel.php +++ b/administrator/components/com_admin/src/Model/SysinfoModel.php @@ -62,7 +62,7 @@ class SysinfoModel extends BaseDatabaseModel * @var string * @since 1.6 */ - protected $php_info = null; + protected $php_info; /** * Array containing the phpinfo() data. @@ -169,7 +169,7 @@ class SysinfoModel extends BaseDatabaseModel * @var string * @since 1.6 */ - protected $editor = null; + protected $editor; /** * Remove sections of data marked as private in the privateSettings @@ -216,15 +216,15 @@ protected function cleanPrivateData(array $dataArray, string $dataType = 'other' protected function cleanSectionPrivateData($sectionValues) { if (!\is_array($sectionValues)) { - if (strstr($sectionValues, JPATH_ROOT)) { + if (strstr((string) $sectionValues, JPATH_ROOT)) { $sectionValues = 'xxxxxx'; } - return \strlen($sectionValues) ? 'xxxxxx' : ''; + return \strlen((string) $sectionValues) !== 0 ? 'xxxxxx' : ''; } foreach ($sectionValues as $setting => $value) { - $sectionValues[$setting] = \strlen($value) ? 'xxxxxx' : ''; + $sectionValues[$setting] = \strlen((string) $value) !== 0 ? 'xxxxxx' : ''; } return $sectionValues; @@ -239,7 +239,7 @@ protected function cleanSectionPrivateData($sectionValues) */ public function &getPhpSettings(): array { - if (!empty($this->php_settings)) { + if ($this->php_settings !== []) { return $this->php_settings; } @@ -306,7 +306,7 @@ public function &getConfig(): array */ public function &getInfo(): array { - if (!empty($this->info)) { + if ($this->info !== []) { return $this->info; } @@ -336,7 +336,7 @@ private function getCompatPluginParameters() { $record = ExtensionHelper::getExtensionRecord('compat', 'plugin', 0, 'behaviour'); - if ($record) { + if ($record instanceof \stdClass) { $params = new Registry($record->params); return ArrayHelper::toString($params->toArray(), ':', ', '); @@ -411,14 +411,15 @@ public function &getPHPInfo(): string date_default_timezone_set('UTC'); phpinfo(INFO_GENERAL | INFO_CONFIGURATION | INFO_MODULES); $phpInfo = ob_get_clean(); - preg_match_all('#]*>(.*)#siU', $phpInfo, $output); - $output = preg_replace('#]*>#', '', $output[1][0]); - $output = preg_replace('#(\w),(\w)#', '\1, \2', $output); + preg_match_all('#]*>(.*)#siU', (string) $phpInfo, $output); + $output = preg_replace('#]*>#', '
', (string) $output[1][0]); + $output = preg_replace('#(\w),(\w)#', '\1, \2', (string) $output); $output = str_replace('
', '', $output); $output = str_replace('
', '', $output); - $output = preg_replace('#
(.*)#', '$1', $output); + $output = preg_replace('#(.*)#', '$1', (string) $output); $output = str_replace('
', '', $output); $output = str_replace('', '', $output); + $this->php_info = $output; return $this->php_info; @@ -463,12 +464,12 @@ public function getExtensions(): array try { $extensions = $db->loadObjectList(); - } catch (\Exception $e) { + } catch (\Exception $exception) { try { - Log::add(Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()), Log::WARNING, 'jerror'); - } catch (\RuntimeException $exception) { + Log::add(Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $exception->getCode(), $exception->getMessage()), Log::WARNING, 'jerror'); + } catch (\RuntimeException) { Factory::getApplication()->enqueueMessage( - Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()), + Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $exception->getCode(), $exception->getMessage()), 'warning' ); } @@ -522,7 +523,7 @@ public function getExtensions(): array */ public function getDirectory(bool $public = false): array { - if (!empty($this->directories)) { + if ($this->directories !== []) { return $this->directories; } @@ -634,9 +635,11 @@ public function getDirectory(bool $public = false): array $this->addDirectory('templates', JPATH_SITE . '/templates'); $this->addDirectory('configuration.php', JPATH_CONFIGURATION . '/configuration.php'); + // Is there a cache path in configuration.php? + $cache_path = trim((string) $registry->get('cache_path', '')); // Is there a cache path in configuration.php? - if ($cache_path = trim($registry->get('cache_path', ''))) { + if ($cache_path !== '' && $cache_path !== '0') { // Frontend and backend use same directory for caching. $this->addDirectory($cache_path, $cache_path, 'COM_ADMIN_CACHE_DIRECTORY'); } else { @@ -721,8 +724,9 @@ protected function parsePhpInfo(string $html): array { $html = strip_tags($html, '

'); $html = preg_replace('/]*>([^<]+)<\/th>/', '\1', $html); - $html = preg_replace('/]*>([^<]+)<\/td>/', '\1', $html); - $t = preg_split('/(]*>[^<]+<\/h2>)/', $html, -1, PREG_SPLIT_DELIM_CAPTURE); + $html = preg_replace('/]*>([^<]+)<\/td>/', '\1', (string) $html); + + $t = preg_split('/(]*>[^<]+<\/h2>)/', (string) $html, -1, PREG_SPLIT_DELIM_CAPTURE); $r = []; $count = \count($t); $p1 = '([^<]+)<\/info>'; diff --git a/administrator/components/com_admin/src/Service/HTML/Configuration.php b/administrator/components/com_admin/src/Service/HTML/Configuration.php index bc9058b9f6831..d3a223742c3ea 100644 --- a/administrator/components/com_admin/src/Service/HTML/Configuration.php +++ b/administrator/components/com_admin/src/Service/HTML/Configuration.php @@ -40,6 +40,6 @@ public function value($value): string $value = implode(', ', $value); } - return htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); + return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); } } diff --git a/administrator/components/com_admin/src/Service/HTML/PhpSetting.php b/administrator/components/com_admin/src/Service/HTML/PhpSetting.php index c1f18f44a8616..7bd4344493fb3 100644 --- a/administrator/components/com_admin/src/Service/HTML/PhpSetting.php +++ b/administrator/components/com_admin/src/Service/HTML/PhpSetting.php @@ -56,6 +56,6 @@ public function set($val) */ public function string($val) { - return !empty($val) ? $val : Text::_('JNONE'); + return empty($val) ? Text::_('JNONE') : $val; } } diff --git a/administrator/components/com_admin/src/Service/HTML/System.php b/administrator/components/com_admin/src/Service/HTML/System.php index a2b3c369a8cef..1f173df359e58 100644 --- a/administrator/components/com_admin/src/Service/HTML/System.php +++ b/administrator/components/com_admin/src/Service/HTML/System.php @@ -32,6 +32,6 @@ class System */ public function server($val) { - return !empty($val) ? $val : Text::_('COM_ADMIN_NA'); + return empty($val) ? Text::_('COM_ADMIN_NA') : $val; } } diff --git a/administrator/components/com_admin/src/View/Help/HtmlView.php b/administrator/components/com_admin/src/View/Help/HtmlView.php index 9d893b8cd8a70..dc38a29548b7e 100644 --- a/administrator/components/com_admin/src/View/Help/HtmlView.php +++ b/administrator/components/com_admin/src/View/Help/HtmlView.php @@ -32,7 +32,7 @@ class HtmlView extends BaseHtmlView * @var string * @since 1.6 */ - protected $helpSearch = null; + protected $helpSearch; /** * The page to be viewed @@ -40,7 +40,7 @@ class HtmlView extends BaseHtmlView * @var string * @since 1.6 */ - protected $page = null; + protected $page; /** * The iso language tag @@ -48,7 +48,7 @@ class HtmlView extends BaseHtmlView * @var string * @since 1.6 */ - protected $languageTag = null; + protected $languageTag; /** * Table of contents diff --git a/administrator/components/com_admin/src/View/Sysinfo/HtmlView.php b/administrator/components/com_admin/src/View/Sysinfo/HtmlView.php index 4fc9b4249b42b..4ce29bcdcc0ea 100644 --- a/administrator/components/com_admin/src/View/Sysinfo/HtmlView.php +++ b/administrator/components/com_admin/src/View/Sysinfo/HtmlView.php @@ -59,7 +59,7 @@ class HtmlView extends BaseHtmlView * @var string * @since 1.6 */ - protected $phpInfo = null; + protected $phpInfo; /** * Information about writable state of directories diff --git a/administrator/components/com_admin/tmpl/help/langforum.php b/administrator/components/com_admin/tmpl/help/langforum.php index c7f8518d8f8fd..9919dea8adfde 100644 --- a/administrator/components/com_admin/tmpl/help/langforum.php +++ b/administrator/components/com_admin/tmpl/help/langforum.php @@ -1,5 +1,7 @@ getLanguage()->load('mod_menu', JPATH_ADMINISTRATOR); $forumId = (int) Text::_('MOD_MENU_HELP_SUPPORT_OFFICIAL_LANGUAGE_FORUM_VALUE'); -if (empty($forumId)) { +if ($forumId === 0) { $forumId = 511; } diff --git a/administrator/components/com_admin/tmpl/sysinfo/default_system.php b/administrator/components/com_admin/tmpl/sysinfo/default_system.php index 06e1bdb41f60a..4e1486f2bd850 100644 --- a/administrator/components/com_admin/tmpl/sysinfo/default_system.php +++ b/administrator/components/com_admin/tmpl/sysinfo/default_system.php @@ -133,7 +133,7 @@ - info['useragent'], ENT_COMPAT, 'UTF-8'); ?> + info['useragent'], ENT_COMPAT, 'UTF-8'); ?> diff --git a/administrator/components/com_associations/layouts/joomla/searchtools/default.php b/administrator/components/com_associations/layouts/joomla/searchtools/default.php index 12b04a06c2b28..4275a64bde482 100644 --- a/administrator/components/com_associations/layouts/joomla/searchtools/default.php +++ b/administrator/components/com_associations/layouts/joomla/searchtools/default.php @@ -20,7 +20,7 @@ $data = $displayData; // Receive overridable options -$data['options'] = !empty($data['options']) ? $data['options'] : []; +$data['options'] = empty($data['options']) ? [] : $data['options']; $noResultsText = ''; $hideActiveFilters = false; @@ -69,8 +69,8 @@ 'showSelector' => $showSelector, 'orderFieldSelector' => '#list_fullordering', 'showNoResults' => !empty($noResultsText), - 'noResultsText' => !empty($noResultsText) ? $noResultsText : '', - 'formSelector' => !empty($data['options']['formSelector']) ? $data['options']['formSelector'] : '#adminForm', + 'noResultsText' => empty($noResultsText) ? '' : $noResultsText, + 'formSelector' => empty($data['options']['formSelector']) ? '#adminForm' : $data['options']['formSelector'], ]; // Merge custom options in the options array. diff --git a/administrator/components/com_associations/src/Controller/AssociationController.php b/administrator/components/com_associations/src/Controller/AssociationController.php index 54db9cba3e9e1..abadc9a449bc0 100644 --- a/administrator/components/com_associations/src/Controller/AssociationController.php +++ b/administrator/components/com_associations/src/Controller/AssociationController.php @@ -39,7 +39,7 @@ class AssociationController extends FormController */ public function edit($key = null, $urlVar = null) { - list($extensionName, $typeName) = explode('.', $this->input->get('itemtype', '', 'string'), 2); + [$extensionName, $typeName] = explode('.', (string) $this->input->get('itemtype', '', 'string'), 2); $id = $this->input->get('id', 0, 'int'); @@ -67,7 +67,7 @@ public function cancel($key = null) { $this->checkToken(); - list($extensionName, $typeName) = explode('.', $this->input->get('itemtype', '', 'string'), 2); + [$extensionName, $typeName] = explode('.', (string) $this->input->get('itemtype', '', 'string'), 2); // Only check in, if component item type allows to check out. if (AssociationsHelper::typeSupportsCheckout($extensionName, $typeName)) { @@ -75,12 +75,12 @@ public function cancel($key = null) $targetId = $this->input->get('target-id', '', 'string'); if ($targetId !== '') { - $ids = array_unique(explode(',', $targetId)); + $ids = array_unique(explode(',', (string) $targetId)); } $ids[] = $this->input->get('id', 0, 'int'); - foreach ($ids as $key => $id) { + foreach ($ids as $id) { AssociationsHelper::getItem($extensionName, $typeName, $id)->checkIn(); } } diff --git a/administrator/components/com_associations/src/Controller/AssociationsController.php b/administrator/components/com_associations/src/Controller/AssociationsController.php index dd24dad3cd972..d91ac6eb0272f 100644 --- a/administrator/components/com_associations/src/Controller/AssociationsController.php +++ b/administrator/components/com_associations/src/Controller/AssociationsController.php @@ -12,6 +12,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Router\Route; use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper; @@ -42,7 +43,7 @@ class AssociationsController extends AdminController * @param string $prefix The class prefix. Optional. * @param array $config The array of possible config values. Optional. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel|boolean + * @return BaseDatabaseModel|boolean * * @since 3.7.0 */ @@ -94,7 +95,7 @@ public function checkin() $this->setRedirect(Route::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); // Figure out if the item supports checking and check it in - list($extensionName, $typeName) = explode('.', $this->input->get('itemtype')); + [$extensionName, $typeName] = explode('.', (string) $this->input->get('itemtype')); $extension = AssociationsHelper::getSupportedExtension($extensionName); $types = $extension->get('types'); @@ -110,7 +111,7 @@ public function checkin() $cid = (array) $this->input->get('cid', [], 'int'); - if (empty($cid)) { + if ($cid === []) { // Seems we don't have an id to work with. return; } diff --git a/administrator/components/com_associations/src/Dispatcher/Dispatcher.php b/administrator/components/com_associations/src/Dispatcher/Dispatcher.php index 4875f196e2110..d62e262eb59f2 100644 --- a/administrator/components/com_associations/src/Dispatcher/Dispatcher.php +++ b/administrator/components/com_associations/src/Dispatcher/Dispatcher.php @@ -43,7 +43,7 @@ protected function checkAccess() $itemType = $this->input->get('itemtype', '', 'string'); if ($itemType !== '') { - list($extensionName, $typeName) = explode('.', $itemType); + [$extensionName, $typeName] = explode('.', (string) $itemType); if (!AssociationsHelper::hasSupport($extensionName)) { throw new \Exception( diff --git a/administrator/components/com_associations/src/Field/ItemlanguageField.php b/administrator/components/com_associations/src/Field/ItemlanguageField.php index 9c7d24754f4f7..91804a81f91e2 100644 --- a/administrator/components/com_associations/src/Field/ItemlanguageField.php +++ b/administrator/components/com_associations/src/Field/ItemlanguageField.php @@ -46,7 +46,7 @@ protected function getOptions() { $input = Factory::getApplication()->getInput(); - list($extensionName, $typeName) = explode('.', $input->get('itemtype', '', 'string'), 2); + [$extensionName, $typeName] = explode('.', (string) $input->get('itemtype', '', 'string'), 2); // Get the extension specific helper method $helper = AssociationsHelper::getExtensionHelper($extensionName); diff --git a/administrator/components/com_associations/src/Field/Modal/AssociationField.php b/administrator/components/com_associations/src/Field/Modal/AssociationField.php index e68292c596f38..b74acba3e151c 100644 --- a/administrator/components/com_associations/src/Field/Modal/AssociationField.php +++ b/administrator/components/com_associations/src/Field/Modal/AssociationField.php @@ -46,7 +46,7 @@ protected function getInput() { // @todo USE Layouts here!!! // The active item id field. - $value = (int) $this->value ?: ''; + $value = (int) $this->value !== 0 ? (int) $this->value : ''; $doc = Factory::getApplication()->getDocument(); $wa = $doc->getWebAssetManager(); @@ -68,7 +68,7 @@ protected function getInput() $html[] = '' . ' ' . Text::_('JCLEAR') diff --git a/administrator/components/com_associations/src/Helper/AssociationsHelper.php b/administrator/components/com_associations/src/Helper/AssociationsHelper.php index b185c9907e73f..8083e6e3f0e9a 100644 --- a/administrator/components/com_associations/src/Helper/AssociationsHelper.php +++ b/administrator/components/com_associations/src/Helper/AssociationsHelper.php @@ -10,6 +10,7 @@ namespace Joomla\Component\Associations\Administrator\Helper; +use Joomla\CMS\Association\AssociationExtensionHelper; use Joomla\CMS\Association\AssociationExtensionInterface; use Joomla\CMS\Association\AssociationServiceInterface; use Joomla\CMS\Factory; @@ -18,6 +19,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; +use Joomla\CMS\Table\Table; use Joomla\Database\ParameterType; use Joomla\Registry\Registry; @@ -38,7 +40,7 @@ class AssociationsHelper extends ContentHelper * @var array * @since 3.7.0 */ - public static $extensionsSupport = null; + public static $extensionsSupport; /** * List of extensions name with support @@ -76,7 +78,7 @@ public static function getAssociationList($extensionName, $typeName, $itemId) * * @param string $extensionName The extension name with com_ * - * @return \Joomla\CMS\Association\AssociationExtensionHelper|null + * @return AssociationExtensionHelper|null * * @since 3.7.0 */ @@ -98,7 +100,7 @@ public static function getExtensionHelper($extensionName) * @param string $typeName The item type * @param int $itemId The id of item for which we need the associated items * - * @return \Joomla\CMS\Table\Table|null + * @return Table|null * * @since 3.7.0 */ @@ -193,7 +195,7 @@ private static function getExtensionHelperClassName($extensionName) */ private static function getExtensionRealName($extensionName) { - return strpos($extensionName, 'com_') === false ? $extensionName : substr($extensionName, 4); + return str_contains($extensionName, 'com_') ? substr($extensionName, 4) : $extensionName; } /** @@ -317,7 +319,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId $text = $language->lang_code; $tooltip = '' . htmlspecialchars($language->title, ENT_QUOTES, 'UTF-8') . '
' - . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '

' . $additional; + . htmlspecialchars((string) $title, ENT_QUOTES, 'UTF-8') . '

' . $additional; $classes = 'badge ' . $labelClass; $items[$langCode]['link'] = '' . $text . '' @@ -362,7 +364,7 @@ public static function getSupportedExtensions() * * @param string $extensionName The extension identifier. * - * @return \Joomla\Registry\Registry The item properties. + * @return Registry The item properties. * * @since 3.7.0 */ @@ -409,7 +411,7 @@ public static function getSupportedExtension($extensionName) $title = $helper->getTypeTitle($typeName); $languageKey = $typeName; - $typeNameExploded = explode('.', $typeName); + $typeNameExploded = explode('.', (string) $typeName); if (array_pop($typeNameExploded) === 'category') { $languageKey = strtoupper($extensionName) . '_CATEGORIES'; @@ -662,8 +664,8 @@ public static function getLanguagefilterPluginId() try { $result = (int) $db->loadResult(); - } catch (\RuntimeException $e) { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + } catch (\RuntimeException $runtimeException) { + Factory::getApplication()->enqueueMessage($runtimeException->getMessage(), 'error'); } return $result; diff --git a/administrator/components/com_associations/src/Model/AssociationModel.php b/administrator/components/com_associations/src/Model/AssociationModel.php index 1f366ecf36ead..8486301cb9c67 100644 --- a/administrator/components/com_associations/src/Model/AssociationModel.php +++ b/administrator/components/com_associations/src/Model/AssociationModel.php @@ -10,6 +10,7 @@ namespace Joomla\Component\Associations\Administrator\Model; +use Joomla\CMS\Form\Form; use Joomla\CMS\MVC\Model\ListModel; // phpcs:disable PSR1.Files.SideEffects @@ -29,7 +30,7 @@ class AssociationModel extends ListModel * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * - * @return \Joomla\CMS\Form\Form|boolean A Form object on success, false on failure + * @return Form|boolean A Form object on success, false on failure * * @since 3.7.0 */ @@ -38,6 +39,6 @@ public function getForm($data = [], $loadData = true) // Get the form. $form = $this->loadForm('com_associations.association', 'association', ['control' => 'jform', 'load_data' => $loadData]); - return !empty($form) ? $form : false; + return empty($form) ? false : $form; } } diff --git a/administrator/components/com_associations/src/Model/AssociationsModel.php b/administrator/components/com_associations/src/Model/AssociationsModel.php index 8f16fc2ddafd9..f203bd69489fc 100644 --- a/administrator/components/com_associations/src/Model/AssociationsModel.php +++ b/administrator/components/com_associations/src/Model/AssociationsModel.php @@ -154,7 +154,7 @@ protected function getListQuery() { $type = null; - list($extensionName, $typeName) = explode('.', $this->state->get('itemtype'), 2); + [$extensionName, $typeName] = explode('.', (string) $this->state->get('itemtype'), 2); $extension = AssociationsHelper::getSupportedExtension($extensionName); $types = $extension->get('types'); @@ -359,7 +359,7 @@ protected function getListQuery() if ($typeName === 'category') { $query->where($db->quoteName('a.extension') . ' = :extensionname') ->bind(':extensionname', $extensionName); - } elseif ($typeNameExploded = explode('.', $typeName)) { + } elseif ($typeNameExploded = explode('.', $typeName) !== []) { if (\count($typeNameExploded) > 1 && array_pop($typeNameExploded) === 'category') { $section = implode('.', $typeNameExploded); $extensionNameSection = $extensionName . '.' . $section; @@ -403,7 +403,7 @@ protected function getListQuery() // Filter on the level. if ($level = $this->getState('filter.level')) { - $queryLevel = ((int) $level + (int) $baselevel - 1); + $queryLevel = ((int) $level + $baselevel - 1); $query->where($db->quoteName('a.level') . ' <= :alevel') ->bind(':alevel', $queryLevel, ParameterType::INTEGER); } @@ -423,12 +423,12 @@ protected function getListQuery() // Filter by search in name. if ($search = $this->getState('filter.search')) { - if (stripos($search, 'id:') === 0) { - $search = (int) substr($search, 3); + if (stripos((string) $search, 'id:') === 0) { + $search = (int) substr((string) $search, 3); $query->where($db->quoteName($fields['id']) . ' = :searchid') ->bind(':searchid', $search, ParameterType::INTEGER); } else { - $search = '%' . str_replace(' ', '%', trim($search)) . '%'; + $search = '%' . str_replace(' ', '%', trim((string) $search)) . '%'; $query->where('(' . $db->quoteName($fields['title']) . ' LIKE :title' . ' OR ' . $db->quoteName($fields['alias']) . ' LIKE :alias)') ->bind(':title', $search) @@ -480,7 +480,7 @@ public function purge($context = '', $key = '') try { $db->execute(); - } catch (ExecutionFailureException $e) { + } catch (ExecutionFailureException) { $app->enqueueMessage(Text::_('COM_ASSOCIATIONS_PURGE_FAILED'), 'error'); return false; @@ -543,7 +543,7 @@ public function clean($context = '', $key = '') try { $db->execute(); - } catch (ExecutionFailureException $e) { + } catch (ExecutionFailureException) { $app->enqueueMessage(Text::_('COM_ASSOCIATIONS_DELETE_ORPHANS_FAILED'), 'error'); return false; diff --git a/administrator/components/com_associations/src/View/Association/HtmlView.php b/administrator/components/com_associations/src/View/Association/HtmlView.php index d0e662e404d84..5d0c44ab0fa60 100644 --- a/administrator/components/com_associations/src/View/Association/HtmlView.php +++ b/administrator/components/com_associations/src/View/Association/HtmlView.php @@ -57,7 +57,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry * * @since 3.7.0 */ @@ -225,7 +225,7 @@ public function display($tpl = null): void $model = $this->getModel(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -235,7 +235,7 @@ public function display($tpl = null): void $input = $this->app->getInput(); $this->referenceId = $input->get('id', 0, 'int'); - [$extensionName, $typeName] = explode('.', $input->get('itemtype', '', 'string'), 2); + [$extensionName, $typeName] = explode('.', (string) $input->get('itemtype', '', 'string'), 2); /** @var Registry $extension */ $extension = AssociationsHelper::getSupportedExtension($extensionName); @@ -275,7 +275,7 @@ public function display($tpl = null): void if (array_pop($typeNameExploded) === 'category') { $this->typeName = 'category'; - if ($typeNameExploded) { + if ($typeNameExploded !== []) { $extensionName .= '.' . implode('.', $typeNameExploded); } @@ -305,7 +305,7 @@ public function display($tpl = null): void $this->targetTitle = ''; if ($target = $input->get('target', '', 'string')) { - $matches = preg_split("#[\:]+#", $target); + $matches = preg_split("#[\:]+#", (string) $target); $this->targetAction = $matches[2]; $this->targetId = $matches[1]; $this->targetLanguage = $matches[0]; diff --git a/administrator/components/com_associations/src/View/Associations/HtmlView.php b/administrator/components/com_associations/src/View/Associations/HtmlView.php index 179ed3e1e745f..6c7be63f2c08a 100644 --- a/administrator/components/com_associations/src/View/Associations/HtmlView.php +++ b/administrator/components/com_associations/src/View/Associations/HtmlView.php @@ -11,13 +11,16 @@ namespace Joomla\Component\Associations\Administrator\View\Associations; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Router\Route; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper; use Joomla\Component\Associations\Administrator\Model\AssociationsModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -30,6 +33,10 @@ */ class HtmlView extends BaseHtmlView { + /** + * @var string + */ + public $editUri; /** * An array of items * @@ -42,7 +49,7 @@ class HtmlView extends BaseHtmlView /** * The pagination object * - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination * * @since 3.7.0 */ @@ -60,11 +67,11 @@ class HtmlView extends BaseHtmlView /** * Selected item type properties. * - * @var \Joomla\Registry\Registry + * @var Registry * * @since 3.7.0 */ - public $itemType = null; + public $itemType; /** * Main Extension Name @@ -105,7 +112,7 @@ class HtmlView extends BaseHtmlView /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form */ public $filterForm; @@ -140,7 +147,7 @@ public function display($tpl = null) } elseif ($this->state->get('itemtype') != '' && $this->state->get('language') != '') { $type = null; - list($extensionName, $typeName) = explode('.', $this->state->get('itemtype'), 2); + [$extensionName, $typeName] = explode('.', (string) $this->state->get('itemtype'), 2); $extension = AssociationsHelper::getSupportedExtension($extensionName); @@ -207,11 +214,9 @@ public function display($tpl = null) if (empty($support['catid'])) { $this->filterForm->setFieldAttribute('category_id', 'extension', $extensionName, 'filter'); - if ($this->getLayout() == 'modal') { - // We need to change the category filter to only show categories tagged to All or to the forced language. - if ($forcedLanguage = Factory::getApplication()->getInput()->get('forcedLanguage', '', 'CMD')) { - $this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter'); - } + // We need to change the category filter to only show categories tagged to All or to the forced language. + if ($this->getLayout() == 'modal' && $forcedLanguage = Factory::getApplication()->getInput()->get('forcedLanguage', '', 'CMD')) { + $this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter'); } } @@ -229,7 +234,7 @@ public function display($tpl = null) } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new \Exception(implode("\n", $errors), 500); } @@ -249,7 +254,7 @@ protected function addToolbar() { $user = $this->getCurrentUser(); - if (isset($this->typeName) && isset($this->extensionName)) { + if ($this->typeName !== null && $this->extensionName !== null) { $helper = AssociationsHelper::getExtensionHelper($this->extensionName); $title = $helper->getTypeTitle($this->typeName); @@ -274,7 +279,7 @@ protected function addToolbar() $toolbar = $this->getDocument()->getToolbar(); if ($user->authorise('core.admin', 'com_associations') || $user->authorise('core.options', 'com_associations')) { - if (!isset($this->typeName)) { + if ($this->typeName === null) { $toolbar->standardButton('', 'COM_ASSOCIATIONS_PURGE', 'associations.purge') ->icon('icon-purge') ->listCheck(false); diff --git a/administrator/components/com_associations/tmpl/association/edit.php b/administrator/components/com_associations/tmpl/association/edit.php index efbe432ed63df..dec97746d3e22 100644 --- a/administrator/components/com_associations/tmpl/association/edit.php +++ b/administrator/components/com_associations/tmpl/association/edit.php @@ -13,7 +13,6 @@ use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; -use Joomla\Component\Associations\Administrator\View\Association\HtmlView; /** @var HtmlView $this */ diff --git a/administrator/components/com_banners/src/Controller/BannerController.php b/administrator/components/com_banners/src/Controller/BannerController.php index e221e16668f19..051daff5241be 100644 --- a/administrator/components/com_banners/src/Controller/BannerController.php +++ b/administrator/components/com_banners/src/Controller/BannerController.php @@ -71,14 +71,14 @@ protected function allowAdd($data = []) */ protected function allowEdit($data = [], $key = 'id') { - $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + $recordId = (int) isset($data[$key]) !== 0 ? $data[$key] : 0; $categoryId = 0; if ($recordId) { $categoryId = (int) $this->getModel()->getItem($recordId)->catid; } - if ($categoryId) { + if ($categoryId !== 0) { // The category has been set. Check the category permissions. return $this->app->getIdentity()->authorise('core.edit', $this->option . '.category.' . $categoryId); } diff --git a/administrator/components/com_banners/src/Controller/BannersController.php b/administrator/components/com_banners/src/Controller/BannersController.php index 4c44abbc47374..13a5e5c01b295 100644 --- a/administrator/components/com_banners/src/Controller/BannersController.php +++ b/administrator/components/com_banners/src/Controller/BannersController.php @@ -14,7 +14,9 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\AdminController; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Response\JsonResponse; +use Joomla\Component\Banners\Administrator\Model\BannerModel; use Joomla\Input\Input; use Joomla\Utilities\ArrayHelper; @@ -61,7 +63,7 @@ public function __construct($config = [], ?MVCFactoryInterface $factory = null, * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model. + * @return BaseDatabaseModel The model. * * @since 1.6 */ @@ -90,23 +92,18 @@ public function sticky_publish() // Remove zero values resulting from input filter $ids = array_filter($ids); - if (empty($ids)) { + if ($ids === []) { $this->app->enqueueMessage(Text::_('COM_BANNERS_NO_BANNERS_SELECTED'), 'warning'); } else { // Get the model. - /** @var \Joomla\Component\Banners\Administrator\Model\BannerModel $model */ + /** @var BannerModel $model */ $model = $this->getModel(); // Change the state of the records. if (!$model->stick($ids, $value)) { $this->app->enqueueMessage($model->getError(), 'warning'); } else { - if ($value == 1) { - $ntext = 'COM_BANNERS_N_BANNERS_STUCK'; - } else { - $ntext = 'COM_BANNERS_N_BANNERS_UNSTUCK'; - } - + $ntext = $value == 1 ? 'COM_BANNERS_N_BANNERS_STUCK' : 'COM_BANNERS_N_BANNERS_UNSTUCK'; $this->setMessage(Text::plural($ntext, \count($ids))); } } diff --git a/administrator/components/com_banners/src/Controller/ClientsController.php b/administrator/components/com_banners/src/Controller/ClientsController.php index 9a73d182ae412..ba8c360697f8a 100644 --- a/administrator/components/com_banners/src/Controller/ClientsController.php +++ b/administrator/components/com_banners/src/Controller/ClientsController.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Banners\Administrator\Controller; use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -38,7 +39,7 @@ class ClientsController extends AdminController * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model. + * @return BaseDatabaseModel The model. * * @since 1.6 */ diff --git a/administrator/components/com_banners/src/Controller/DisplayController.php b/administrator/components/com_banners/src/Controller/DisplayController.php index fe11bc9a1bc68..3fc824fb71a08 100644 --- a/administrator/components/com_banners/src/Controller/DisplayController.php +++ b/administrator/components/com_banners/src/Controller/DisplayController.php @@ -56,7 +56,7 @@ public function display($cachable = false, $urlparams = []) // Check for edit form. if ($view === 'banner' && $layout === 'edit' && !$this->checkEditId('com_banners.edit.banner', $id)) { // Somehow the person just went to the form - we don't allow that. - if (!\count($this->app->getMessageQueue())) { + if (\count($this->app->getMessageQueue()) === 0) { $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error'); } @@ -67,7 +67,7 @@ public function display($cachable = false, $urlparams = []) if ($view === 'client' && $layout === 'edit' && !$this->checkEditId('com_banners.edit.client', $id)) { // Somehow the person just went to the form - we don't allow that. - if (!\count($this->app->getMessageQueue())) { + if (\count($this->app->getMessageQueue()) === 0) { $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error'); } diff --git a/administrator/components/com_banners/src/Controller/TracksController.php b/administrator/components/com_banners/src/Controller/TracksController.php index 1652afc823768..292a42f5c7e24 100644 --- a/administrator/components/com_banners/src/Controller/TracksController.php +++ b/administrator/components/com_banners/src/Controller/TracksController.php @@ -13,6 +13,8 @@ use Joomla\CMS\Application\ApplicationHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\Component\Banners\Administrator\Model\TracksModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -40,7 +42,7 @@ class TracksController extends BaseController * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model. + * @return BaseDatabaseModel The model. * * @since 1.6 */ @@ -62,7 +64,7 @@ public function delete() $this->checkToken(); // Get the model. - /** @var \Joomla\Component\Banners\Administrator\Model\TracksModel $model */ + /** @var TracksModel $model */ $model = $this->getModel(); // Load the filter state. @@ -111,7 +113,7 @@ public function display($cachable = false, $urlparams = []) $this->checkToken('GET'); // Get the model for the view. - /** @var \Joomla\Component\Banners\Administrator\Model\TracksModel $model */ + /** @var TracksModel $model */ $model = $this->getModel($vName); // Load the filter state. diff --git a/administrator/components/com_banners/src/Field/BannerclientField.php b/administrator/components/com_banners/src/Field/BannerclientField.php index 9afb894575d82..1ba7d9056a16d 100644 --- a/administrator/components/com_banners/src/Field/BannerclientField.php +++ b/administrator/components/com_banners/src/Field/BannerclientField.php @@ -39,7 +39,7 @@ class BannerclientField extends ListField * * @since 1.6 */ - public function getOptions() + protected function getOptions() { return array_merge(parent::getOptions(), BannersHelper::getClientOptions()); } diff --git a/administrator/components/com_banners/src/Field/ClicksField.php b/administrator/components/com_banners/src/Field/ClicksField.php index 80d34d4046515..e1a257be757dc 100644 --- a/administrator/components/com_banners/src/Field/ClicksField.php +++ b/administrator/components/com_banners/src/Field/ClicksField.php @@ -44,7 +44,7 @@ protected function getInput() $onclick = ' onclick="document.getElementById(\'' . $this->id . '\').value=\'0\';"'; return '
' + . htmlspecialchars((string) $this->value, ENT_COMPAT, 'UTF-8') . '" readonly="readonly">' . '
'; } diff --git a/administrator/components/com_banners/src/Field/ImpmadeField.php b/administrator/components/com_banners/src/Field/ImpmadeField.php index 3cf5a25574a80..d7fc08bf8cae5 100644 --- a/administrator/components/com_banners/src/Field/ImpmadeField.php +++ b/administrator/components/com_banners/src/Field/ImpmadeField.php @@ -44,7 +44,7 @@ protected function getInput() $onclick = ' onclick="document.getElementById(\'' . $this->id . '\').value=\'0\';"'; return '
' + . htmlspecialchars((string) $this->value, ENT_COMPAT, 'UTF-8') . '" readonly="readonly">' . '
'; } diff --git a/administrator/components/com_banners/src/Field/ImptotalField.php b/administrator/components/com_banners/src/Field/ImptotalField.php index 2fc6b6c53cf5e..eef6ccdb08531 100644 --- a/administrator/components/com_banners/src/Field/ImptotalField.php +++ b/administrator/components/com_banners/src/Field/ImptotalField.php @@ -42,14 +42,14 @@ class ImptotalField extends FormField protected function getInput() { $class = ' class="form-control validate-numeric text_area"'; - $onchange = ' onchange="document.getElementById(\'' . $this->id . '_unlimited\').checked=document.getElementById(\'' . $this->id + $onchange = ' onchange="document.getElementById(\'' . $this->id . "_unlimited').checked=document.getElementById('" . $this->id . '\').value==\'\';"'; - $onclick = ' onclick="if (document.getElementById(\'' . $this->id . '_unlimited\').checked) document.getElementById(\'' . $this->id + $onclick = ' onclick="if (document.getElementById(\'' . $this->id . "_unlimited').checked) document.getElementById('" . $this->id . '\').value=\'\';"'; $value = empty($this->value) ? '' : $this->value; $checked = empty($this->value) ? ' checked="checked"' : ''; - return '' . '
' . '
'; diff --git a/administrator/components/com_banners/src/Helper/BannersHelper.php b/administrator/components/com_banners/src/Helper/BannersHelper.php index cd867e89e53e5..65853fbd7eccd 100644 --- a/administrator/components/com_banners/src/Helper/BannersHelper.php +++ b/administrator/components/com_banners/src/Helper/BannersHelper.php @@ -16,6 +16,7 @@ use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Table\Table; +use Joomla\Component\Banners\Administrator\Table\ClientTable; use Joomla\Database\ParameterType; // phpcs:disable PSR1.Files.SideEffects @@ -67,8 +68,8 @@ public static function updateReset() try { $rows = $db->loadObjectList(); - } catch (\RuntimeException $e) { - $app->enqueueMessage($e->getMessage(), 'error'); + } catch (\RuntimeException $runtimeException) { + $app->enqueueMessage($runtimeException->getMessage(), 'error'); return false; } @@ -77,7 +78,7 @@ public static function updateReset() $purchaseType = $row->purchase_type; if ($purchaseType < 0 && $row->cid) { - /** @var \Joomla\Component\Banners\Administrator\Table\ClientTable $client */ + /** @var ClientTable $client */ $client = Table::getInstance('ClientTable', '\\Joomla\\Component\\Banners\\Administrator\\Table\\'); $client->load($row->cid); $purchaseType = $client->purchase_type; @@ -164,8 +165,8 @@ public static function getClientOptions() try { $options = $db->loadObjectList(); - } catch (\RuntimeException $e) { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + } catch (\RuntimeException $runtimeException) { + Factory::getApplication()->enqueueMessage($runtimeException->getMessage(), 'error'); } array_unshift($options, HTMLHelper::_('select.option', '0', Text::_('COM_BANNERS_NO_CLIENT'))); diff --git a/administrator/components/com_banners/src/Model/BannerModel.php b/administrator/components/com_banners/src/Model/BannerModel.php index b03de8fd0eb8f..92ae4b65cd9b4 100644 --- a/administrator/components/com_banners/src/Model/BannerModel.php +++ b/administrator/components/com_banners/src/Model/BannerModel.php @@ -17,7 +17,9 @@ use Joomla\CMS\Table\Table; use Joomla\CMS\Table\TableInterface; use Joomla\CMS\Versioning\VersionableModelTrait; +use Joomla\Component\Banners\Administrator\Table\BannerTable; use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper; +use Joomla\Component\Categories\Administrator\Model\CategoryModel; use Joomla\Database\ParameterType; // phpcs:disable PSR1.Files.SideEffects @@ -110,7 +112,7 @@ protected function batchClient($value, $pks, $contexts) // Set the variables $user = $this->getCurrentUser(); - /** @var \Joomla\Component\Banners\Administrator\Table\BannerTable $table */ + /** @var BannerTable $table */ $table = $this->getTable(); foreach ($pks as $pk) { @@ -285,18 +287,16 @@ protected function loadFormData() */ public function stick(&$pks, $value = 1) { - /** @var \Joomla\Component\Banners\Administrator\Table\BannerTable $table */ + /** @var BannerTable $table */ $table = $this->getTable(); $pks = (array) $pks; // Access checks. foreach ($pks as $i => $pk) { - if ($table->load($pk)) { - if (!$this->canEditState($table)) { - // Prune items that you can't change. - unset($pks[$i]); - Factory::getApplication()->enqueueMessage(Text::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), 'error'); - } + if ($table->load($pk) && !$this->canEditState($table)) { + // Prune items that you can't change. + unset($pks[$i]); + Factory::getApplication()->enqueueMessage(Text::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), 'error'); } } @@ -418,14 +418,14 @@ public function save($data) if ($createCategory && $this->canCreateCategory()) { $category = [ // Remove #new# prefix, if exists. - 'title' => strpos($data['catid'], '#new#') === 0 ? substr($data['catid'], 5) : $data['catid'], + 'title' => str_starts_with((string) $data['catid'], '#new#') ? substr((string) $data['catid'], 5) : $data['catid'], 'parent_id' => 1, 'extension' => 'com_banners', 'language' => $data['language'], 'published' => 1, ]; - /** @var \Joomla\Component\Categories\Administrator\Model\CategoryModel $categoryModel */ + /** @var CategoryModel $categoryModel */ $categoryModel = Factory::getApplication()->bootComponent('com_categories') ->getMVCFactory()->createModel('Category', 'Administrator', ['ignore_request' => true]); @@ -442,18 +442,16 @@ public function save($data) // Alter the name for save as copy if ($input->get('task') == 'save2copy') { - /** @var \Joomla\Component\Banners\Administrator\Table\BannerTable $origTable */ + /** @var BannerTable $origTable */ $origTable = clone $this->getTable(); $origTable->load($input->getInt('id')); if ($data['name'] == $origTable->name) { - list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']); + [$name, $alias] = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']); $data['name'] = $name; $data['alias'] = $alias; - } else { - if ($data['alias'] == $origTable->alias) { - $data['alias'] = ''; - } + } elseif ($data['alias'] == $origTable->alias) { + $data['alias'] = ''; } $data['state'] = 0; diff --git a/administrator/components/com_banners/src/Model/BannersModel.php b/administrator/components/com_banners/src/Model/BannersModel.php index a835d5bb23f5a..a826cfca81f63 100644 --- a/administrator/components/com_banners/src/Model/BannersModel.php +++ b/administrator/components/com_banners/src/Model/BannersModel.php @@ -178,12 +178,12 @@ protected function getListQuery() // Filter by search in title if ($search = $this->getState('filter.search')) { - if (stripos($search, 'id:') === 0) { - $search = (int) substr($search, 3); + if (stripos((string) $search, 'id:') === 0) { + $search = (int) substr((string) $search, 3); $query->where($db->quoteName('a.id') . ' = :search') ->bind(':search', $search, ParameterType::INTEGER); } else { - $search = '%' . str_replace(' ', '%', trim($search)) . '%'; + $search = '%' . str_replace(' ', '%', trim((string) $search)) . '%'; $query->where('(' . $db->quoteName('a.name') . ' LIKE :search1 OR ' . $db->quoteName('a.alias') . ' LIKE :search2)') ->bind([':search1', ':search2'], $search); } @@ -196,7 +196,7 @@ protected function getListQuery() } // Filter on the level. - if ($level = (int) $this->getState('filter.level')) { + if ($level = (int) $this->getState('filter.level') !== 0) { $query->where($db->quoteName('c.level') . ' <= :level') ->bind(':level', $level, ParameterType::INTEGER); } diff --git a/administrator/components/com_banners/src/Model/ClientModel.php b/administrator/components/com_banners/src/Model/ClientModel.php index 6378292da6ab2..07b5e5e2a6840 100644 --- a/administrator/components/com_banners/src/Model/ClientModel.php +++ b/administrator/components/com_banners/src/Model/ClientModel.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Banners\Administrator\Model; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\MVC\Model\AdminModel; use Joomla\CMS\Table\Table; use Joomla\CMS\Versioning\VersionableModelTrait; @@ -85,7 +86,7 @@ protected function canEditState($record) * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * - * @return \Joomla\CMS\Form\Form|boolean A Form object on success, false on failure + * @return Form|boolean A Form object on success, false on failure * * @since 1.6 */ diff --git a/administrator/components/com_banners/src/Model/ClientsModel.php b/administrator/components/com_banners/src/Model/ClientsModel.php index 54216dd4f553e..229835c79873c 100644 --- a/administrator/components/com_banners/src/Model/ClientsModel.php +++ b/administrator/components/com_banners/src/Model/ClientsModel.php @@ -162,9 +162,11 @@ protected function getListQuery() $db->quoteName('uc.name'), ] ); + // Filter by search in title + $search = trim((string) $this->getState('filter.search', '')); // Filter by search in title - if ($search = trim($this->getState('filter.search', ''))) { + if ($search !== '' && $search !== '0') { if (stripos($search, 'id:') === 0) { $search = (int) substr($search, 3); $query->where($db->quoteName('a.id') . ' = :search') @@ -177,7 +179,7 @@ protected function getListQuery() } // Filter by purchase type - if ($purchaseType = (int) $this->getState('filter.purchase_type')) { + if ($purchaseType = (int) $this->getState('filter.purchase_type') !== 0) { if ($defaultPurchase === $purchaseType) { $query->where('(' . $db->quoteName('a.purchase_type') . ' = :type OR ' . $db->quoteName('a.purchase_type') . ' = -1)'); } else { @@ -246,8 +248,8 @@ public function getItems() try { $state = 1; $countPublished = $db->loadAssocList('cid', 'count_published'); - } catch (\RuntimeException $e) { - $this->setError($e->getMessage()); + } catch (\RuntimeException $runtimeException) { + $this->setError($runtimeException->getMessage()); return false; } @@ -256,8 +258,8 @@ public function getItems() try { $state = 0; $countUnpublished = $db->loadAssocList('cid', 'count_published'); - } catch (\RuntimeException $e) { - $this->setError($e->getMessage()); + } catch (\RuntimeException $runtimeException) { + $this->setError($runtimeException->getMessage()); return false; } @@ -266,8 +268,8 @@ public function getItems() try { $state = -2; $countTrashed = $db->loadAssocList('cid', 'count_published'); - } catch (\RuntimeException $e) { - $this->setError($e->getMessage()); + } catch (\RuntimeException $runtimeException) { + $this->setError($runtimeException->getMessage()); return false; } @@ -276,8 +278,8 @@ public function getItems() try { $state = 2; $countArchived = $db->loadAssocList('cid', 'count_published'); - } catch (\RuntimeException $e) { - $this->setError($e->getMessage()); + } catch (\RuntimeException $runtimeException) { + $this->setError($runtimeException->getMessage()); return false; } diff --git a/administrator/components/com_banners/src/Model/DownloadModel.php b/administrator/components/com_banners/src/Model/DownloadModel.php index 6dc2854c3b83a..adf5642bb922e 100644 --- a/administrator/components/com_banners/src/Model/DownloadModel.php +++ b/administrator/components/com_banners/src/Model/DownloadModel.php @@ -12,6 +12,7 @@ use Joomla\CMS\Application\ApplicationHelper; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\MVC\Model\FormModel; // phpcs:disable PSR1.Files.SideEffects @@ -55,7 +56,7 @@ protected function populateState() * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * - * @return \Joomla\CMS\Form\Form|boolean A Form object on success, false on failure + * @return Form|boolean A Form object on success, false on failure * * @since 1.6 */ diff --git a/administrator/components/com_banners/src/Model/TracksModel.php b/administrator/components/com_banners/src/Model/TracksModel.php index 3656463c93cf2..d0be7c3c19233 100644 --- a/administrator/components/com_banners/src/Model/TracksModel.php +++ b/administrator/components/com_banners/src/Model/TracksModel.php @@ -126,7 +126,7 @@ protected function getListQuery() // Filter by type. - if ($type = (int) $this->getState('filter.type')) { + if ($type = (int) $this->getState('filter.type') !== 0) { $query->where($db->quoteName('a.track_type') . ' = :type') ->bind(':type', $type, ParameterType::INTEGER); } @@ -162,7 +162,7 @@ protected function getListQuery() } // Filter on the level. - if ($level = (int) $this->getState('filter.level')) { + if ($level = (int) $this->getState('filter.level') !== 0) { $query->where($db->quoteName('c.level') . ' <= :level') ->bind(':level', $level, ParameterType::INTEGER); } @@ -193,7 +193,7 @@ public function delete() $categoryId = (int) $this->getState('category_id'); // Access checks. - if ($categoryId) { + if ($categoryId !== 0) { $allow = $user->authorise('core.delete', 'com_banners.category.' . $categoryId); } else { $allow = $user->authorise('core.delete', 'com_banners'); @@ -206,7 +206,7 @@ public function delete() ->delete($db->quoteName('#__banner_tracks')); // Filter by type - if ($type = (int) $this->getState('filter.type')) { + if ($type = (int) $this->getState('filter.type') !== 0) { $query->where($db->quoteName('track_type') . ' = :type') ->bind(':type', $type, ParameterType::INTEGER); } @@ -228,13 +228,13 @@ public function delete() ->from($db->quoteName('#__banners')); // Filter by client - if ($clientId = (int) $this->getState('filter.client_id')) { + if ($clientId = (int) $this->getState('filter.client_id') !== 0) { $subQuery->where($db->quoteName('cid') . ' = :clientId'); $query->bind(':clientId', $clientId, ParameterType::INTEGER); } // Filter by category - if ($categoryId) { + if ($categoryId !== 0) { $subQuery->where($db->quoteName('catid') . ' = :categoryId'); $query->bind(':categoryId', $categoryId, ParameterType::INTEGER); } @@ -267,17 +267,12 @@ public function delete() */ public function getBaseName() { - if (!isset($this->basename)) { + if ($this->basename === null) { $basename = str_replace('__SITE__', Factory::getApplication()->get('sitename'), $this->getState('basename')); $categoryId = $this->getState('filter.category_id'); if (is_numeric($categoryId)) { - if ($categoryId > 0) { - $basename = str_replace('__CATID__', $categoryId, $basename); - } else { - $basename = str_replace('__CATID__', '', $basename); - } - + $basename = $categoryId > 0 ? str_replace('__CATID__', $categoryId, $basename) : str_replace('__CATID__', '', $basename); $categoryName = $this->getCategoryName(); $basename = str_replace('__CATNAME__', $categoryName, $basename); } else { @@ -311,19 +306,11 @@ public function getBaseName() $begin = $this->getState('filter.begin'); - if (!empty($begin)) { - $basename = str_replace('__BEGIN__', $begin, $basename); - } else { - $basename = str_replace('__BEGIN__', '', $basename); - } + $basename = empty($begin) ? str_replace('__BEGIN__', '', $basename) : str_replace('__BEGIN__', $begin, $basename); $end = $this->getState('filter.end'); - if (!empty($end)) { - $basename = str_replace('__END__', $end, $basename); - } else { - $basename = str_replace('__END__', '', $basename); - } + $basename = empty($end) ? str_replace('__END__', '', $basename) : str_replace('__END__', $end, $basename); $this->basename = $basename; } @@ -342,7 +329,7 @@ protected function getCategoryName() { $categoryId = (int) $this->getState('filter.category_id'); - if ($categoryId) { + if ($categoryId !== 0) { $db = $this->getDatabase(); $query = $db->getQuery(true) ->select($db->quoteName('title')) @@ -376,7 +363,7 @@ protected function getClientName() { $clientId = (int) $this->getState('filter.client_id'); - if ($clientId) { + if ($clientId !== 0) { $db = $this->getDatabase(); $query = $db->getQuery(true) ->select($db->quoteName('name')) @@ -432,7 +419,7 @@ public function getMimeType() */ public function getContent() { - if (!isset($this->content)) { + if (!property_exists($this, 'content') || $this->content === null) { $this->content = '"' . str_replace('"', '""', Text::_('COM_BANNERS_HEADING_NAME')) . '","' . str_replace('"', '""', Text::_('COM_BANNERS_HEADING_CLIENT')) . '","' . str_replace('"', '""', Text::_('JCATEGORY')) . '","' @@ -464,13 +451,10 @@ public function getContent() // Run the packager $delete = Folder::files($app->get('tmp_path') . '/', uniqid('banners_tracks_'), false, true); - if (!empty($delete)) { - if (!File::delete($delete)) { - // File::delete throws an error - $this->setError(Text::_('COM_BANNERS_ERR_ZIP_DELETE_FAILURE')); - - return false; - } + if (!empty($delete) && !File::delete($delete)) { + // File::delete throws an error + $this->setError(Text::_('COM_BANNERS_ERR_ZIP_DELETE_FAILURE')); + return false; } $archive = new Archive(); diff --git a/administrator/components/com_banners/src/Service/Html/Banner.php b/administrator/components/com_banners/src/Service/Html/Banner.php index 77314f24fd6f3..7a17e2c4c4256 100644 --- a/administrator/components/com_banners/src/Service/Html/Banner.php +++ b/administrator/components/com_banners/src/Service/Html/Banner.php @@ -78,8 +78,8 @@ public function clientlist() try { $options = $db->loadObjectList(); - } catch (\RuntimeException $e) { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + } catch (\RuntimeException $runtimeException) { + Factory::getApplication()->enqueueMessage($runtimeException->getMessage(), 'error'); } return $options; diff --git a/administrator/components/com_banners/src/Table/BannerTable.php b/administrator/components/com_banners/src/Table/BannerTable.php index bd3968945314b..a572f61f4cfc1 100644 --- a/administrator/components/com_banners/src/Table/BannerTable.php +++ b/administrator/components/com_banners/src/Table/BannerTable.php @@ -89,8 +89,8 @@ public function check() { try { parent::check(); - } catch (\Exception $e) { - $this->setError($e->getMessage()); + } catch (\Exception $exception) { + $this->setError($exception->getMessage()); return false; } @@ -99,25 +99,25 @@ public function check() $this->name = htmlspecialchars_decode($this->name, ENT_QUOTES); // Set alias - if (trim($this->alias) == '') { + if (trim($this->alias) === '') { $this->alias = $this->name; } $this->alias = ApplicationHelper::stringURLSafe($this->alias, $this->language); - if (trim(str_replace('-', '', $this->alias)) == '') { + if (trim(str_replace('-', '', $this->alias)) === '') { $this->alias = Factory::getDate()->format('Y-m-d-H-i-s'); } // Check for a valid category. - if (!$this->catid = (int) $this->catid) { + if ($this->catid = (int) $this->catid === 0) { $this->setError(Text::_('JLIB_DATABASE_ERROR_CATEGORY_REQUIRED')); return false; } // Set created date if not set. - if (!(int) $this->created) { + if ((int) $this->created === 0) { $this->created = Factory::getDate()->toSql(); } diff --git a/administrator/components/com_banners/src/Table/ClientTable.php b/administrator/components/com_banners/src/Table/ClientTable.php index 5a08c82bb4c79..7a4f65cf858c1 100644 --- a/administrator/components/com_banners/src/Table/ClientTable.php +++ b/administrator/components/com_banners/src/Table/ClientTable.php @@ -76,8 +76,8 @@ public function check() { try { parent::check(); - } catch (\Exception $e) { - $this->setError($e->getMessage()); + } catch (\Exception $exception) { + $this->setError($exception->getMessage()); return false; } diff --git a/administrator/components/com_banners/src/View/Banner/HtmlView.php b/administrator/components/com_banners/src/View/Banner/HtmlView.php index 7e2785000a55c..ef8e1a8a364d0 100644 --- a/administrator/components/com_banners/src/View/Banner/HtmlView.php +++ b/administrator/components/com_banners/src/View/Banner/HtmlView.php @@ -76,7 +76,7 @@ public function display($tpl = null): void $this->state = $model->getState(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -100,7 +100,7 @@ protected function addToolbar(): void $user = $this->getCurrentUser(); $userId = $user->id; $isNew = ($this->item->id == 0); - $checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $userId); + $checkedOut = !\is_null($this->item->checked_out) && $this->item->checked_out != $userId; $toolbar = $this->getDocument()->getToolbar(); // Since we don't track these assets at the item level, use the category id. diff --git a/administrator/components/com_banners/src/View/Banners/HtmlView.php b/administrator/components/com_banners/src/View/Banners/HtmlView.php index dced0e0e68bcd..c346cb5214418 100644 --- a/administrator/components/com_banners/src/View/Banners/HtmlView.php +++ b/administrator/components/com_banners/src/View/Banners/HtmlView.php @@ -110,12 +110,12 @@ public function display($tpl = null): void $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + if (\count($this->items) === 0 && $this->isEmptyState = $model->getIsEmptyState()) { $this->setLayout('emptystate'); } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_banners/src/View/Client/HtmlView.php b/administrator/components/com_banners/src/View/Client/HtmlView.php index 0772f29620c42..292a94e732e3c 100644 --- a/administrator/components/com_banners/src/View/Client/HtmlView.php +++ b/administrator/components/com_banners/src/View/Client/HtmlView.php @@ -20,6 +20,7 @@ use Joomla\CMS\Toolbar\Toolbar; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Banners\Administrator\Model\ClientModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -51,7 +52,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry * @since 1.5 */ protected $state; @@ -59,7 +60,7 @@ class HtmlView extends BaseHtmlView /** * Object containing permissions for the item * - * @var \Joomla\Registry\Registry + * @var Registry * @since 1.5 */ protected $canDo; @@ -85,7 +86,7 @@ public function display($tpl = null): void $this->canDo = ContentHelper::getActions('com_banners'); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -109,7 +110,7 @@ protected function addToolbar(): void $user = $this->getCurrentUser(); $isNew = ($this->item->id == 0); - $checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $user->id); + $checkedOut = !\is_null($this->item->checked_out) && $this->item->checked_out != $user->id; $canDo = $this->canDo; $toolbar = $this->getDocument()->getToolbar(); diff --git a/administrator/components/com_banners/src/View/Clients/HtmlView.php b/administrator/components/com_banners/src/View/Clients/HtmlView.php index adc913a2edd5b..04b67be2d337a 100644 --- a/administrator/components/com_banners/src/View/Clients/HtmlView.php +++ b/administrator/components/com_banners/src/View/Clients/HtmlView.php @@ -18,6 +18,7 @@ use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Banners\Administrator\Model\ClientsModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -65,7 +66,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry * @since 1.6 */ protected $state; @@ -99,12 +100,12 @@ public function display($tpl = null): void $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + if (\count($this->items) === 0 && $this->isEmptyState = $model->getIsEmptyState()) { $this->setLayout('emptystate'); } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_banners/src/View/Download/HtmlView.php b/administrator/components/com_banners/src/View/Download/HtmlView.php index a9bf5b198bd2b..09427ea70cafe 100644 --- a/administrator/components/com_banners/src/View/Download/HtmlView.php +++ b/administrator/components/com_banners/src/View/Download/HtmlView.php @@ -52,7 +52,7 @@ public function display($tpl = null): void $this->form = $model->getForm(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_banners/src/View/Tracks/HtmlView.php b/administrator/components/com_banners/src/View/Tracks/HtmlView.php index 65044eed4151e..a8f8bb2c6c1b0 100644 --- a/administrator/components/com_banners/src/View/Tracks/HtmlView.php +++ b/administrator/components/com_banners/src/View/Tracks/HtmlView.php @@ -19,6 +19,7 @@ use Joomla\CMS\Router\Route; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Banners\Administrator\Model\TracksModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -66,7 +67,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry * @since 1.6 */ protected $state; @@ -99,12 +100,12 @@ public function display($tpl = null): void $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + if (\count($this->items) === 0 && $this->isEmptyState = $model->getIsEmptyState()) { $this->setLayout('emptystate'); } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_banners/src/View/Tracks/RawView.php b/administrator/components/com_banners/src/View/Tracks/RawView.php index ff7652ac2f78a..d5570d83ef48f 100644 --- a/administrator/components/com_banners/src/View/Tracks/RawView.php +++ b/administrator/components/com_banners/src/View/Tracks/RawView.php @@ -48,7 +48,7 @@ public function display($tpl = null): void $content = $model->getContent(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_banners/tmpl/banners/default.php b/administrator/components/com_banners/tmpl/banners/default.php index 7b24a58ff792c..82e7638d3cd89 100644 --- a/administrator/components/com_banners/tmpl/banners/default.php +++ b/administrator/components/com_banners/tmpl/banners/default.php @@ -92,7 +92,7 @@ class="js-draggable" data-url="" data-direction="" data-nested="true" class="js-draggable" data-url="" data-direction="" data-nested="true"> items as $i => $item) : $ordering = ($listOrder == 'ordering'); diff --git a/administrator/components/com_banners/tmpl/banners/emptystate.php b/administrator/components/com_banners/tmpl/banners/emptystate.php index 24425a9e9ce4a..0cee536213d3c 100644 --- a/administrator/components/com_banners/tmpl/banners/emptystate.php +++ b/administrator/components/com_banners/tmpl/banners/emptystate.php @@ -1,5 +1,7 @@ 'COM_BANNERS', 'formURL' => 'index.php?option=com_banners&view=banners', diff --git a/administrator/components/com_banners/tmpl/clients/emptystate.php b/administrator/components/com_banners/tmpl/clients/emptystate.php index d97f2d15ffd22..5d03645e76890 100644 --- a/administrator/components/com_banners/tmpl/clients/emptystate.php +++ b/administrator/components/com_banners/tmpl/clients/emptystate.php @@ -1,5 +1,7 @@ 'COM_BANNERS_CLIENT', 'formURL' => 'index.php?option=com_banners&view=clients', diff --git a/administrator/components/com_cache/src/Controller/DisplayController.php b/administrator/components/com_cache/src/Controller/DisplayController.php index 4fbb455f1c963..79f92f291af83 100644 --- a/administrator/components/com_cache/src/Controller/DisplayController.php +++ b/administrator/components/com_cache/src/Controller/DisplayController.php @@ -15,6 +15,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\BaseController; use Joomla\CMS\Response\JsonResponse; +use Joomla\Component\Cache\Administrator\Model\CacheModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -80,7 +81,7 @@ public function delete() $cid = (array) $this->input->post->get('cid', [], 'string'); - if (empty($cid)) { + if ($cid === []) { $this->app->enqueueMessage(Text::_('JERROR_NO_ITEMS_SELECTED'), 'warning'); } else { $result = $this->getModel('cache')->cleanlist($cid); @@ -107,7 +108,7 @@ public function deleteAll() // Check for request forgeries $this->checkToken(); - /** @var \Joomla\Component\Cache\Administrator\Model\CacheModel $model */ + /** @var CacheModel $model */ $model = $this->getModel('cache'); $allCleared = true; diff --git a/administrator/components/com_cache/src/Model/CacheModel.php b/administrator/components/com_cache/src/Model/CacheModel.php index cae0a8d60401c..11eeba09dfc35 100644 --- a/administrator/components/com_cache/src/Model/CacheModel.php +++ b/administrator/components/com_cache/src/Model/CacheModel.php @@ -45,14 +45,14 @@ class CacheModel extends ListModel * * @var integer */ - protected $_total = null; + protected $_total; /** * Pagination object * * @var object */ - protected $_pagination = null; + protected $_pagination; /** * Constructor. @@ -130,7 +130,7 @@ public function getData() // Process filter by search term. if ($search = $this->getState('filter.search')) { foreach ($data as $key => $cacheItem) { - if (stripos($cacheItem->group, $search) === false) { + if (stripos($cacheItem->group, (string) $search) === false) { unset($data[$key]); } } @@ -140,7 +140,7 @@ public function getData() $listOrder = $this->getState('list.ordering', 'group'); $listDirn = $this->getState('list.direction', 'ASC'); - $this->_data = ArrayHelper::sortObjects($data, $listOrder, strtolower($listDirn) === 'desc' ? -1 : 1, true, true); + $this->_data = ArrayHelper::sortObjects($data, $listOrder, strtolower((string) $listDirn) === 'desc' ? -1 : 1, true, true); // Process pagination. $limit = (int) $this->getState('list.limit', 25); @@ -153,10 +153,10 @@ public function getData() } else { $this->_data = []; } - } catch (CacheConnectingException $exception) { + } catch (CacheConnectingException) { $this->setError(Text::_('COM_CACHE_ERROR_CACHE_CONNECTION_FAILED')); $this->_data = []; - } catch (UnsupportedCacheException $exception) { + } catch (UnsupportedCacheException) { $this->setError(Text::_('COM_CACHE_ERROR_CACHE_DRIVER_UNSUPPORTED')); $this->_data = []; } @@ -224,9 +224,7 @@ public function clean($group = '') { try { $this->getCache()->clean($group); - } catch (CacheConnectingException $exception) { - return false; - } catch (UnsupportedCacheException $exception) { + } catch (CacheConnectingException | UnsupportedCacheException) { return false; } @@ -264,9 +262,7 @@ public function purge() { try { Factory::getCache('')->gc(); - } catch (CacheConnectingException $exception) { - return false; - } catch (UnsupportedCacheException $exception) { + } catch (CacheConnectingException | UnsupportedCacheException) { return false; } diff --git a/administrator/components/com_cache/src/View/Cache/HtmlView.php b/administrator/components/com_cache/src/View/Cache/HtmlView.php index 6d7a4b6a72fc9..ce288e490a5bd 100644 --- a/administrator/components/com_cache/src/View/Cache/HtmlView.php +++ b/administrator/components/com_cache/src/View/Cache/HtmlView.php @@ -17,6 +17,7 @@ use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Cache\Administrator\Model\CacheModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -72,7 +73,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry * @since 1.6 */ protected $state; @@ -100,11 +101,11 @@ public function display($tpl = null): void $this->activeFilters = $model->getActiveFilters(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } - if (!\count($this->data) && ($this->state->get('filter.search') === null || $this->state->get('filter.search') === '')) { + if (\count($this->data) === 0 && ($this->state->get('filter.search') === null || $this->state->get('filter.search') === '')) { $this->setLayout('emptystate'); } @@ -127,7 +128,7 @@ protected function addToolbar(): void // Get the toolbar object instance $toolbar = $this->getDocument()->getToolbar(); - if (\count($this->data)) { + if (\count($this->data) !== 0) { $toolbar->delete('delete') ->listCheck(true); diff --git a/administrator/components/com_cache/tmpl/cache/default.php b/administrator/components/com_cache/tmpl/cache/default.php index 77ae9c5836892..9db03cdc6923d 100644 --- a/administrator/components/com_cache/tmpl/cache/default.php +++ b/administrator/components/com_cache/tmpl/cache/default.php @@ -68,7 +68,7 @@ - data as $folder => $item) : ?> + data as $item) : ?> group, false, 'cid', 'cb', $item->group); ?> diff --git a/administrator/components/com_categories/layouts/joomla/form/field/categoryedit.php b/administrator/components/com_categories/layouts/joomla/form/field/categoryedit.php index 7e2fd4ea0fab5..f647dda54ac30 100644 --- a/administrator/components/com_categories/layouts/joomla/form/field/categoryedit.php +++ b/administrator/components/com_categories/layouts/joomla/form/field/categoryedit.php @@ -58,7 +58,7 @@ $attr2 = ''; // Initialize some field attributes. -$attr .= !empty($size) ? ' size="' . $size . '"' : ''; +$attr .= empty($size) ? '' : ' size="' . $size . '"'; $attr .= $multiple ? ' multiple' : ''; $attr .= $autofocus ? ' autofocus' : ''; $attr .= $onchange ? ' onchange="' . $onchange . '"' : ''; @@ -68,7 +68,7 @@ $attr .= ' disabled="disabled"'; } -$attr2 .= !empty($class) ? ' class="' . $class . '"' : ''; +$attr2 .= empty($class) ? '' : ' class="' . $class . '"'; $placeholder = $this->escape(Text::_('JGLOBAL_TYPE_OR_SELECT_CATEGORY')); @@ -94,7 +94,7 @@ // E.g. form field type tag sends $this->value as array if ($multiple && is_array($value)) { - if (!count($value)) { + if ($value === []) { $value[] = ''; } @@ -141,4 +141,4 @@ ->useScript('webcomponent.field-fancy-select'); ?> -> +> diff --git a/administrator/components/com_categories/src/Controller/CategoriesController.php b/administrator/components/com_categories/src/Controller/CategoriesController.php index 3039ecf0c4ec8..1b55803e79600 100644 --- a/administrator/components/com_categories/src/Controller/CategoriesController.php +++ b/administrator/components/com_categories/src/Controller/CategoriesController.php @@ -12,8 +12,10 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Response\JsonResponse; use Joomla\CMS\Router\Route; +use Joomla\Component\Categories\Administrator\Model\CategoryModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -33,7 +35,7 @@ class CategoriesController extends AdminController * @param string $prefix The class prefix. Optional. * @param array $config The array of possible config values. Optional. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model. + * @return BaseDatabaseModel The model. * * @since 1.6 */ @@ -80,7 +82,7 @@ public function rebuild() $extension = $this->input->get('extension'); $this->setRedirect(Route::_('index.php?option=com_categories&view=categories&extension=' . $extension, false)); - /** @var \Joomla\Component\Categories\Administrator\Model\CategoryModel $model */ + /** @var CategoryModel $model */ $model = $this->getModel(); if ($model->rebuild()) { diff --git a/administrator/components/com_categories/src/Controller/CategoryController.php b/administrator/components/com_categories/src/Controller/CategoryController.php index a3809aca8f77f..2dbbb55facd60 100644 --- a/administrator/components/com_categories/src/Controller/CategoryController.php +++ b/administrator/components/com_categories/src/Controller/CategoryController.php @@ -16,6 +16,7 @@ use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Router\Route; use Joomla\CMS\Versioning\VersionableControllerTrait; +use Joomla\Component\Categories\Administrator\Model\CategoryModel; use Joomla\Input\Input; use Joomla\Registry\Registry; @@ -75,8 +76,10 @@ public function __construct($config = [], ?MVCFactoryInterface $factory = null, protected function allowAdd($data = []) { $user = $this->app->getIdentity(); - - return ($user->authorise('core.create', $this->extension) || \count($user->getAuthorisedCategories($this->extension, 'core.create'))); + if ($user->authorise('core.create', $this->extension)) { + return true; + } + return (bool) \count($user->getAuthorisedCategories($this->extension, 'core.create')); } /** @@ -91,7 +94,7 @@ protected function allowAdd($data = []) */ protected function allowEdit($data = [], $key = 'parent_id') { - $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + $recordId = (int) isset($data[$key]) !== 0 ? $data[$key] : 0; $user = $this->app->getIdentity(); // Check "edit" permission on record asset (explicit or inherited) @@ -181,7 +184,7 @@ public function batch($model = null) { $this->checkToken(); - /** @var \Joomla\Component\Categories\Administrator\Model\CategoryModel $model */ + /** @var CategoryModel $model */ $model = $this->getModel('Category'); // Preset the redirect @@ -213,9 +216,7 @@ protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') } } - $append .= '&extension=' . $this->extension; - - return $append; + return $append . ('&extension=' . $this->extension); } /** @@ -228,15 +229,14 @@ protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') protected function getRedirectToListAppend() { $append = parent::getRedirectToListAppend(); - $append .= '&extension=' . $this->extension; - return $append; + return $append . ('&extension=' . $this->extension); } /** * Function that allows child controller access to model data after the data has been saved. * - * @param \Joomla\CMS\MVC\Model\BaseDatabaseModel $model The data model object. + * @param BaseDatabaseModel $model The data model object. * @param array $validData The validated data. * * @return void diff --git a/administrator/components/com_categories/src/Controller/DisplayController.php b/administrator/components/com_categories/src/Controller/DisplayController.php index 41e6790a2dfa6..27ff100823a96 100644 --- a/administrator/components/com_categories/src/Controller/DisplayController.php +++ b/administrator/components/com_categories/src/Controller/DisplayController.php @@ -89,7 +89,7 @@ public function display($cachable = false, $urlparams = []) // Check for edit form. if ($vName == 'category' && $lName == 'edit' && !$this->checkEditId('com_categories.edit.category', $id)) { // Somehow the person just went to the form - we don't allow that. - if (!\count($this->app->getMessageQueue())) { + if (\count($this->app->getMessageQueue()) === 0) { $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error'); } diff --git a/administrator/components/com_categories/src/Field/CategoryeditField.php b/administrator/components/com_categories/src/Field/CategoryeditField.php index c824639799c3b..b49e412b0b4f2 100644 --- a/administrator/components/com_categories/src/Field/CategoryeditField.php +++ b/administrator/components/com_categories/src/Field/CategoryeditField.php @@ -79,7 +79,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) $return = parent::setup($element, $value, $group); if ($return) { - $this->allowAdd = isset($this->element['allowAdd']) ? (bool) $this->element['allowAdd'] : false; + $this->allowAdd = isset($this->element['allowAdd']) && (bool) $this->element['allowAdd']; $this->customPrefix = (string) $this->element['customPrefix']; } @@ -97,14 +97,11 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) */ public function __get($name) { - switch ($name) { - case 'allowAdd': - return (bool) $this->$name; - case 'customPrefix': - return $this->$name; - } - - return parent::__get($name); + return match ($name) { + 'allowAdd' => (bool) $this->$name, + 'customPrefix' => $this->$name, + default => parent::__get($name), + }; } /** @@ -123,11 +120,10 @@ public function __set($name, $value) switch ($name) { case 'allowAdd': - $value = (string) $value; $this->$name = ($value === 'true' || $value === $name || $value === '1'); break; case 'customPrefix': - $this->$name = (string) $value; + $this->$name = $value; break; default: parent::__set($name, $value); @@ -196,7 +192,7 @@ protected function getOptions() // Filter language if (!empty($this->element['language'])) { - if (strpos($this->element['language'], ',') !== false) { + if (str_contains($this->element['language'], ',')) { $language = explode(',', $this->element['language']); } else { $language = $this->element['language']; @@ -237,23 +233,21 @@ protected function getOptions() try { $options = $db->loadObjectList(); - } catch (\RuntimeException $e) { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + } catch (\RuntimeException $runtimeException) { + Factory::getApplication()->enqueueMessage($runtimeException->getMessage(), 'error'); } // Pad the option text with spaces using depth level as a multiplier. foreach ($options as $option) { // Translate ROOT - if ($this->element['parent'] == true || $jinput->get('option') == 'com_categories') { - if ($option->level == 0) { - $option->text = Text::_('JGLOBAL_ROOT_PARENT'); - } + if (($this->element['parent'] == true || $jinput->get('option') == 'com_categories') && $option->level == 0) { + $option->text = Text::_('JGLOBAL_ROOT_PARENT'); } if ($option->published == 1) { - $option->text = str_repeat('- ', !$option->level ? 0 : $option->level - 1) . $option->text; + $option->text = str_repeat('- ', $option->level ? $option->level - 1 : 0) . $option->text; } else { - $option->text = str_repeat('- ', !$option->level ? 0 : $option->level - 1) . '[' . $option->text . ']'; + $option->text = str_repeat('- ', $option->level ? $option->level - 1 : 0) . '[' . $option->text . ']'; } // Displays language code if not set to All diff --git a/administrator/components/com_categories/src/Field/ComponentsCategoryField.php b/administrator/components/com_categories/src/Field/ComponentsCategoryField.php index c6599b83b6127..45c2889e383f3 100644 --- a/administrator/components/com_categories/src/Field/ComponentsCategoryField.php +++ b/administrator/components/com_categories/src/Field/ComponentsCategoryField.php @@ -60,17 +60,18 @@ protected function getOptions() $option->value = $categoryType; // Extract the component name and optional section name - $parts = explode('.', $categoryType); + $parts = explode('.', (string) $categoryType); $component = $parts[0]; $section = (\count($parts) > 1) ? $parts[1] : null; // Load component language files $lang = Factory::getLanguage(); - $lang->load($component, JPATH_BASE) - || $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component); + if (!$lang->load($component, JPATH_BASE)) { + $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component); + } // If the component section string exists, let's use it - if ($lang->hasKey($component_section_key = strtoupper($component . ($section ? "_$section" : '')))) { + if ($lang->hasKey($component_section_key = strtoupper($component . ($section !== null && $section !== '' && $section !== '0' ? '_' . $section : '')))) { $option->text = Text::_($component_section_key); } else { // Else use the component title $option->text = Text::_(strtoupper($component)); diff --git a/administrator/components/com_categories/src/Field/Modal/CategoryField.php b/administrator/components/com_categories/src/Field/Modal/CategoryField.php index ba48fdcc64355..a96d381500859 100644 --- a/administrator/components/com_categories/src/Field/Modal/CategoryField.php +++ b/administrator/components/com_categories/src/Field/Modal/CategoryField.php @@ -53,8 +53,8 @@ class CategoryField extends ModalSelectField public function setup(\SimpleXMLElement $element, $value, $group = null) { // Check if the value consist with id:alias, extract the id only - if ($value && str_contains($value, ':')) { - [$id] = explode(':', $value, 2); + if ($value && str_contains((string) $value, ':')) { + [$id] = explode(':', (string) $value, 2); $value = (int) $id; } @@ -76,7 +76,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) $language = (string) $this->element['language']; // Prepare enabled actions - $this->canDo['propagate'] = ((string) $this->element['propagate'] == 'true') && \count($languages) > 2; + $this->canDo['propagate'] = ((string) $this->element['propagate'] === 'true') && \count($languages) > 2; // Prepare Urls $linkItems = (new Uri())->setPath(Uri::base(true) . '/index.php'); @@ -90,6 +90,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) ]); $linkItem = clone $linkItems; $linkItem->setVar('view', 'category'); + $linkCheckin = (new Uri())->setPath(Uri::base(true) . '/index.php'); $linkCheckin->setQuery([ 'option' => 'com_categories', @@ -98,7 +99,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) Session::getFormToken() => 1, ]); - if ($language) { + if ($language !== '' && $language !== '0') { $linkItems->setVar('forcedLanguage', $language); $linkItem->setVar('forcedLanguage', $language); @@ -112,6 +113,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) $urlSelect = $linkItems; $urlEdit = clone $linkItem; $urlEdit->setVar('task', 'category.edit'); + $urlNew = clone $linkItem; $urlNew->setVar('task', 'category.add'); @@ -139,23 +141,21 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) */ protected function getValueTitle() { - $value = (int) $this->value ?: ''; + $value = (int) $this->value !== 0 ? (int) $this->value : ''; $title = ''; - if ($value) { - try { - $db = $this->getDatabase(); - $query = $db->getQuery(true) - ->select($db->quoteName('title')) - ->from($db->quoteName('#__categories')) - ->where($db->quoteName('id') . ' = :value') - ->bind(':value', $value, ParameterType::INTEGER); - $db->setQuery($query); - - $title = $db->loadResult(); - } catch (\Throwable $e) { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); - } + try { + $db = $this->getDatabase(); + $query = $db->getQuery(true) + ->select($db->quoteName('title')) + ->from($db->quoteName('#__categories')) + ->where($db->quoteName('id') . ' = :value') + ->bind(':value', $value, ParameterType::INTEGER); + $db->setQuery($query); + + $title = $db->loadResult(); + } catch (\Throwable $throwable) { + Factory::getApplication()->enqueueMessage($throwable->getMessage(), 'error'); } return $title ?: $value; diff --git a/administrator/components/com_categories/src/Helper/CategoriesHelper.php b/administrator/components/com_categories/src/Helper/CategoriesHelper.php index 36d247022ff4a..9565d28e97aa2 100644 --- a/administrator/components/com_categories/src/Helper/CategoriesHelper.php +++ b/administrator/components/com_categories/src/Helper/CategoriesHelper.php @@ -100,8 +100,6 @@ public static function createCategory($data) ->getMVCFactory()->createModel('Category', 'Administrator', ['ignore_request' => true]); $categoryModel->save($data); - $catid = $categoryModel->getState('category.id'); - - return $catid; + return $categoryModel->getState('category.id'); } } diff --git a/administrator/components/com_categories/src/Model/CategoriesModel.php b/administrator/components/com_categories/src/Model/CategoriesModel.php index defbc31c0aa84..f08d51e1a2246 100644 --- a/administrator/components/com_categories/src/Model/CategoriesModel.php +++ b/administrator/components/com_categories/src/Model/CategoriesModel.php @@ -109,7 +109,7 @@ protected function populateState($ordering = 'a.lft', $direction = 'asc') $extension = $app->getUserStateFromRequest($this->context . '.filter.extension', 'extension', 'com_content', 'cmd'); $this->setState('filter.extension', $extension); - $parts = explode('.', $extension); + $parts = explode('.', (string) $extension); // Extract the component name $this->setState('filter.component', $parts[0]); @@ -249,7 +249,7 @@ protected function getListQuery() $categoryId = $categoryId ? [$categoryId] : []; } - if (\count($categoryId)) { + if ($categoryId !== []) { // Case: Using both categories filter and by level filter $categoryTable = Table::getInstance('Category', 'JTable'); $subCatItemsWhere = []; @@ -270,7 +270,7 @@ protected function getListQuery() } // Filter by access level. - if ($access = (int) $this->getState('filter.access')) { + if ($access = (int) $this->getState('filter.access') !== 0) { $query->where($db->quoteName('a.access') . ' = :access') ->bind(':access', $access, ParameterType::INTEGER); } @@ -296,12 +296,12 @@ protected function getListQuery() $search = $this->getState('filter.search'); if (!empty($search)) { - if (stripos($search, 'id:') === 0) { - $search = (int) substr($search, 3); + if (stripos((string) $search, 'id:') === 0) { + $search = (int) substr((string) $search, 3); $query->where($db->quoteName('a.id') . ' = :search') ->bind(':search', $search, ParameterType::INTEGER); } else { - $search = '%' . str_replace(' ', '%', trim($search)) . '%'; + $search = '%' . str_replace(' ', '%', trim((string) $search)) . '%'; $query->extendWhere( 'AND', [ @@ -351,7 +351,7 @@ protected function getListQuery() $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id') ) ->bind(':typeAlias', $typeAlias); - } elseif ($tag = (int) $tag) { + } elseif ($tag = (int) $tag !== 0) { $query->join( 'INNER', $db->quoteName('#__contentitem_tag_map', 'tagmap'), @@ -418,11 +418,11 @@ public function getAssoc() $extension = $this->getState('filter.extension'); $this->hasAssociation = Associations::isEnabled(); - $extension = explode('.', $extension); + $extension = explode('.', (string) $extension); $component = array_shift($extension); $cname = str_replace('com_', '', $component); - if (!$this->hasAssociation || !$component || !$cname) { + if (!$this->hasAssociation || !$component || ($cname === '' || $cname === '0' || $cname === [])) { $this->hasAssociation = false; return $this->hasAssociation; diff --git a/administrator/components/com_categories/src/Model/CategoryModel.php b/administrator/components/com_categories/src/Model/CategoryModel.php index f9e516ee0bddb..89f38b38c10f6 100644 --- a/administrator/components/com_categories/src/Model/CategoryModel.php +++ b/administrator/components/com_categories/src/Model/CategoryModel.php @@ -25,6 +25,7 @@ use Joomla\CMS\MVC\Model\AdminModel; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Table\Category; +use Joomla\CMS\Table\Table; use Joomla\CMS\UCM\UCMType; use Joomla\CMS\Versioning\VersionableModelTrait; use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper; @@ -61,7 +62,7 @@ class CategoryModel extends AdminModel * @var string * @since 3.2 */ - public $typeAlias = null; + public $typeAlias; /** * The context used for the associations table @@ -151,7 +152,7 @@ protected function canEditState($record) * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * - * @return \Joomla\CMS\Table\Table A Table object + * @return Table A Table object * * @since 1.6 */ @@ -182,7 +183,7 @@ protected function populateState() $extension = $app->getInput()->get('extension', 'com_content'); $this->setState('category.extension', $extension); - $parts = explode('.', $extension); + $parts = explode('.', (string) $extension); // Extract the component name $this->setState('category.component', $parts[0]); @@ -254,7 +255,7 @@ public function getForm($data = [], $loadData = true) // A workaround to get the extension into the model for save requests. if (empty($extension) && isset($data['extension'])) { $extension = $data['extension']; - $parts = explode('.', $extension); + $parts = explode('.', (string) $extension); $this->setState('category.extension', $extension); $this->setState('category.component', $parts[0]); @@ -274,7 +275,7 @@ public function getForm($data = [], $loadData = true) } $categoryId = $jinput->get('id'); - $parts = explode('.', $extension); + $parts = explode('.', (string) $extension); $assetKey = $categoryId ? $extension . '.category.' . $categoryId : $parts[0]; if (!$this->getCurrentUser()->authorise('core.edit.state', $assetKey)) { @@ -334,7 +335,7 @@ protected function loadFormData() // Pre-select some filters (Status, Language, Access) in edit form if those have been selected in Category Manager if (!$data->id) { // Check for which extension the Category Manager is used and get selected fields - $extension = substr($app->getUserState('com_categories.categories.filter.extension', ''), 4); + $extension = substr((string) $app->getUserState('com_categories.categories.filter.extension', ''), 4); $filters = (array) $app->getUserState('com_categories.categories.' . $extension . '.filter'); $data->set( @@ -344,10 +345,10 @@ protected function loadFormData() ((isset($filters['published']) && $filters['published'] !== '') ? $filters['published'] : null) ) ); - $data->set('language', $app->getInput()->getString('language', (!empty($filters['language']) ? $filters['language'] : null))); + $data->set('language', $app->getInput()->getString('language', (empty($filters['language']) ? null : $filters['language']))); $data->set( 'access', - $app->getInput()->getInt('access', (!empty($filters['access']) ? $filters['access'] : $app->get('access'))) + $app->getInput()->getInt('access', (empty($filters['access']) ? $app->get('access') : $filters['access'])) ); } } @@ -372,10 +373,8 @@ protected function loadFormData() */ public function validate($form, $data, $group = null) { - if (!$this->getCurrentUser()->authorise('core.admin', $data['extension'])) { - if (isset($data['rules'])) { - unset($data['rules']); - } + if (!$this->getCurrentUser()->authorise('core.admin', $data['extension']) && isset($data['rules'])) { + unset($data['rules']); } return parent::validate($form, $data, $group); @@ -407,16 +406,16 @@ protected function preprocessForm(Form $form, $data, $group = 'content') $name = 'category' . ($section ? ('.' . $section) : ''); // Looking first in the component forms folder - $path = Path::clean(JPATH_ADMINISTRATOR . "/components/$component/forms/$name.xml"); + $path = Path::clean(JPATH_ADMINISTRATOR . \sprintf('/components/%s/forms/%s.xml', $component, $name)); // Looking in the component models/forms folder (J! 3) if (!file_exists($path)) { - $path = Path::clean(JPATH_ADMINISTRATOR . "/components/$component/models/forms/$name.xml"); + $path = Path::clean(JPATH_ADMINISTRATOR . \sprintf('/components/%s/models/forms/%s.xml', $component, $name)); } // Old way: looking in the component folder if (!file_exists($path)) { - $path = Path::clean(JPATH_ADMINISTRATOR . "/components/$component/$name.xml"); + $path = Path::clean(JPATH_ADMINISTRATOR . \sprintf('/components/%s/%s.xml', $component, $name)); } if (file_exists($path)) { @@ -435,20 +434,22 @@ protected function preprocessForm(Form $form, $data, $group = 'content') } else { // Try to find the component helper. $eName = str_replace('com_', '', $component); - $path = Path::clean(JPATH_ADMINISTRATOR . "/components/$component/helpers/category.php"); + $path = Path::clean(JPATH_ADMINISTRATOR . \sprintf('/components/%s/helpers/category.php', $component)); if (file_exists($path)) { - $cName = ucfirst($eName) . ucfirst($section) . 'HelperCategory'; + $cName = ucfirst($eName) . ucfirst((string) $section) . 'HelperCategory'; \JLoader::register($cName, $path); if (class_exists($cName) && \is_callable([$cName, 'onPrepareForm'])) { - $lang->load($component, JPATH_BASE, null, false, false) + if ( + !($lang->load($component, JPATH_BASE, null, false, false) || $lang->load($component, JPATH_BASE . '/components/' . $component, null, false, false) - || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false) - || $lang->load($component, JPATH_BASE . '/components/' . $component, $lang->getDefault(), false, false); + || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false)) + ) { + $lang->load($component, JPATH_BASE . '/components/' . $component, $lang->getDefault(), false, false); + } \call_user_func_array([$cName, 'onPrepareForm'], [&$form]); - // Check for an error. if ($form instanceof \Exception) { $this->setError($form->getMessage()); @@ -495,6 +496,7 @@ protected function preprocessForm(Form $form, $data, $group = 'content') // Trigger the default form events. parent::preprocessForm($form, $data, $group); + return null; } /** @@ -510,7 +512,7 @@ public function save($data) { $table = $this->getTable(); $input = Factory::getApplication()->getInput(); - $pk = (!empty($data['id'])) ? $data['id'] : (int) $this->getState($this->getName() . '.id'); + $pk = (empty($data['id'])) ? (int) $this->getState($this->getName() . '.id') : $data['id']; $isNew = true; $context = $this->option . '.' . $this->name; @@ -541,10 +543,8 @@ public function save($data) [$title, $alias] = $this->generateNewTitle($data['parent_id'], $data['alias'], $data['title']); $data['title'] = $title; $data['alias'] = $alias; - } else { - if ($data['alias'] == $origTable->alias) { - $data['alias'] = ''; - } + } elseif ($data['alias'] == $origTable->alias) { + $data['alias'] = ''; } $data['published'] = 0; @@ -857,7 +857,7 @@ protected function batchFlipordering($value, $pks, $contexts) } } - return empty($successful) ? false : $successful; + return $successful === [] ? false : $successful; } /** @@ -885,7 +885,7 @@ protected function batchCopy($value, $pks, $contexts) $newIds = []; // Check that the parent exists - if ($parentId) { + if ($parentId !== 0) { if (!$this->table->load($parentId)) { if ($error = $this->table->getError()) { // Fatal error @@ -915,7 +915,7 @@ protected function batchCopy($value, $pks, $contexts) } // If the parent is 0, set it to the ID of the root item in the tree - if (empty($parentId)) { + if ($parentId === 0) { if (!$parentId = $this->table->getRootId()) { $this->setError($this->table->getError()); @@ -941,8 +941,8 @@ protected function batchCopy($value, $pks, $contexts) try { $count = $db->loadResult(); - } catch (\RuntimeException $e) { - $this->setError($e->getMessage()); + } catch (\RuntimeException $runtimeException) { + $this->setError($runtimeException->getMessage()); return false; } @@ -1089,7 +1089,7 @@ protected function batchMove($value, $pks, $contexts) $extension = Factory::getApplication()->getInput()->get('extension', '', 'word'); // Check that the parent exists. - if ($parentId) { + if ($parentId !== 0) { if (!$this->table->load($parentId)) { if ($error = $this->table->getError()) { // Fatal error. @@ -1205,7 +1205,7 @@ protected function batchMove($value, $pks, $contexts) } // Process the child rows - if (!empty($children)) { + if ($children !== []) { // Remove any duplicates and sanitize ids. $children = array_unique($children); $children = ArrayHelper::toInteger($children); @@ -1283,11 +1283,11 @@ public function getAssoc() $extension = $this->getState('category.extension', ''); $this->hasAssociation = Associations::isEnabled(); - $extension = explode('.', $extension); + $extension = explode('.', (string) $extension); $component = array_shift($extension); $cname = str_replace('com_', '', $component); - if (!$this->hasAssociation || !$component || !$cname) { + if (!$this->hasAssociation || !$component || ($cname === '' || $cname === '0' || $cname === [])) { $this->hasAssociation = false; return $this->hasAssociation; diff --git a/administrator/components/com_categories/src/Table/CategoryTable.php b/administrator/components/com_categories/src/Table/CategoryTable.php index 3342fc111dcdb..517c86ba02452 100644 --- a/administrator/components/com_categories/src/Table/CategoryTable.php +++ b/administrator/components/com_categories/src/Table/CategoryTable.php @@ -10,6 +10,8 @@ namespace Joomla\Component\Categories\Administrator\Table; +use Joomla\CMS\Table\Category; + // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects @@ -19,7 +21,7 @@ * * @since 1.6 */ -class CategoryTable extends \Joomla\CMS\Table\Category +class CategoryTable extends Category { /** * Method to delete a node and, optionally, its child nodes from the table. diff --git a/administrator/components/com_categories/src/View/Categories/HtmlView.php b/administrator/components/com_categories/src/View/Categories/HtmlView.php index aa012b5052633..27245f2ee1607 100644 --- a/administrator/components/com_categories/src/View/Categories/HtmlView.php +++ b/administrator/components/com_categories/src/View/Categories/HtmlView.php @@ -12,6 +12,7 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Text; @@ -20,6 +21,7 @@ use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Toolbar\Button\DropdownButton; use Joomla\CMS\Toolbar\ToolbarHelper; +use Joomla\CMS\WebAsset\WebAssetManager; use Joomla\Component\Categories\Administrator\Model\CategoriesModel; use Joomla\Filesystem\Path; @@ -65,7 +67,7 @@ class HtmlView extends BaseHtmlView /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form */ public $filterForm; @@ -114,12 +116,12 @@ public function display($tpl = null) $this->activeFilters = $model->getActiveFilters(); // Written this way because we only want to call IsEmptyState if no items, to prevent always calling it when not needed. - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + if (\count($this->items) === 0 && $this->isEmptyState = $model->getIsEmptyState()) { $this->setLayout('emptystate'); } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -190,13 +192,14 @@ protected function addToolbar() // Need to load the menu language file as mod_menu hasn't been loaded yet. $lang = $this->getLanguage(); - $lang->load($component, JPATH_BASE) - || $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component); + if (!$lang->load($component, JPATH_BASE)) { + $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component); + } // If a component categories title string is present, let's use it. - if ($lang->hasKey($component_title_key = strtoupper($component . ($section ? "_$section" : '')) . '_CATEGORIES_TITLE')) { + if ($lang->hasKey($component_title_key = strtoupper($component . ($section ? '_' . $section : '')) . '_CATEGORIES_TITLE')) { $title = Text::_($component_title_key); - } elseif ($lang->hasKey($component_section_key = strtoupper($component . ($section ? "_$section" : '')))) { + } elseif ($lang->hasKey($component_section_key = strtoupper($component . ($section ? '_' . $section : '')))) { // Else if the component section string exists, let's use it. $title = Text::sprintf('COM_CATEGORIES_CATEGORIES_TITLE', $this->escape(Text::_($component_section_key))); } else { // Else use the base title @@ -204,7 +207,7 @@ protected function addToolbar() } // Load specific css component - /** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */ + /** @var WebAssetManager $wa */ $wa = $this->getDocument()->getWebAssetManager(); $wa->getRegistry()->addExtensionRegistryFile($component); @@ -215,7 +218,7 @@ protected function addToolbar() } // Prepare the toolbar. - ToolbarHelper::title($title, 'folder categories ' . substr($component, 4) . ($section ? "-$section" : '') . '-categories'); + ToolbarHelper::title($title, 'folder categories ' . substr((string) $component, 4) . ($section ? '-' . $section : '') . '-categories'); if ($canDo->get('core.create') || \count($user->getAuthorisedCategories($component, 'core.create')) > 0) { $toolbar->addNew('category.add'); @@ -282,11 +285,11 @@ protected function addToolbar() $name = 'category' . ($section ? ('.' . $section) : ''); // Looking first in the component forms folder - $path = Path::clean(JPATH_ADMINISTRATOR . "/components/$component/forms/$name.xml"); + $path = Path::clean(JPATH_ADMINISTRATOR . \sprintf('/components/%s/forms/%s.xml', $component, $name)); // Looking in the component models/forms folder (J! 3) if (!file_exists($path)) { - $path = Path::clean(JPATH_ADMINISTRATOR . "/components/$component/models/forms/$name.xml"); + $path = Path::clean(JPATH_ADMINISTRATOR . \sprintf('/components/%s/models/forms/%s.xml', $component, $name)); } $ref_key = ''; @@ -302,14 +305,14 @@ protected function addToolbar() $url = (string) $xml->listhelp['url']; } - if (!$ref_key) { + if ($ref_key === '' || $ref_key === '0') { // Compute the ref_key if it does exist in the component - $languageKey = strtoupper($component . ($section ? "_$section" : '')) . '_CATEGORIES_HELP_KEY'; + $languageKey = strtoupper($component . ($section ? '_' . $section : '')) . '_CATEGORIES_HELP_KEY'; if ($lang->hasKey($languageKey)) { $ref_key = $languageKey; } else { - $languageKey = 'JHELP_COMPONENTS_' . strtoupper(substr($component, 4) . ($section ? "_$section" : '')) . '_CATEGORIES'; + $languageKey = 'JHELP_COMPONENTS_' . strtoupper(substr((string) $component, 4) . ($section ? '_' . $section : '')) . '_CATEGORIES'; if ($lang->hasKey($languageKey)) { $ref_key = $languageKey; @@ -324,12 +327,10 @@ protected function addToolbar() * -locally searching in a component help file if helpURL param exists in the component and is set to '' * -remotely searching in a component URL if helpURL param exists in the component and is NOT set to '' */ - if (!$url) { - if ($lang->hasKey($lang_help_url = strtoupper($component) . '_HELP_URL')) { - $debug = $lang->setDebug(false); - $url = Text::_($lang_help_url); - $lang->setDebug($debug); - } + if (($url === '' || $url === '0') && $lang->hasKey($lang_help_url = strtoupper((string) $component) . '_HELP_URL')) { + $debug = $lang->setDebug(false); + $url = Text::_($lang_help_url); + $lang->setDebug($debug); } $toolbar->help($ref_key, ComponentHelper::getParams($component)->exists('helpURL'), $url); diff --git a/administrator/components/com_categories/src/View/Category/HtmlView.php b/administrator/components/com_categories/src/View/Category/HtmlView.php index 7e54e36d6af94..fa8d654a89d06 100644 --- a/administrator/components/com_categories/src/View/Category/HtmlView.php +++ b/administrator/components/com_categories/src/View/Category/HtmlView.php @@ -12,6 +12,7 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Helper\TagsHelper; use Joomla\CMS\Language\Associations; @@ -20,8 +21,10 @@ use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\CMS\Toolbar\Toolbar; use Joomla\CMS\Toolbar\ToolbarHelper; +use Joomla\CMS\WebAsset\WebAssetManager; use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper; use Joomla\Component\Categories\Administrator\Model\CategoryModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -37,7 +40,7 @@ class HtmlView extends BaseHtmlView /** * The Form object * - * @var \Joomla\CMS\Form\Form + * @var Form */ protected $form; @@ -51,7 +54,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $state; @@ -65,7 +68,7 @@ class HtmlView extends BaseHtmlView /** * The actions the user is authorised to perform * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $canDo; @@ -112,7 +115,7 @@ public function display($tpl = null) } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -170,7 +173,7 @@ protected function addToolbar() $toolbar = $this->getDocument()->getToolbar(); $isNew = ($this->item->id == 0); - $checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $userId); + $checkedOut = !\is_null($this->item->checked_out) && $this->item->checked_out != $userId; // Avoid nonsense situation. if ($extension == 'com_categories') { @@ -178,23 +181,24 @@ protected function addToolbar() } // The extension can be in the form com_foo.section - $parts = explode('.', $extension); + $parts = explode('.', (string) $extension); $component = $parts[0]; $section = (\count($parts) > 1) ? $parts[1] : null; $componentParams = ComponentHelper::getParams($component); // Need to load the menu language file as mod_menu hasn't been loaded yet. $lang = $this->getLanguage(); - $lang->load($component, JPATH_BASE) - || $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component); + if (!$lang->load($component, JPATH_BASE)) { + $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component); + } // Get the results for each action. $canDo = $this->canDo; // If a component categories title string is present, let's use it. - if ($lang->hasKey($component_title_key = $component . ($section ? "_$section" : '') . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE')) { + if ($lang->hasKey($component_title_key = $component . ($section !== null && $section !== '' && $section !== '0' ? '_' . $section : '') . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE')) { $title = Text::_($component_title_key); - } elseif ($lang->hasKey($component_section_key = $component . ($section ? "_$section" : ''))) { + } elseif ($lang->hasKey($component_section_key = $component . ($section !== null && $section !== '' && $section !== '0' ? '_' . $section : ''))) { // Else if the component section string exists, let's use it. $title = Text::sprintf('COM_CATEGORIES_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', $this->escape(Text::_($component_section_key))); @@ -204,7 +208,7 @@ protected function addToolbar() } // Load specific css component - /** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */ + /** @var WebAssetManager $wa */ $wa = $this->getDocument()->getWebAssetManager(); $wa->getRegistry()->addExtensionRegistryFile($component); @@ -218,7 +222,7 @@ protected function addToolbar() ToolbarHelper::title( $title, 'folder category-' . ($isNew ? 'add' : 'edit') - . ' ' . substr($component, 4) . ($section ? "-$section" : '') . '-category-' . ($isNew ? 'add' : 'edit') + . ' ' . substr($component, 4) . ($section !== null && $section !== '' && $section !== '0' ? '-' . $section : '') . '-category-' . ($isNew ? 'add' : 'edit') ); if ($isNew) { @@ -297,15 +301,15 @@ function (Toolbar $childBar) use ($checkedOut, $canDo, $itemEditable, $component $ref_key = (string) $this->form->getXml()->help['key']; // Try with a language string - if (!$ref_key) { + if ($ref_key === '' || $ref_key === '0') { // Compute the ref_key if it does exist in the component - $languageKey = strtoupper($component . ($section ? "_$section" : '')) . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_HELP_KEY'; + $languageKey = strtoupper($component . ($section !== null && $section !== '' && $section !== '0' ? '_' . $section : '')) . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_HELP_KEY'; if ($lang->hasKey($languageKey)) { $ref_key = $languageKey; } else { $languageKey = 'JHELP_COMPONENTS_' - . strtoupper(substr($component, 4) . ($section ? "_$section" : '')) + . strtoupper(substr($component, 4) . ($section !== null && $section !== '' && $section !== '0' ? '_' . $section : '')) . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT'); if ($lang->hasKey($languageKey)) { @@ -323,12 +327,10 @@ function (Toolbar $childBar) use ($checkedOut, $canDo, $itemEditable, $component */ $url = (string) $this->form->getXml()->help['url']; - if (!$url) { - if ($lang->hasKey($lang_help_url = strtoupper($component) . '_HELP_URL')) { - $debug = $lang->setDebug(false); - $url = Text::_($lang_help_url); - $lang->setDebug($debug); - } + if (($url === '' || $url === '0') && $lang->hasKey($lang_help_url = strtoupper($component) . '_HELP_URL')) { + $debug = $lang->setDebug(false); + $url = Text::_($lang_help_url); + $lang->setDebug($debug); } $toolbar->help($ref_key, $componentParams->exists('helpURL'), $url, $component); @@ -357,19 +359,20 @@ protected function addModalToolbar() } // The extension can be in the form com_foo.section - $parts = explode('.', $extension); + $parts = explode('.', (string) $extension); $component = $parts[0]; // Need to load the menu language file as mod_menu hasn't been loaded yet. $lang = $this->getLanguage(); - $lang->load($component, JPATH_BASE) - || $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component); + if (!$lang->load($component, JPATH_BASE)) { + $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component); + } // Build the actions for new and existing records. $canDo = $this->canDo; // Load specific css component - /** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */ + /** @var WebAssetManager $wa */ $wa = $this->getDocument()->getWebAssetManager(); $wa->getRegistry()->addExtensionRegistryFile($component); diff --git a/administrator/components/com_categories/tmpl/categories/default.php b/administrator/components/com_categories/tmpl/categories/default.php index 1535e9eeeb213..0f29837bd48f2 100644 --- a/administrator/components/com_categories/tmpl/categories/default.php +++ b/administrator/components/com_categories/tmpl/categories/default.php @@ -30,8 +30,8 @@ $extension = $this->escape($this->state->get('filter.extension')); $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); -$saveOrder = ($listOrder == 'a.lft' && strtolower($listDirn) == 'asc'); -$parts = explode('.', $extension, 2); +$saveOrder = ($listOrder == 'a.lft' && strtolower((string) $listDirn) === 'asc'); +$parts = explode('.', (string) $extension, 2); $component = $parts[0]; $section = null; @@ -127,7 +127,7 @@ class="js-draggable" data-url="" data-direction="" data-nested="false" class="js-draggable" data-url="" data-direction="" data-nested="false" > items as $i => $item) : ?> ordering as $k => $v) { $v = implode('-', $v); $v = '-' . $v . '-'; - if (strpos($v, '-' . $_currentParentId . '-') !== false) { + if (str_contains($v, '-' . $_currentParentId . '-')) { $parentsStr .= ' ' . $k; $_currentParentId = $k; break; diff --git a/administrator/components/com_categories/tmpl/categories/emptystate.php b/administrator/components/com_categories/tmpl/categories/emptystate.php index 96049dd3532aa..7989f996461c2 100644 --- a/administrator/components/com_categories/tmpl/categories/emptystate.php +++ b/administrator/components/com_categories/tmpl/categories/emptystate.php @@ -1,5 +1,7 @@ state->get('filter.extension'); $component = $this->state->get('filter.component'); $section = $this->state->get('filter.section'); // Special handling for the title as com_categories is a service component for many other components. Copied from the categories view. $lang = Factory::getApplication()->getLanguage(); -$lang->load($component, JPATH_BASE) -|| $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component); +if (!$lang->load($component, JPATH_BASE)) { + $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component); +} // If a component categories title string is present, let's use it. -if ($lang->hasKey($component_title_key = strtoupper($component . ($section ? "_$section" : '')) . '_CATEGORIES_TITLE')) { +if ($lang->hasKey($component_title_key = strtoupper($component . ($section ? '_' . $section : '')) . '_CATEGORIES_TITLE')) { $title = Text::_($component_title_key); -} elseif ($lang->hasKey($component_section_key = strtoupper($component . ($section ? "_$section" : '')))) { +} elseif ($lang->hasKey($component_section_key = strtoupper($component . ($section ? '_' . $section : '')))) { // Else if the component section string exists, let's use it $title = Text::sprintf('COM_CATEGORIES_CATEGORIES_TITLE', $this->escape(Text::_($component_section_key))); } else // Else use the base title diff --git a/administrator/components/com_categories/tmpl/categories/modal.php b/administrator/components/com_categories/tmpl/categories/modal.php index e16028f85ccd6..506824c263565 100644 --- a/administrator/components/com_categories/tmpl/categories/modal.php +++ b/administrator/components/com_categories/tmpl/categories/modal.php @@ -97,7 +97,7 @@ } $link = RouteHelper::getCategoryRoute($item->id, $item->language); - $itemHtml = '' . $item->title . ''; + $itemHtml = '' . $item->title . ''; ?> diff --git a/administrator/components/com_checkin/src/Controller/DisplayController.php b/administrator/components/com_checkin/src/Controller/DisplayController.php index e267dc566e68c..3f7573cc318a6 100644 --- a/administrator/components/com_checkin/src/Controller/DisplayController.php +++ b/administrator/components/com_checkin/src/Controller/DisplayController.php @@ -13,6 +13,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\BaseController; use Joomla\CMS\Response\JsonResponse; +use Joomla\Component\Checkin\Administrator\Model\CheckinModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -59,11 +60,11 @@ public function checkin() $ids = (array) $this->input->get('cid', [], 'string'); - if (empty($ids)) { + if ($ids === []) { $this->app->enqueueMessage(Text::_('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST'), 'warning'); } else { // Get the model. - /** @var \Joomla\Component\Checkin\Administrator\Model\CheckinModel $model */ + /** @var CheckinModel $model */ $model = $this->getModel('Checkin'); // Checked in the items. @@ -89,7 +90,7 @@ public function getMenuBadgeData() $model = $this->getModel('Checkin'); - $amount = (int) \count($model->getItems()); + $amount = \count($model->getItems()); echo new JsonResponse($amount); } @@ -110,7 +111,7 @@ public function getQuickiconContent() $model = $this->getModel('Checkin'); - $amount = (int) \count($model->getItems()); + $amount = \count($model->getItems()); $result = []; diff --git a/administrator/components/com_checkin/src/Model/CheckinModel.php b/administrator/components/com_checkin/src/Model/CheckinModel.php index 50e663de3accb..46482c20f46ec 100644 --- a/administrator/components/com_checkin/src/Model/CheckinModel.php +++ b/administrator/components/com_checkin/src/Model/CheckinModel.php @@ -96,7 +96,7 @@ public function checkin($ids = []) foreach ($ids as $tn) { // Make sure we get the right tables based on prefix. - if (stripos($tn, $app->get('dbprefix')) !== 0) { + if (stripos((string) $tn, (string) $app->get('dbprefix')) !== 0) { continue; } @@ -147,7 +147,7 @@ public function checkin($ids = []) */ public function getTotal() { - if (!isset($this->total)) { + if ($this->total === null) { $this->getItems(); } @@ -163,7 +163,7 @@ public function getTotal() */ public function getItems() { - if (!isset($this->items)) { + if (!property_exists($this, 'items') || $this->items === null) { $db = $this->getDatabase(); $tables = $db->getTableList(); $prefix = Factory::getApplication()->get('dbprefix'); @@ -173,11 +173,11 @@ public function getItems() foreach ($tables as $tn) { // Make sure we get the right tables based on prefix. - if (stripos($tn, $prefix) !== 0) { + if (stripos((string) $tn, (string) $prefix) !== 0) { continue; } - if ($this->getState('filter.search') && stripos($tn, $this->getState('filter.search')) === false) { + if ($this->getState('filter.search') && stripos((string) $tn, (string) $this->getState('filter.search')) === false) { continue; } @@ -209,28 +209,22 @@ public function getItems() // Order items by table if ($this->getState('list.ordering') == 'table') { - if (strtolower($this->getState('list.direction')) == 'asc') { + if (strtolower((string) $this->getState('list.direction')) === 'asc') { ksort($results); } else { krsort($results); } - } else { + } elseif (strtolower((string) $this->getState('list.direction')) === 'asc') { // Order items by number of items - if (strtolower($this->getState('list.direction')) == 'asc') { - asort($results); - } else { - arsort($results); - } + asort($results); + } else { + arsort($results); } // Pagination $limit = (int) $this->getState('list.limit'); - if ($limit !== 0) { - $this->items = \array_slice($results, $this->getState('list.start'), $limit); - } else { - $this->items = $results; - } + $this->items = $limit !== 0 ? \array_slice($results, $this->getState('list.start'), $limit) : $results; } return $this->items; diff --git a/administrator/components/com_checkin/src/View/Checkin/HtmlView.php b/administrator/components/com_checkin/src/View/Checkin/HtmlView.php index 28fd48ea1db0a..33a259a85fb19 100644 --- a/administrator/components/com_checkin/src/View/Checkin/HtmlView.php +++ b/administrator/components/com_checkin/src/View/Checkin/HtmlView.php @@ -10,11 +10,14 @@ namespace Joomla\Component\Checkin\Administrator\View\Checkin; +use Joomla\CMS\Form\Form; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Checkin\Administrator\Model\CheckinModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -44,21 +47,21 @@ class HtmlView extends BaseHtmlView /** * The pagination object * - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination */ protected $pagination; /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $state; /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form * * @since 4.0.0 */ @@ -101,13 +104,13 @@ public function display($tpl = null) $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); - if (!\count($this->items)) { + if (\count($this->items) === 0) { $this->isEmptyState = true; $this->setLayout('emptystate'); } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_config/src/Controller/ApplicationController.php b/administrator/components/com_config/src/Controller/ApplicationController.php index eb33421783efb..d90a6b3471a48 100644 --- a/administrator/components/com_config/src/Controller/ApplicationController.php +++ b/administrator/components/com_config/src/Controller/ApplicationController.php @@ -18,6 +18,7 @@ use Joomla\CMS\Response\JsonResponse; use Joomla\CMS\Router\Route; use Joomla\CMS\Session\Session; +use Joomla\Component\Config\Administrator\Model\ApplicationModel; use Joomla\Input\Input; // phpcs:disable PSR1.Files.SideEffects @@ -66,7 +67,7 @@ public function cancel() /** * Saves the form * - * @return void|boolean Void on success. Boolean false on fail. + * @return bool|null Void on success. Boolean false on fail. * * @since 4.0.0 */ @@ -84,7 +85,7 @@ public function save() $this->app->setUserState('com_config.config.global.data', null); - /** @var \Joomla\Component\Config\Administrator\Model\ApplicationModel $model */ + /** @var ApplicationModel $model */ $model = $this->getModel('Application', 'Administrator'); $data = $this->input->post->get('jform', [], 'array'); @@ -181,16 +182,11 @@ public function save() $this->app->enqueueMessage(Text::_('COM_CONFIG_SAVE_SUCCESS'), 'message'); // Set the redirect based on the task. - switch ($this->input->getCmd('task')) { - case 'apply': - $this->setRedirect(Route::_('index.php?option=com_config', false)); - break; - - case 'save': - default: - $this->setRedirect(Route::_('index.php', false)); - break; - } + match ($this->input->getCmd('task')) { + 'apply' => $this->setRedirect(Route::_('index.php?option=com_config', false)), + default => $this->setRedirect(Route::_('index.php', false)), + }; + return null; } /** @@ -217,16 +213,15 @@ public function removeroot() } // Initialise model. - - /** @var \Joomla\Component\Config\Administrator\Model\ApplicationModel $model */ + /** @var ApplicationModel $model */ $model = $this->getModel('Application', 'Administrator'); // Attempt to save the configuration and remove root. try { $model->removeroot(); - } catch (\RuntimeException $e) { + } catch (\RuntimeException $runtimeException) { // Save failed, go back to the screen and display a notice. - $this->setRedirect('index.php', Text::_('JERROR_SAVE_FAILED', $e->getMessage()), 'error'); + $this->setRedirect('index.php', Text::_('JERROR_SAVE_FAILED', $runtimeException->getMessage()), 'error'); return false; } @@ -265,7 +260,7 @@ public function sendtestmail() $this->app->close(); } - /** @var \Joomla\Component\Config\Administrator\Model\ApplicationModel $model */ + /** @var ApplicationModel $model */ $model = $this->getModel('Application', 'Administrator'); echo new JsonResponse($model->sendTestMail()); @@ -294,7 +289,7 @@ public function store() $this->app->close(); } - /** @var \Joomla\Component\Config\Administrator\Model\ApplicationModel $model */ + /** @var ApplicationModel $model */ $model = $this->getModel('Application', 'Administrator'); echo new JsonResponse($model->storePermissions()); $this->app->close(); diff --git a/administrator/components/com_config/src/Controller/ComponentController.php b/administrator/components/com_config/src/Controller/ComponentController.php index f7abd791c87c2..085425af60389 100644 --- a/administrator/components/com_config/src/Controller/ComponentController.php +++ b/administrator/components/com_config/src/Controller/ComponentController.php @@ -16,6 +16,7 @@ use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\CMS\Router\Route; use Joomla\CMS\Uri\Uri; +use Joomla\Component\Config\Administrator\Model\ComponentModel; use Joomla\Input\Input; // phpcs:disable PSR1.Files.SideEffects @@ -68,15 +69,16 @@ public function save($key = null, $urlVar = null) $id = $this->input->get('id', null, 'INT'); $option = $this->input->get('component'); $user = $this->app->getIdentity(); - $context = "$this->option.edit.$this->context.$option"; + $context = \sprintf('%s.edit.%s.%s', $this->option, $this->context, $option); - /** @var \Joomla\Component\Config\Administrator\Model\ComponentModel $model */ + /** @var ComponentModel $model */ $model = $this->getModel('Component', 'Administrator'); $model->setState('component.option', $option); + $form = $model->getForm(); // Make sure com_joomlaupdate and com_privacy can only be accessed by SuperUser - if (\in_array(strtolower($option), ['com_joomlaupdate', 'com_privacy'], true) && !$user->authorise('core.admin')) { + if (\in_array(strtolower((string) $option), ['com_joomlaupdate', 'com_privacy'], true) && !$user->authorise('core.admin')) { $this->setRedirect(Route::_('index.php', false), Text::_('JERROR_ALERTNOAUTHOR'), 'error'); } @@ -95,7 +97,7 @@ public function save($key = null, $urlVar = null) $redirect = ''; if (!empty($returnUri)) { - $redirect = '&return=' . urlencode($returnUri); + $redirect = '&return=' . urlencode((string) $returnUri); } // Validate the posted data. @@ -125,14 +127,14 @@ public function save($key = null, $urlVar = null) try { $model->save($data); - } catch (\RuntimeException $e) { + } catch (\RuntimeException $runtimeException) { // Save the data in the session. $this->app->setUserState($context . '.data', $data); // Save failed, go back to the screen and display a notice. $this->setRedirect( Route::_('index.php?option=com_config&view=component&component=' . $option . $redirect, false), - Text::_('JERROR_SAVE_FAILED', $e->getMessage()), + Text::_('JERROR_SAVE_FAILED', $runtimeException->getMessage()), 'error' ); @@ -162,7 +164,7 @@ public function save($key = null, $urlVar = null) $redirect = 'index.php?option=' . $option; if (!empty($returnUri)) { - $redirect = base64_decode($returnUri); + $redirect = base64_decode((string) $returnUri); } // Don't redirect to an external URL. @@ -190,7 +192,7 @@ public function cancel($key = null) $component = $this->input->get('component'); // Clear session data. - $this->app->setUserState("$this->option.edit.$this->context.$component.data", null); + $this->app->setUserState(\sprintf('%s.edit.%s.%s.data', $this->option, $this->context, $component), null); // Calculate redirect URL $returnUri = $this->input->post->get('return', null, 'base64'); @@ -198,7 +200,7 @@ public function cancel($key = null) $redirect = 'index.php?option=' . $component; if (!empty($returnUri)) { - $redirect = base64_decode($returnUri); + $redirect = base64_decode((string) $returnUri); } // Don't redirect to an external URL. diff --git a/administrator/components/com_config/src/Controller/DisplayController.php b/administrator/components/com_config/src/Controller/DisplayController.php index 008a20deff0f5..894f6fddb31ed 100644 --- a/administrator/components/com_config/src/Controller/DisplayController.php +++ b/administrator/components/com_config/src/Controller/DisplayController.php @@ -55,7 +55,7 @@ public function display($cachable = false, $urlparams = []) // Make sure com_joomlaupdate and com_privacy can only be accessed by SuperUser if ( - \in_array(strtolower($component), ['com_joomlaupdate', 'com_privacy']) + \in_array(strtolower((string) $component), ['com_joomlaupdate', 'com_privacy']) && !$this->app->getIdentity()->authorise('core.admin') ) { $this->setRedirect(Route::_('index.php'), Text::_('JERROR_ALERTNOAUTHOR'), 'error'); diff --git a/administrator/components/com_config/src/Controller/RequestController.php b/administrator/components/com_config/src/Controller/RequestController.php index 889f3282f1b59..cc905d9a4148b 100644 --- a/administrator/components/com_config/src/Controller/RequestController.php +++ b/administrator/components/com_config/src/Controller/RequestController.php @@ -12,6 +12,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\Component\Config\Administrator\Model\ApplicationModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -50,7 +51,7 @@ public function getJson() $paths->insert(JPATH_BASE . '/components/' . $componentFolder . '/view/' . $viewName . '/tmpl', 1); } - $model = new \Joomla\Component\Config\Administrator\Model\ApplicationModel(); + $model = new ApplicationModel(); $component = $model->getState()->get('component.option'); // Access check. @@ -65,8 +66,8 @@ public function getJson() try { $data = $model->getData(); - } catch (\Exception $e) { - $this->app->enqueueMessage($e->getMessage(), 'error'); + } catch (\Exception $exception) { + $this->app->enqueueMessage($exception->getMessage(), 'error'); return false; } diff --git a/administrator/components/com_config/src/Dispatcher/Dispatcher.php b/administrator/components/com_config/src/Dispatcher/Dispatcher.php index 18c901eb88288..936d080467705 100644 --- a/administrator/components/com_config/src/Dispatcher/Dispatcher.php +++ b/administrator/components/com_config/src/Dispatcher/Dispatcher.php @@ -45,7 +45,7 @@ protected function checkAccess(): void $view = $this->input->getCmd('view'); $component = $this->input->getCmd('component'); - if ($component && (substr($task, 0, 10) === 'component.' || $view === 'component')) { + if ($component && (str_starts_with($task, 'component.') || $view === 'component')) { // User is changing component settings, check if he has permission to do that $canAccess = ConfigHelper::canChangeComponentConfig($component); } else { diff --git a/administrator/components/com_config/src/Field/ConfigComponentsField.php b/administrator/components/com_config/src/Field/ConfigComponentsField.php index 7ec5fb115417f..3d850f9da1e0f 100644 --- a/administrator/components/com_config/src/Field/ConfigComponentsField.php +++ b/administrator/components/com_config/src/Field/ConfigComponentsField.php @@ -61,8 +61,9 @@ protected function getOptions() 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); + if (!$lang->load($extension . '.sys', JPATH_ADMINISTRATOR)) { + $lang->load($extension . '.sys', $source); + } // Translate component name $item->text = Text::_($item->text); diff --git a/administrator/components/com_config/src/Field/FiltersField.php b/administrator/components/com_config/src/Field/FiltersField.php index d2b5a6a9cc2e5..3744c8425efe8 100644 --- a/administrator/components/com_config/src/Field/FiltersField.php +++ b/administrator/components/com_config/src/Field/FiltersField.php @@ -89,8 +89,8 @@ protected function getInput() $group_filter = $this->value[$group->value]; - $group_filter['filter_tags'] = !empty($group_filter['filter_tags']) ? $group_filter['filter_tags'] : ''; - $group_filter['filter_attributes'] = !empty($group_filter['filter_attributes']) ? $group_filter['filter_attributes'] : ''; + $group_filter['filter_tags'] = empty($group_filter['filter_tags']) ? '' : $group_filter['filter_tags']; + $group_filter['filter_attributes'] = empty($group_filter['filter_attributes']) ? '' : $group_filter['filter_attributes']; $html[] = ' '; $html[] = ' '; @@ -125,7 +125,7 @@ protected function getInput() . ' name="' . $this->name . '[' . $group->value . '][filter_tags]"' . ' type="text"' . ' id="' . $this->id . $group->value . '_filter_tags" class="novalidate form-control"' - . ' value="' . htmlspecialchars($group_filter['filter_tags'], ENT_QUOTES) . '"' + . ' value="' . htmlspecialchars((string) $group_filter['filter_tags'], ENT_QUOTES) . '"' . '>'; $html[] = ' '; $html[] = ' '; @@ -135,7 +135,7 @@ protected function getInput() . ' name="' . $this->name . '[' . $group->value . '][filter_attributes]"' . ' type="text"' . ' id="' . $this->id . $group->value . '_filter_attributes" class="novalidate form-control"' - . ' value="' . htmlspecialchars($group_filter['filter_attributes'], ENT_QUOTES) . '"' + . ' value="' . htmlspecialchars((string) $group_filter['filter_attributes'], ENT_QUOTES) . '"' . '>'; $html[] = ' '; $html[] = ' '; @@ -168,9 +168,9 @@ protected function getUserGroups() $query->join('LEFT', '#__usergroups AS b on a.lft > b.lft AND a.rgt < b.rgt'); $query->group('a.id, a.title, a.lft'); $query->order('a.lft ASC'); + $db->setQuery($query); - $options = $db->loadObjectList(); - return $options; + return $db->loadObjectList(); } } diff --git a/administrator/components/com_config/src/Helper/ConfigHelper.php b/administrator/components/com_config/src/Helper/ConfigHelper.php index 115d384402162..8456489d44b4f 100644 --- a/administrator/components/com_config/src/Helper/ConfigHelper.php +++ b/administrator/components/com_config/src/Helper/ConfigHelper.php @@ -42,9 +42,8 @@ public static function getAllComponents() ->where('type = ' . $db->quote('component')) ->where('enabled = 1'); $db->setQuery($query); - $result = $db->loadColumn(); - return $result; + return $db->loadColumn(); } /** @@ -75,7 +74,10 @@ public static function canChangeComponentConfig(string $component) $user = Factory::getApplication()->getIdentity(); if (!\in_array(strtolower($component), ['com_joomlaupdate', 'com_privacy'], true)) { - return $user->authorise('core.admin', $component) || $user->authorise('core.options', $component); + if ($user->authorise('core.admin', $component)) { + return true; + } + return $user->authorise('core.options', $component); } return $user->authorise('core.admin'); @@ -146,7 +148,8 @@ public static function loadLanguageForComponent($component) // Load the core file then // Load extension-local file. - $lang->load($component . '.sys', JPATH_BASE) - || $lang->load($component . '.sys', JPATH_ADMINISTRATOR . '/components/' . $component); + if (!$lang->load($component . '.sys', JPATH_BASE)) { + $lang->load($component . '.sys', JPATH_ADMINISTRATOR . '/components/' . $component); + } } } diff --git a/administrator/components/com_config/src/Model/ApplicationModel.php b/administrator/components/com_config/src/Model/ApplicationModel.php index a362c9523c808..c88a90eb8baca 100644 --- a/administrator/components/com_config/src/Model/ApplicationModel.php +++ b/administrator/components/com_config/src/Model/ApplicationModel.php @@ -154,7 +154,7 @@ public function validateDbConnection($data) $data['dbsslcert'] = ''; } - if ((bool) $data['dbsslverifyservercert'] === true) { + if ((bool) $data['dbsslverifyservercert']) { $data['dbsslverifyservercert'] = false; } @@ -167,14 +167,14 @@ public function validateDbConnection($data) } } else { // Check localhost - if (strtolower($data['host']) === 'localhost') { + if (strtolower((string) $data['host']) === 'localhost') { Factory::getApplication()->enqueueMessage(Text::_('COM_CONFIG_ERROR_DATABASE_ENCRYPTION_LOCALHOST'), 'error'); return false; } // Check CA file and folder depending on database type if server certificate verification - if ((bool) $data['dbsslverifyservercert'] === true) { + if ((bool) $data['dbsslverifyservercert']) { if (empty($data['dbsslca'])) { Factory::getApplication()->enqueueMessage( Text::sprintf( @@ -186,7 +186,6 @@ public function validateDbConnection($data) return false; } - if (!is_file(Path::clean($data['dbsslca']))) { Factory::getApplication()->enqueueMessage( Text::sprintf( @@ -198,11 +197,9 @@ public function validateDbConnection($data) return false; } - } else { + } elseif (!empty($data['dbsslca'])) { // Reset unused option - if (!empty($data['dbsslca'])) { - $data['dbsslca'] = ''; - } + $data['dbsslca'] = ''; } // Check key and certificate if two-way encryption @@ -306,7 +303,7 @@ public function save($data) ]; foreach (['cipher', 'ca', 'key', 'cert'] as $value) { - $confVal = trim($data['dbssl' . $value]); + $confVal = trim((string) $data['dbssl' . $value]); if ($confVal !== '') { $options['ssl'][$value] = $confVal; @@ -317,8 +314,8 @@ public function save($data) try { $revisedDbo = DatabaseDriver::getInstance($options); $revisedDbo->getVersion(); - } catch (\Exception $e) { - $app->enqueueMessage(Text::sprintf('COM_CONFIG_ERROR_DATABASE_NOT_AVAILABLE', $e->getCode(), $e->getMessage()), 'error'); + } catch (\Exception $exception) { + $app->enqueueMessage(Text::sprintf('COM_CONFIG_ERROR_DATABASE_NOT_AVAILABLE', $exception->getCode(), $exception->getMessage()), 'error'); return false; } @@ -475,7 +472,7 @@ public function save($data) } else { $revisedDbo->truncateTable('#__session'); } - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { /* * The database API logs errors on failures so we don't need to add any error handling mechanisms here. * Also, this data won't be added or checked anymore once the configuration is saved, so it'll purge itself @@ -495,29 +492,26 @@ public function save($data) $data['session_filesystem_path'] = Path::clean($data['session_filesystem_path']); - if ($currentPath !== $data['session_filesystem_path']) { - if (!is_dir(Path::clean($data['session_filesystem_path'])) && !Folder::create($data['session_filesystem_path'])) { - try { - Log::add( - Text::sprintf( - 'COM_CONFIG_ERROR_CUSTOM_SESSION_FILESYSTEM_PATH_NOTWRITABLE_USING_DEFAULT', - $data['session_filesystem_path'] - ), - Log::WARNING, - 'jerror' - ); - } catch (\RuntimeException $logException) { - $app->enqueueMessage( - Text::sprintf( - 'COM_CONFIG_ERROR_CUSTOM_SESSION_FILESYSTEM_PATH_NOTWRITABLE_USING_DEFAULT', - $data['session_filesystem_path'] - ), - 'warning' - ); - } - - $data['session_filesystem_path'] = $currentPath; + if ($currentPath !== $data['session_filesystem_path'] && (!is_dir(Path::clean($data['session_filesystem_path'])) && !Folder::create($data['session_filesystem_path']))) { + try { + Log::add( + Text::sprintf( + 'COM_CONFIG_ERROR_CUSTOM_SESSION_FILESYSTEM_PATH_NOTWRITABLE_USING_DEFAULT', + $data['session_filesystem_path'] + ), + Log::WARNING, + 'jerror' + ); + } catch (\RuntimeException) { + $app->enqueueMessage( + Text::sprintf( + 'COM_CONFIG_ERROR_CUSTOM_SESSION_FILESYSTEM_PATH_NOTWRITABLE_USING_DEFAULT', + $data['session_filesystem_path'] + ), + 'warning' + ); } + $data['session_filesystem_path'] = $currentPath; } } @@ -583,7 +577,7 @@ public function save($data) Log::WARNING, 'jerror' ); - } catch (\RuntimeException $logException) { + } catch (\RuntimeException) { $app->enqueueMessage( Text::sprintf('COM_CONFIG_ERROR_CUSTOM_CACHE_PATH_NOTWRITABLE_USING_DEFAULT', $path, JPATH_CACHE), 'warning' @@ -599,7 +593,7 @@ public function save($data) if ($error) { try { Log::add(Text::sprintf('COM_CONFIG_ERROR_CACHE_PATH_NOTWRITABLE', $path), Log::WARNING, 'jerror'); - } catch (\RuntimeException $exception) { + } catch (\RuntimeException) { $app->enqueueMessage(Text::sprintf('COM_CONFIG_ERROR_CACHE_PATH_NOTWRITABLE', $path), 'warning'); } @@ -616,16 +610,16 @@ public function save($data) if ((!$data['caching'] && $prev['caching']) || $data['cache_handler'] !== $prev['cache_handler']) { try { Factory::getCache()->clean(); - } catch (CacheConnectingException $exception) { + } catch (CacheConnectingException) { try { Log::add(Text::_('COM_CONFIG_ERROR_CACHE_CONNECTION_FAILED'), Log::WARNING, 'jerror'); - } catch (\RuntimeException $logException) { + } catch (\RuntimeException) { $app->enqueueMessage(Text::_('COM_CONFIG_ERROR_CACHE_CONNECTION_FAILED'), 'warning'); } - } catch (UnsupportedCacheException $exception) { + } catch (UnsupportedCacheException) { try { Log::add(Text::_('COM_CONFIG_ERROR_CACHE_DRIVER_UNSUPPORTED'), Log::WARNING, 'jerror'); - } catch (\RuntimeException $logException) { + } catch (\RuntimeException) { $app->enqueueMessage(Text::_('COM_CONFIG_ERROR_CACHE_DRIVER_UNSUPPORTED'), 'warning'); } } @@ -659,7 +653,7 @@ public function save($data) Log::WARNING, 'jerror' ); - } catch (\RuntimeException $logException) { + } catch (\RuntimeException) { $app->enqueueMessage( Text::sprintf('COM_CONFIG_ERROR_CUSTOM_TEMP_PATH_NOTWRITABLE_USING_DEFAULT', $path, $defaultTmpPath), 'warning' @@ -674,7 +668,7 @@ public function save($data) if ($error) { try { Log::add(Text::sprintf('COM_CONFIG_ERROR_TMP_PATH_NOTWRITABLE', $path), Log::WARNING, 'jerror'); - } catch (\RuntimeException $exception) { + } catch (\RuntimeException) { $app->enqueueMessage(Text::sprintf('COM_CONFIG_ERROR_TMP_PATH_NOTWRITABLE', $path), 'warning'); } } @@ -708,7 +702,7 @@ public function save($data) Log::WARNING, 'jerror' ); - } catch (\RuntimeException $logException) { + } catch (\RuntimeException) { $app->enqueueMessage( Text::sprintf('COM_CONFIG_ERROR_CUSTOM_LOG_PATH_NOTWRITABLE_USING_DEFAULT', $path, $defaultLogPath), 'warning' @@ -722,7 +716,7 @@ public function save($data) if ($error) { try { Log::add(Text::sprintf('COM_CONFIG_ERROR_LOG_PATH_NOTWRITABLE', $path), Log::WARNING, 'jerror'); - } catch (\RuntimeException $exception) { + } catch (\RuntimeException) { $app->enqueueMessage(Text::sprintf('COM_CONFIG_ERROR_LOG_PATH_NOTWRITABLE', $path), 'warning'); } } @@ -773,7 +767,7 @@ public function save($data) */ public function removeroot() { - $app = Factory::getApplication(); + Factory::getApplication(); // Get the previous configuration. $prev = new \JConfig(); @@ -871,7 +865,7 @@ public function storePermissions($permission = null) } // We are creating a new item so we don't have an item id so don't allow. - if (substr($permission['component'], -6) === '.false') { + if (str_ends_with((string) $permission['component'], '.false')) { $app->enqueueMessage(Text::_('JLIB_RULES_SAVE_BEFORE_CHANGE_PERMISSIONS'), 'error'); return false; @@ -946,7 +940,7 @@ public function storePermissions($permission = null) /** @var Asset $parentAsset */ $parentAsset = Table::getInstance('Asset'); - if (strpos($asset->name, '.') !== false) { + if (str_contains($asset->name, '.')) { $assetParts = explode('.', $asset->name); $parentAsset->loadByName($assetParts[0]); $parentAssetId = $parentAsset->id; @@ -1005,8 +999,8 @@ public function storePermissions($permission = null) return false; } - } catch (\Exception $e) { - $app->enqueueMessage($e->getMessage(), 'error'); + } catch (\Exception $exception) { + $app->enqueueMessage($exception->getMessage(), 'error'); return false; } @@ -1081,8 +1075,8 @@ public function storePermissions($permission = null) $db->setQuery($query); $totalChildGroups = (int) $db->loadResult(); - } catch (\Exception $e) { - $app->enqueueMessage($e->getMessage(), 'error'); + } catch (\Exception $exception) { + $app->enqueueMessage($exception->getMessage(), 'error'); return false; } @@ -1099,13 +1093,13 @@ public function storePermissions($permission = null) // Get the group, group parent id, and group global config recursive calculated permission for the chosen action. $inheritedGroupRule = Access::checkGroup($permission['rule'], $permission['action'], $assetId); - if (!empty($parentAssetId)) { + if ($parentAssetId !== null && $parentAssetId !== 0) { $inheritedGroupParentAssetRule = Access::checkGroup($permission['rule'], $permission['action'], $parentAssetId); } else { $inheritedGroupParentAssetRule = null; } - $inheritedParentGroupRule = !empty($parentGroupId) ? Access::checkGroup($parentGroupId, $permission['action'], $assetId) : null; + $inheritedParentGroupRule = $parentGroupId === 0 ? null : Access::checkGroup($parentGroupId, $permission['action'], $assetId); // Current group is a Super User group, so calculated setting is "Allowed (Super User)". if ($isSuperUserGroupAfter) { @@ -1146,7 +1140,7 @@ public function storePermissions($permission = null) // Third part: Overwrite the calculated permissions labels for special cases. // Global configuration with "Not Set" permission. Calculated permission is "Not Allowed (Default)". - if (empty($parentGroupId) && $isGlobalConfig === true && $assetRule === null) { + if ($parentGroupId === 0 && $isGlobalConfig && $assetRule === null) { $result['class'] = 'badge bg-danger'; $result['text'] = Text::_('JLIB_RULES_NOT_ALLOWED_DEFAULT'); } elseif ($inheritedGroupParentAssetRule === false || $inheritedParentGroupRule === false) { diff --git a/administrator/components/com_config/src/Model/ComponentModel.php b/administrator/components/com_config/src/Model/ComponentModel.php index 17554c5791631..d8f7c2dbe558e 100644 --- a/administrator/components/com_config/src/Model/ComponentModel.php +++ b/administrator/components/com_config/src/Model/ComponentModel.php @@ -95,8 +95,9 @@ public function getForm($data = [], $loadData = true) } $lang = Factory::getLanguage(); - $lang->load($option, JPATH_BASE) - || $lang->load($option, JPATH_BASE . "/components/$option"); + if (!$lang->load($option, JPATH_BASE)) { + $lang->load($option, JPATH_BASE . ('/components/' . $option)); + } return $form; } @@ -136,12 +137,11 @@ public function getComponent() // Load common and local language files. $lang = Factory::getLanguage(); - $lang->load($option, JPATH_BASE) - || $lang->load($option, JPATH_BASE . "/components/$option"); - - $result = ComponentHelper::getComponent($option); + if (!$lang->load($option, JPATH_BASE)) { + $lang->load($option, JPATH_BASE . ('/components/' . $option)); + } - return $result; + return ComponentHelper::getComponent($option); } /** diff --git a/administrator/components/com_config/src/View/Application/HtmlView.php b/administrator/components/com_config/src/View/Application/HtmlView.php index 6ec11ecb289a1..d89d35b219ed8 100644 --- a/administrator/components/com_config/src/View/Application/HtmlView.php +++ b/administrator/components/com_config/src/View/Application/HtmlView.php @@ -12,11 +12,14 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\CMS\Toolbar\ToolbarHelper; +use Joomla\CMS\User\User; use Joomla\Component\Config\Administrator\Helper\ConfigHelper; use Joomla\Component\Config\Administrator\Model\ApplicationModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -29,10 +32,27 @@ */ class HtmlView extends BaseHtmlView { + /** + * @var User + */ + public $user; + /** + * @var Registry + */ + public $usersParams; + /** + * @var Registry + */ + public $mediaParams; + public $components; + /** + * @var bool + */ + public $userIsSuperAdmin; /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry * @since 3.2 */ public $state; @@ -40,7 +60,7 @@ class HtmlView extends BaseHtmlView /** * The form object * - * @var \Joomla\CMS\Form\Form + * @var Form * @since 3.2 */ public $form; @@ -101,8 +121,8 @@ public function display($tpl = null) $this->form = $model->getForm(); $this->data = $model->getData(); $this->user = $this->getCurrentUser(); - } catch (\Exception $e) { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + } catch (\Exception $exception) { + Factory::getApplication()->enqueueMessage($exception->getMessage(), 'error'); return; } diff --git a/administrator/components/com_config/src/View/Component/HtmlView.php b/administrator/components/com_config/src/View/Component/HtmlView.php index 486824d9f564d..2f2e8b4a1ad77 100644 --- a/administrator/components/com_config/src/View/Component/HtmlView.php +++ b/administrator/components/com_config/src/View/Component/HtmlView.php @@ -10,12 +10,15 @@ namespace Joomla\Component\Config\Administrator\View\Component; +use Joomla\CMS\Component\ComponentRecord; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Config\Administrator\Helper\ConfigHelper; use Joomla\Component\Config\Administrator\Model\ComponentModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -28,10 +31,19 @@ */ class HtmlView extends BaseHtmlView { + /** + * @var mixed[] + */ + public $components; + /** + * @var bool + */ + public $userIsSuperAdmin; + public $currentComponent; /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry * @since 3.2 */ public $state; @@ -39,7 +51,7 @@ class HtmlView extends BaseHtmlView /** * The form object * - * @var \Joomla\CMS\Form\Form + * @var Form * @since 3.2 */ public $form; @@ -47,7 +59,7 @@ class HtmlView extends BaseHtmlView /** * An object with the information for the component * - * @var \Joomla\CMS\Component\ComponentRecord + * @var ComponentRecord * @since 3.2 */ public $component; @@ -103,8 +115,8 @@ public function display($tpl = null) $this->form = $model->getForm(); $user = $this->getCurrentUser(); - } catch (\Exception $e) { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + } catch (\Exception $exception) { + Factory::getApplication()->enqueueMessage($exception->getMessage(), 'error'); return; } @@ -148,7 +160,7 @@ protected function addToolbar() $toolbar->divider(); $inlinehelp = (string) $this->form->getXml()->config->inlinehelp['button'] === 'show'; - $targetClass = (string) $this->form->getXml()->config->inlinehelp['targetclass'] ?: 'hide-aware-inline-help'; + $targetClass = (string) $this->form->getXml()->config->inlinehelp['targetclass'] !== '' && (string) $this->form->getXml()->config->inlinehelp['targetclass'] !== '0' ? (string) $this->form->getXml()->config->inlinehelp['targetclass'] : 'hide-aware-inline-help'; if ($inlinehelp) { $toolbar->inlinehelp($targetClass); @@ -158,9 +170,9 @@ protected function addToolbar() $helpKey = (string) $this->form->getXml()->config->help['key']; // Try with legacy language key - if (!$helpKey) { + if ($helpKey === '' || $helpKey === '0') { $language = Factory::getApplication()->getLanguage(); - $languageKey = 'JHELP_COMPONENTS_' . strtoupper($this->currentComponent) . '_OPTIONS'; + $languageKey = 'JHELP_COMPONENTS_' . strtoupper((string) $this->currentComponent) . '_OPTIONS'; if ($language->hasKey($languageKey)) { $helpKey = $languageKey; diff --git a/administrator/components/com_config/tmpl/application/default_cache.php b/administrator/components/com_config/tmpl/application/default_cache.php index e9d88a07764d2..5010ce7757164 100644 --- a/administrator/components/com_config/tmpl/application/default_cache.php +++ b/administrator/components/com_config/tmpl/application/default_cache.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_CACHE_SETTINGS'); $this->description = ''; $this->fieldsname = 'cache'; diff --git a/administrator/components/com_config/tmpl/application/default_cookie.php b/administrator/components/com_config/tmpl/application/default_cookie.php index 85dc8b44da95c..7a2ea45578ee6 100644 --- a/administrator/components/com_config/tmpl/application/default_cookie.php +++ b/administrator/components/com_config/tmpl/application/default_cookie.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_COOKIE_SETTINGS'); $this->description = ''; $this->fieldsname = 'cookie'; diff --git a/administrator/components/com_config/tmpl/application/default_database.php b/administrator/components/com_config/tmpl/application/default_database.php index 9c537b940454b..6e346fa6fdb4e 100644 --- a/administrator/components/com_config/tmpl/application/default_database.php +++ b/administrator/components/com_config/tmpl/application/default_database.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_DATABASE_SETTINGS'); $this->description = ''; $this->fieldsname = 'database'; diff --git a/administrator/components/com_config/tmpl/application/default_debug.php b/administrator/components/com_config/tmpl/application/default_debug.php index 7c57a2d203ada..80c2b3d3ed62b 100644 --- a/administrator/components/com_config/tmpl/application/default_debug.php +++ b/administrator/components/com_config/tmpl/application/default_debug.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_DEBUG_SETTINGS'); $this->description = ''; $this->fieldsname = 'debug'; diff --git a/administrator/components/com_config/tmpl/application/default_filters.php b/administrator/components/com_config/tmpl/application/default_filters.php index 3231b109fc2fa..2549d60e61da5 100644 --- a/administrator/components/com_config/tmpl/application/default_filters.php +++ b/administrator/components/com_config/tmpl/application/default_filters.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_TEXT_FILTER_SETTINGS'); $this->description = ''; $this->fieldsname = 'filters'; diff --git a/administrator/components/com_config/tmpl/application/default_locale.php b/administrator/components/com_config/tmpl/application/default_locale.php index 86f7633eecc94..8b6f69a31380e 100644 --- a/administrator/components/com_config/tmpl/application/default_locale.php +++ b/administrator/components/com_config/tmpl/application/default_locale.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_LOCATION_SETTINGS'); $this->description = ''; $this->fieldsname = 'locale'; diff --git a/administrator/components/com_config/tmpl/application/default_logging.php b/administrator/components/com_config/tmpl/application/default_logging.php index 0ef1c8a8d7f23..1ddf9d69e39fd 100644 --- a/administrator/components/com_config/tmpl/application/default_logging.php +++ b/administrator/components/com_config/tmpl/application/default_logging.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_LOGGING_SETTINGS'); $this->description = ''; $this->fieldsname = 'logging'; diff --git a/administrator/components/com_config/tmpl/application/default_logging_custom.php b/administrator/components/com_config/tmpl/application/default_logging_custom.php index d84e8117b90d8..d74cc9275e3c9 100644 --- a/administrator/components/com_config/tmpl/application/default_logging_custom.php +++ b/administrator/components/com_config/tmpl/application/default_logging_custom.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_LOGGING_CUSTOM_SETTINGS'); $this->description = ''; $this->fieldsname = 'logging_custom'; diff --git a/administrator/components/com_config/tmpl/application/default_metadata.php b/administrator/components/com_config/tmpl/application/default_metadata.php index 08d3a241f7529..85ee5d9ebf751 100644 --- a/administrator/components/com_config/tmpl/application/default_metadata.php +++ b/administrator/components/com_config/tmpl/application/default_metadata.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_METADATA_SETTINGS'); $this->description = ''; $this->fieldsname = 'metadata'; diff --git a/administrator/components/com_config/tmpl/application/default_permissions.php b/administrator/components/com_config/tmpl/application/default_permissions.php index 87ffa4a2c8389..52b5b045f9d44 100644 --- a/administrator/components/com_config/tmpl/application/default_permissions.php +++ b/administrator/components/com_config/tmpl/application/default_permissions.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_PERMISSION_SETTINGS'); $this->description = ''; $this->fieldsname = 'permissions'; diff --git a/administrator/components/com_config/tmpl/application/default_proxy.php b/administrator/components/com_config/tmpl/application/default_proxy.php index 609cd0dd837f6..00b237ed746ce 100644 --- a/administrator/components/com_config/tmpl/application/default_proxy.php +++ b/administrator/components/com_config/tmpl/application/default_proxy.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_PROXY_SETTINGS'); $this->description = ''; $this->fieldsname = 'proxy'; diff --git a/administrator/components/com_config/tmpl/application/default_seo.php b/administrator/components/com_config/tmpl/application/default_seo.php index 2841add1d4612..4e44315aa17a5 100644 --- a/administrator/components/com_config/tmpl/application/default_seo.php +++ b/administrator/components/com_config/tmpl/application/default_seo.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_SEO_SETTINGS'); $this->description = Text::_('COM_CONFIG_SEO_SETTINGS_DESC'); $this->fieldsname = 'seo'; diff --git a/administrator/components/com_config/tmpl/application/default_server.php b/administrator/components/com_config/tmpl/application/default_server.php index 71fd03907c878..5bef8d030df32 100644 --- a/administrator/components/com_config/tmpl/application/default_server.php +++ b/administrator/components/com_config/tmpl/application/default_server.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_SERVER_SETTINGS'); $this->description = ''; $this->fieldsname = 'server'; diff --git a/administrator/components/com_config/tmpl/application/default_session.php b/administrator/components/com_config/tmpl/application/default_session.php index f31bc7fa90cea..67724b8b17c05 100644 --- a/administrator/components/com_config/tmpl/application/default_session.php +++ b/administrator/components/com_config/tmpl/application/default_session.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_SESSION_SETTINGS'); $this->description = ''; $this->fieldsname = 'session'; diff --git a/administrator/components/com_config/tmpl/application/default_site.php b/administrator/components/com_config/tmpl/application/default_site.php index e29382ed3a232..669ae5aaea196 100644 --- a/administrator/components/com_config/tmpl/application/default_site.php +++ b/administrator/components/com_config/tmpl/application/default_site.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_SITE_SETTINGS'); $this->description = ''; $this->fieldsname = 'site'; diff --git a/administrator/components/com_config/tmpl/application/default_webservices.php b/administrator/components/com_config/tmpl/application/default_webservices.php index 443dc7e6475a8..0ce1b31069add 100644 --- a/administrator/components/com_config/tmpl/application/default_webservices.php +++ b/administrator/components/com_config/tmpl/application/default_webservices.php @@ -8,13 +8,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +use Joomla\Component\Config\Administrator\View\Application\HtmlView; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; defined('_JEXEC') or die; -/** @var \Joomla\Component\Config\Administrator\View\Application\HtmlView $this */ - +/** @var HtmlView $this */ $this->name = Text::_('COM_CONFIG_WEBSERVICES_SETTINGS'); $this->description = ''; $this->fieldsname = 'webservices'; diff --git a/administrator/components/com_config/tmpl/component/default.php b/administrator/components/com_config/tmpl/component/default.php index 0ffc394ad285b..bc5c10c224a54 100644 --- a/administrator/components/com_config/tmpl/component/default.php +++ b/administrator/components/com_config/tmpl/component/default.php @@ -68,7 +68,7 @@ showon)) : ?> useScript('showon'); ?> - showon, $this->formControl)) . '\''; ?> + showon, $this->formControl)) . "'"; ?> label) ? 'COM_CONFIG_' . $name . '_FIELDSET_LABEL' : $fieldSet->label; ?> @@ -78,7 +78,7 @@ label); ?>
- + 1) : ?>
@@ -117,7 +117,7 @@ - + 1) : ?> diff --git a/administrator/components/com_contact/src/Controller/ContactController.php b/administrator/components/com_contact/src/Controller/ContactController.php index 4e77dec9217b0..381d04719d713 100644 --- a/administrator/components/com_contact/src/Controller/ContactController.php +++ b/administrator/components/com_contact/src/Controller/ContactController.php @@ -14,6 +14,7 @@ use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Router\Route; use Joomla\CMS\Versioning\VersionableControllerTrait; +use Joomla\Component\Contact\Administrator\Model\ContactModel; use Joomla\Utilities\ArrayHelper; // phpcs:disable PSR1.Files.SideEffects @@ -63,7 +64,7 @@ protected function allowAdd($data = []) */ protected function allowEdit($data = [], $key = 'id') { - $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + $recordId = (int) isset($data[$key]) !== 0 ? $data[$key] : 0; // Since there is no asset tracking, fallback to the component permissions. if (!$recordId) { @@ -101,7 +102,7 @@ public function batch($model = null) $this->checkToken(); // Set the model - /** @var \Joomla\Component\Contact\Administrator\Model\ContactModel $model */ + /** @var ContactModel $model */ $model = $this->getModel('Contact', 'Administrator', []); // Preset the redirect diff --git a/administrator/components/com_contact/src/Controller/ContactsController.php b/administrator/components/com_contact/src/Controller/ContactsController.php index 3c44571dfb671..0ef86a06a84b3 100644 --- a/administrator/components/com_contact/src/Controller/ContactsController.php +++ b/administrator/components/com_contact/src/Controller/ContactsController.php @@ -14,7 +14,9 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\AdminController; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Response\JsonResponse; +use Joomla\Component\Contact\Administrator\Model\ContactModel; use Joomla\Input\Input; use Joomla\Utilities\ArrayHelper; @@ -66,7 +68,7 @@ public function featured() $value = ArrayHelper::getValue($values, $task, 0, 'int'); // Get the model. - /** @var \Joomla\Component\Contact\Administrator\Model\ContactModel $model */ + /** @var ContactModel $model */ $model = $this->getModel(); // Access checks. @@ -87,7 +89,7 @@ public function featured() } } - if (empty($ids)) { + if ($ids === []) { $message = null; $this->app->enqueueMessage(Text::_('COM_CONTACT_NO_ITEM_SELECTED'), 'warning'); @@ -114,7 +116,7 @@ public function featured() * @param string $prefix The prefix for the PHP class name. * @param array $config Array of configuration parameters. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel + * @return BaseDatabaseModel * * @since 1.6 */ diff --git a/administrator/components/com_contact/src/Controller/DisplayController.php b/administrator/components/com_contact/src/Controller/DisplayController.php index 0b78a94eab855..014f89f9d0cf7 100644 --- a/administrator/components/com_contact/src/Controller/DisplayController.php +++ b/administrator/components/com_contact/src/Controller/DisplayController.php @@ -53,7 +53,7 @@ public function display($cachable = false, $urlparams = []) // Check for edit form. if ($view == 'contact' && $layout == 'edit' && !$this->checkEditId('com_contact.edit.contact', $id)) { // Somehow the person just went to the form - we don't allow that. - if (!\count($this->app->getMessageQueue())) { + if (\count($this->app->getMessageQueue()) === 0) { $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error'); } diff --git a/administrator/components/com_contact/src/Extension/ContactComponent.php b/administrator/components/com_contact/src/Extension/ContactComponent.php index 7016c7503687a..90a4a04b0b20a 100644 --- a/administrator/components/com_contact/src/Extension/ContactComponent.php +++ b/administrator/components/com_contact/src/Extension/ContactComponent.php @@ -122,13 +122,11 @@ public function getContexts(): array { Factory::getLanguage()->load('com_contact', JPATH_ADMINISTRATOR); - $contexts = [ + return [ 'com_contact.contact' => Text::_('COM_CONTACT_FIELDS_CONTEXT_CONTACT'), 'com_contact.mail' => Text::_('COM_CONTACT_FIELDS_CONTEXT_MAIL'), 'com_contact.categories' => Text::_('JCATEGORY'), ]; - - return $contexts; } /** @@ -170,10 +168,8 @@ public function getSchemaorgContexts(): array { Factory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR); - $contexts = [ + return [ 'com_contact.contact' => Text::_('COM_CONTACT'), ]; - - return $contexts; } } diff --git a/administrator/components/com_contact/src/Field/Modal/ContactField.php b/administrator/components/com_contact/src/Field/Modal/ContactField.php index 7dc872ac6db99..1bfec8d4ad313 100644 --- a/administrator/components/com_contact/src/Field/Modal/ContactField.php +++ b/administrator/components/com_contact/src/Field/Modal/ContactField.php @@ -53,8 +53,8 @@ class ContactField extends ModalSelectField public function setup(\SimpleXMLElement $element, $value, $group = null) { // Check if the value consist with id:alias, extract the id only - if ($value && str_contains($value, ':')) { - [$id] = explode(':', $value, 2); + if ($value && str_contains((string) $value, ':')) { + [$id] = explode(':', (string) $value, 2); $value = (int) $id; } @@ -70,7 +70,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) $language = (string) $this->element['language']; // Prepare enabled actions - $this->canDo['propagate'] = ((string) $this->element['propagate'] == 'true') && \count($languages) > 2; + $this->canDo['propagate'] = ((string) $this->element['propagate'] === 'true') && \count($languages) > 2; // Prepare Urls $linkItems = (new Uri())->setPath(Uri::base(true) . '/index.php'); @@ -83,6 +83,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) ]); $linkItem = clone $linkItems; $linkItem->setVar('view', 'contact'); + $linkCheckin = (new Uri())->setPath(Uri::base(true) . '/index.php'); $linkCheckin->setQuery([ 'option' => 'com_contact', @@ -91,7 +92,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) Session::getFormToken() => 1, ]); - if ($language) { + if ($language !== '' && $language !== '0') { $linkItems->setVar('forcedLanguage', $language); $linkItem->setVar('forcedLanguage', $language); @@ -105,6 +106,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) $urlSelect = $linkItems; $urlEdit = clone $linkItem; $urlEdit->setVar('task', 'contact.edit'); + $urlNew = clone $linkItem; $urlNew->setVar('task', 'contact.add'); @@ -132,23 +134,21 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) */ protected function getValueTitle() { - $value = (int) $this->value ?: ''; + $value = (int) $this->value !== 0 ? (int) $this->value : ''; $title = ''; - if ($value) { - try { - $db = $this->getDatabase(); - $query = $db->getQuery(true) - ->select($db->quoteName('name')) - ->from($db->quoteName('#__contact_details')) - ->where($db->quoteName('id') . ' = :value') - ->bind(':value', $value, ParameterType::INTEGER); - $db->setQuery($query); - - $title = $db->loadResult(); - } catch (\Throwable $e) { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); - } + try { + $db = $this->getDatabase(); + $query = $db->getQuery(true) + ->select($db->quoteName('name')) + ->from($db->quoteName('#__contact_details')) + ->where($db->quoteName('id') . ' = :value') + ->bind(':value', $value, ParameterType::INTEGER); + $db->setQuery($query); + + $title = $db->loadResult(); + } catch (\Throwable $throwable) { + Factory::getApplication()->enqueueMessage($throwable->getMessage(), 'error'); } return $title ?: $value; diff --git a/administrator/components/com_contact/src/Model/ContactModel.php b/administrator/components/com_contact/src/Model/ContactModel.php index 7344f38bd7ee3..30f6352f8384b 100644 --- a/administrator/components/com_contact/src/Model/ContactModel.php +++ b/administrator/components/com_contact/src/Model/ContactModel.php @@ -18,8 +18,10 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Model\AdminModel; use Joomla\CMS\String\PunycodeHelper; +use Joomla\CMS\Table\Table; use Joomla\CMS\Versioning\VersionableModelTrait; use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper; +use Joomla\Component\Categories\Administrator\Model\CategoryModel; use Joomla\Database\ParameterType; use Joomla\Registry\Registry; use Joomla\Utilities\ArrayHelper; @@ -292,14 +294,14 @@ public function save($data) if ($createCategory && $this->canCreateCategory()) { $category = [ // Remove #new# prefix, if exists. - 'title' => strpos($data['catid'], '#new#') === 0 ? substr($data['catid'], 5) : $data['catid'], + 'title' => str_starts_with((string) $data['catid'], '#new#') ? substr((string) $data['catid'], 5) : $data['catid'], 'parent_id' => 1, 'extension' => 'com_contact', 'language' => $data['language'], 'published' => 1, ]; - /** @var \Joomla\Component\Categories\Administrator\Model\CategoryModel $categoryModel */ + /** @var CategoryModel $categoryModel */ $categoryModel = Factory::getApplication()->bootComponent('com_categories') ->getMVCFactory()->createModel('Category', 'Administrator', ['ignore_request' => true]); @@ -320,13 +322,11 @@ public function save($data) $origTable->load($input->getInt('id')); if ($data['name'] == $origTable->name) { - list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']); + [$name, $alias] = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']); $data['name'] = $name; $data['alias'] = $alias; - } else { - if ($data['alias'] == $origTable->alias) { - $data['alias'] = ''; - } + } elseif ($data['alias'] == $origTable->alias) { + $data['alias'] = ''; } $data['published'] = 0; @@ -346,7 +346,7 @@ public function save($data) /** * Prepare and sanitise the table prior to saving. * - * @param \Joomla\CMS\Table\Table $table The Table object + * @param Table $table The Table object * * @return void * @@ -388,7 +388,7 @@ protected function prepareTable($table) /** * A protected method to get a set of ordering conditions. * - * @param \Joomla\CMS\Table\Table $table A record object. + * @param Table $table A record object. * * @return array An array of conditions to add to ordering queries. * @@ -488,8 +488,8 @@ public function featured($pks, $value = 0) $db->setQuery($query); $db->execute(); - } catch (\Exception $e) { - $this->setError($e->getMessage()); + } catch (\Exception $exception) { + $this->setError($exception->getMessage()); return false; } diff --git a/administrator/components/com_contact/src/Model/ContactsModel.php b/administrator/components/com_contact/src/Model/ContactsModel.php index cbacd0635e8c0..d0ed660ed82c1 100644 --- a/administrator/components/com_contact/src/Model/ContactsModel.php +++ b/administrator/components/com_contact/src/Model/ContactsModel.php @@ -154,7 +154,7 @@ protected function getListQuery() $db->quoteName( explode( ', ', - $this->getState( + (string) $this->getState( 'list.select', 'a.id, a.name, a.alias, a.checked_out, a.checked_out_time, a.catid, a.user_id' . ', a.published, a.access, a.created, a.created_by, a.ordering, a.featured, a.language' . @@ -254,12 +254,12 @@ protected function getListQuery() $search = $this->getState('filter.search'); if (!empty($search)) { - if (stripos($search, 'id:') === 0) { - $search = substr($search, 3); + if (stripos((string) $search, 'id:') === 0) { + $search = substr((string) $search, 3); $query->where($db->quoteName('a.id') . ' = :id'); $query->bind(':id', $search, ParameterType::INTEGER); } else { - $search = '%' . trim($search) . '%'; + $search = '%' . trim((string) $search) . '%'; $query->where( '(' . $db->quoteName('a.name') . ' LIKE :name OR ' . $db->quoteName('a.alias') . ' LIKE :alias)' ); @@ -300,7 +300,7 @@ protected function getListQuery() '(' . $subQuery . ') AS ' . $db->quoteName('tagmap'), $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id') ); - } elseif ($tag = (int) $tag) { + } elseif ($tag = (int) $tag !== 0) { $query->join( 'INNER', $db->quoteName('#__contentitem_tag_map', 'tagmap'), @@ -324,7 +324,7 @@ protected function getListQuery() } // Case: Using both categories filter and by level filter - if (\count($categoryId)) { + if ($categoryId !== []) { $categoryId = ArrayHelper::toInteger($categoryId); $categoryTable = Table::getInstance('Category', '\\Joomla\\CMS\\Table\\'); $subCatItemsWhere = []; diff --git a/administrator/components/com_contact/src/Service/HTML/AdministratorService.php b/administrator/components/com_contact/src/Service/HTML/AdministratorService.php index d99c69510bb38..70ec3a3122686 100644 --- a/administrator/components/com_contact/src/Service/HTML/AdministratorService.php +++ b/administrator/components/com_contact/src/Service/HTML/AdministratorService.php @@ -133,12 +133,10 @@ public function featured($value, $i, $canChange = true) $tooltipText = Text::_($state[2]); } - $html = '' . ''; - - return $html; } } diff --git a/administrator/components/com_contact/src/Service/HTML/Icon.php b/administrator/components/com_contact/src/Service/HTML/Icon.php index 9073e21a66395..43c26b5ea0c5b 100644 --- a/administrator/components/com_contact/src/Service/HTML/Icon.php +++ b/administrator/components/com_contact/src/Service/HTML/Icon.php @@ -78,9 +78,7 @@ public function create($category, $params, $attribs = []) $attribs['class'] = 'btn btn-primary'; } - $button = HTMLHelper::_('link', Route::_($url), $text, $attribs); - - return $button; + return HTMLHelper::_('link', Route::_($url), $text, $attribs); } /** @@ -128,9 +126,8 @@ public function edit($contact, $params, $attribs = [], $legacy = false) $text = LayoutHelper::render('joomla.content.icons.edit_lock', ['contact' => $contact, 'tooltip' => $tooltip, 'legacy' => $legacy]); $attribs['aria-describedby'] = 'editcontact-' . (int) $contact->id; - $output = HTMLHelper::_('link', '#', $text, $attribs); - return $output; + return HTMLHelper::_('link', '#', $text, $attribs); } $contactUrl = RouteHelper::getContactRoute($contact->slug, $contact->catid, $contact->language); @@ -159,8 +156,7 @@ public function edit($contact, $params, $attribs = [], $legacy = false) $text .= ''; $attribs['aria-describedby'] = $aria_described; - $output = HTMLHelper::_('link', Route::_($url), $text, $attribs); - return $output; + return HTMLHelper::_('link', Route::_($url), $text, $attribs); } } diff --git a/administrator/components/com_contact/src/Table/ContactTable.php b/administrator/components/com_contact/src/Table/ContactTable.php index c1ba065f60a22..c32b0bb788103 100644 --- a/administrator/components/com_contact/src/Table/ContactTable.php +++ b/administrator/components/com_contact/src/Table/ContactTable.php @@ -87,7 +87,7 @@ public function store($updateNulls = true) $userId = $this->getCurrentUser()->id; // Set created date if not set. - if (!(int) $this->created) { + if ((int) $this->created === 0) { $this->created = $date; } @@ -101,7 +101,7 @@ public function store($updateNulls = true) $this->created_by = $userId; } - if (!(int) $this->modified) { + if ((int) $this->modified === 0) { $this->modified = $date; } @@ -149,8 +149,8 @@ public function check() { try { parent::check(); - } catch (\Exception $e) { - $this->setError($e->getMessage()); + } catch (\Exception $exception) { + $this->setError($exception->getMessage()); return false; } @@ -164,7 +164,7 @@ public function check() } // Check for valid name - if (trim($this->name) == '') { + if (trim($this->name) === '') { $this->setError(Text::_('COM_CONTACT_WARNING_PROVIDE_VALID_NAME')); return false; @@ -174,7 +174,7 @@ public function check() $this->generateAlias(); // Check for a valid category. - if (!$this->catid = (int) $this->catid) { + if ($this->catid = (int) $this->catid === 0) { $this->setError(Text::_('JLIB_DATABASE_ERROR_CATEGORY_REQUIRED')); return false; @@ -200,7 +200,7 @@ public function check() // Clean up description -- eliminate quotes and <> brackets if (!empty($this->metadesc)) { // Only process if not empty - $badCharacters = ["\"", '<', '>']; + $badCharacters = ['"', '<', '>']; $this->metadesc = StringHelper::str_ireplace($badCharacters, '', $this->metadesc); } else { $this->metadesc = ''; @@ -252,7 +252,7 @@ public function generateAlias() $this->alias = ApplicationHelper::stringURLSafe($this->alias, $this->language); - if (trim(str_replace('-', '', $this->alias)) == '') { + if (trim(str_replace('-', '', $this->alias)) === '') { $this->alias = Factory::getDate()->format('Y-m-d-H-i-s'); } diff --git a/administrator/components/com_contact/src/View/Contact/HtmlView.php b/administrator/components/com_contact/src/View/Contact/HtmlView.php index 5e64cf65aca61..5076368f9cf3c 100644 --- a/administrator/components/com_contact/src/View/Contact/HtmlView.php +++ b/administrator/components/com_contact/src/View/Contact/HtmlView.php @@ -12,6 +12,7 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Text; @@ -20,6 +21,7 @@ use Joomla\CMS\Toolbar\Toolbar; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Contact\Administrator\Model\ContactModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -35,7 +37,7 @@ class HtmlView extends BaseHtmlView /** * The Form object * - * @var \Joomla\CMS\Form\Form + * @var Form */ protected $form; @@ -49,7 +51,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $state; @@ -86,7 +88,7 @@ public function display($tpl = null) } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -126,7 +128,7 @@ protected function addToolbar() $user = $this->getCurrentUser(); $userId = $user->id; $isNew = ($this->item->id == 0); - $checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $userId); + $checkedOut = !\is_null($this->item->checked_out) && $this->item->checked_out != $userId; $toolbar = $this->getDocument()->getToolbar(); // Since we don't track these assets at the item level, use the category id. diff --git a/administrator/components/com_contact/src/View/Contacts/HtmlView.php b/administrator/components/com_contact/src/View/Contacts/HtmlView.php index 02dea42e0211b..a4af77fd08aff 100644 --- a/administrator/components/com_contact/src/View/Contacts/HtmlView.php +++ b/administrator/components/com_contact/src/View/Contacts/HtmlView.php @@ -11,14 +11,17 @@ namespace Joomla\Component\Contact\Administrator\View\Contacts; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Toolbar\Button\DropdownButton; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Contact\Administrator\Model\ContactsModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -41,21 +44,21 @@ class HtmlView extends BaseHtmlView /** * The pagination object * - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination */ protected $pagination; /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $state; /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form */ public $filterForm; @@ -93,38 +96,33 @@ public function display($tpl = null) $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + if (\count($this->items) === 0 && $this->isEmptyState = $model->getIsEmptyState()) { $this->setLayout('emptystate'); } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } // We don't need toolbar in the modal window. if ($this->getLayout() !== 'modal') { $this->addToolbar(); - // We do not need to filter by language when multilingual is disabled if (!Multilanguage::isEnabled()) { unset($this->activeFilters['language']); $this->filterForm->removeField('language', 'filter'); } - } else { + } elseif ($forcedLanguage = Factory::getApplication()->getInput()->get('forcedLanguage', '', 'CMD')) { // In article associations modal we need to remove language filter if forcing a language. // We also need to change the category filter to show show categories with All or the forced language. - if ($forcedLanguage = Factory::getApplication()->getInput()->get('forcedLanguage', '', 'CMD')) { - // If the language is forced we can't allow to select the language, so transform the language selector filter into a hidden field. - $languageXml = new \SimpleXMLElement(''); - $this->filterForm->setField($languageXml, 'filter', true); - - // Also, unset the active language filter so the search tools is not open by default with this filter. - unset($this->activeFilters['language']); - - // One last changes needed is to change the category filter to just show categories with All language or with the forced language. - $this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter'); - } + // If the language is forced we can't allow to select the language, so transform the language selector filter into a hidden field. + $languageXml = new \SimpleXMLElement(''); + $this->filterForm->setField($languageXml, 'filter', true); + // Also, unset the active language filter so the search tools is not open by default with this filter. + unset($this->activeFilters['language']); + // One last changes needed is to change the category filter to just show categories with All language or with the forced language. + $this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter'); } parent::display($tpl); diff --git a/administrator/components/com_contact/tmpl/contacts/default.php b/administrator/components/com_contact/tmpl/contacts/default.php index 83049cc92f6be..4f64b23805ff5 100644 --- a/administrator/components/com_contact/tmpl/contacts/default.php +++ b/administrator/components/com_contact/tmpl/contacts/default.php @@ -93,7 +93,7 @@ class="js-draggable" data-url="" data-direction="" data-nested="true" class="js-draggable" data-url="" data-direction="" data-nested="true"> items); diff --git a/administrator/components/com_contact/tmpl/contacts/emptystate.php b/administrator/components/com_contact/tmpl/contacts/emptystate.php index c42bdffdf487b..565a61c3b125d 100644 --- a/administrator/components/com_contact/tmpl/contacts/emptystate.php +++ b/administrator/components/com_contact/tmpl/contacts/emptystate.php @@ -1,5 +1,7 @@ 'COM_CONTACT', 'formURL' => 'index.php?option=com_contact', diff --git a/administrator/components/com_contact/tmpl/contacts/modal.php b/administrator/components/com_contact/tmpl/contacts/modal.php index ed2579532dc83..d823b500347ff 100644 --- a/administrator/components/com_contact/tmpl/contacts/modal.php +++ b/administrator/components/com_contact/tmpl/contacts/modal.php @@ -110,7 +110,7 @@ } $link = RouteHelper::getContactRoute($item->id, $item->catid, $item->language); - $itemHtml = '' . $item->name . ''; + $itemHtml = '' . $item->name . ''; ?> diff --git a/administrator/components/com_content/src/Controller/AjaxController.php b/administrator/components/com_content/src/Controller/AjaxController.php index 9b8047b685320..506d983f2c15e 100644 --- a/administrator/components/com_content/src/Controller/AjaxController.php +++ b/administrator/components/com_content/src/Controller/AjaxController.php @@ -37,7 +37,6 @@ class AjaxController extends BaseController * assocId: the id of the article whose associations are to be returned * excludeLang: the association for this language is to be excluded * - * @return null * * @since 3.9.0 */ diff --git a/administrator/components/com_content/src/Controller/ArticleController.php b/administrator/components/com_content/src/Controller/ArticleController.php index abffcfed2f15b..4c7edb17f3a7c 100644 --- a/administrator/components/com_content/src/Controller/ArticleController.php +++ b/administrator/components/com_content/src/Controller/ArticleController.php @@ -16,6 +16,7 @@ use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Router\Route; use Joomla\CMS\Versioning\VersionableControllerTrait; +use Joomla\Component\Content\Administrator\Model\ArticleModel; use Joomla\Input\Input; use Joomla\Utilities\ArrayHelper; @@ -159,7 +160,7 @@ protected function allowAdd($data = []) */ protected function allowEdit($data = [], $key = 'id') { - $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + $recordId = (int) isset($data[$key]) !== 0 ? $data[$key] : 0; $user = $this->app->getIdentity(); // Zero record (id:0), return component edit permission by calling parent controller method @@ -202,7 +203,7 @@ public function batch($model = null) $this->checkToken(); // Set the model - /** @var \Joomla\Component\Content\Administrator\Model\ArticleModel $model */ + /** @var ArticleModel $model */ $model = $this->getModel('Article', 'Administrator', []); // Preset the redirect diff --git a/administrator/components/com_content/src/Controller/ArticlesController.php b/administrator/components/com_content/src/Controller/ArticlesController.php index dc86b71f090e5..b6b15b7ab0abb 100644 --- a/administrator/components/com_content/src/Controller/ArticlesController.php +++ b/administrator/components/com_content/src/Controller/ArticlesController.php @@ -14,8 +14,10 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\AdminController; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Response\JsonResponse; use Joomla\CMS\Router\Route; +use Joomla\Component\Content\Administrator\Model\ArticleModel; use Joomla\Input\Input; use Joomla\Utilities\ArrayHelper; @@ -90,7 +92,7 @@ public function featured() } } - if (empty($ids)) { + if ($ids === []) { $this->app->enqueueMessage(Text::_('JERROR_NO_ITEMS_SELECTED'), 'error'); $this->setRedirect(Route::_($redirectUrl, false)); @@ -99,7 +101,7 @@ public function featured() } // Get the model. - /** @var \Joomla\Component\Content\Administrator\Model\ArticleModel $model */ + /** @var ArticleModel $model */ $model = $this->getModel(); // Publish the items. @@ -125,7 +127,7 @@ public function featured() * @param string $prefix The class prefix. Optional. * @param array $config The array of possible config values. Optional. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel + * @return BaseDatabaseModel * * @since 1.6 */ diff --git a/administrator/components/com_content/src/Controller/DisplayController.php b/administrator/components/com_content/src/Controller/DisplayController.php index 158c8f3a17ce3..41d2ad7b53343 100644 --- a/administrator/components/com_content/src/Controller/DisplayController.php +++ b/administrator/components/com_content/src/Controller/DisplayController.php @@ -53,7 +53,7 @@ public function display($cachable = false, $urlparams = []) // Check for edit form. if ($view == 'article' && $layout == 'edit' && !$this->checkEditId('com_content.edit.article', $id)) { // Somehow the person just went to the form - we don't allow that. - if (!\count($this->app->getMessageQueue())) { + if (\count($this->app->getMessageQueue()) === 0) { $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error'); } diff --git a/administrator/components/com_content/src/Controller/FeaturedController.php b/administrator/components/com_content/src/Controller/FeaturedController.php index 92756c9fc89c6..ae3c5d70a7e86 100644 --- a/administrator/components/com_content/src/Controller/FeaturedController.php +++ b/administrator/components/com_content/src/Controller/FeaturedController.php @@ -11,7 +11,9 @@ namespace Joomla\Component\Content\Administrator\Controller; use Joomla\CMS\Language\Text; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Response\JsonResponse; +use Joomla\Component\Content\Administrator\Model\FeatureModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -55,10 +57,10 @@ public function delete() } } - if (empty($ids)) { + if ($ids === []) { $this->app->enqueueMessage(Text::_('JERROR_NO_ITEMS_SELECTED'), 'error'); } else { - /** @var \Joomla\Component\Content\Administrator\Model\FeatureModel $model */ + /** @var FeatureModel $model */ $model = $this->getModel(); // Remove the items. @@ -91,7 +93,7 @@ public function publish() * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model. + * @return BaseDatabaseModel The model. * * @since 1.6 */ diff --git a/administrator/components/com_content/src/Event/Model/FeatureEvent.php b/administrator/components/com_content/src/Event/Model/FeatureEvent.php index 226a56203a3c7..29a5834a47175 100644 --- a/administrator/components/com_content/src/Event/Model/FeatureEvent.php +++ b/administrator/components/com_content/src/Event/Model/FeatureEvent.php @@ -35,36 +35,36 @@ class FeatureEvent extends AbstractImmutableEvent public function __construct($name, array $arguments = []) { if (!isset($arguments['extension'])) { - throw new \BadMethodCallException("Argument 'extension' of event $this->name is required but has not been provided"); + throw new \BadMethodCallException(\sprintf("Argument 'extension' of event %s is required but has not been provided", $this->name)); } if (!isset($arguments['extension']) || !\is_string($arguments['extension'])) { - throw new \BadMethodCallException("Argument 'extension' of event $this->name is not of type 'string'"); + throw new \BadMethodCallException(\sprintf("Argument 'extension' of event %s is not of type 'string'", $this->name)); } - if (strpos($arguments['extension'], '.') === false) { - throw new \BadMethodCallException("Argument 'extension' of event $this->name has wrong format. Valid format: 'component.section'"); + if (!str_contains($arguments['extension'], '.')) { + throw new \BadMethodCallException(\sprintf("Argument 'extension' of event %s has wrong format. Valid format: 'component.section'", $this->name)); } if (!\array_key_exists('extensionName', $arguments) || !\array_key_exists('section', $arguments)) { $parts = explode('.', $arguments['extension']); - $arguments['extensionName'] = $arguments['extensionName'] ?? $parts[0]; - $arguments['section'] = $arguments['section'] ?? $parts[1]; + $arguments['extensionName'] ??= $parts[0]; + $arguments['section'] ??= $parts[1]; } if (!isset($arguments['pks']) || !\is_array($arguments['pks'])) { - throw new \BadMethodCallException("Argument 'pks' of event $this->name is not of type 'array'"); + throw new \BadMethodCallException(\sprintf("Argument 'pks' of event %s is not of type 'array'", $this->name)); } if (!isset($arguments['value']) || !is_numeric($arguments['value'])) { - throw new \BadMethodCallException("Argument 'value' of event $this->name is not of type 'numeric'"); + throw new \BadMethodCallException(\sprintf("Argument 'value' of event %s is not of type 'numeric'", $this->name)); } $arguments['value'] = (int) $arguments['value']; if ($arguments['value'] !== 0 && $arguments['value'] !== 1) { - throw new \BadMethodCallException("Argument 'value' of event $this->name is not 0 or 1"); + throw new \BadMethodCallException(\sprintf("Argument 'value' of event %s is not 0 or 1", $this->name)); } parent::__construct($name, $arguments); diff --git a/administrator/components/com_content/src/Extension/ContentComponent.php b/administrator/components/com_content/src/Extension/ContentComponent.php index bd2861e1fa467..aff33d556f813 100644 --- a/administrator/components/com_content/src/Extension/ContentComponent.php +++ b/administrator/components/com_content/src/Extension/ContentComponent.php @@ -178,12 +178,10 @@ public function getContexts(): array { Factory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR); - $contexts = [ + return [ 'com_content.article' => Text::_('COM_CONTENT'), 'com_content.categories' => Text::_('JCATEGORY'), ]; - - return $contexts; } /** @@ -197,11 +195,9 @@ public function getSchemaorgContexts(): array { Factory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR); - $contexts = [ + return [ 'com_content.article' => Text::_('COM_CONTENT'), ]; - - return $contexts; } /** @@ -215,11 +211,9 @@ public function getWorkflowContexts(): array { Factory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR); - $contexts = [ + return [ 'com_content.article' => Text::_('COM_CONTENT'), ]; - - return $contexts; } /** @@ -293,7 +287,7 @@ public function getModelName($context): string return 'Article'; } - return ucfirst($modelname); + return ucfirst((string) $modelname); } /** diff --git a/administrator/components/com_content/src/Field/Modal/ArticleField.php b/administrator/components/com_content/src/Field/Modal/ArticleField.php index c173321bbf6c0..cec0d1dee1a00 100644 --- a/administrator/components/com_content/src/Field/Modal/ArticleField.php +++ b/administrator/components/com_content/src/Field/Modal/ArticleField.php @@ -53,8 +53,8 @@ class ArticleField extends ModalSelectField public function setup(\SimpleXMLElement $element, $value, $group = null) { // Check if the value consist with id:alias, extract the id only - if ($value && str_contains($value, ':')) { - [$id] = explode(':', $value, 2); + if ($value && str_contains((string) $value, ':')) { + [$id] = explode(':', (string) $value, 2); $value = (int) $id; } @@ -70,7 +70,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) $language = (string) $this->element['language']; // Prepare enabled actions - $this->canDo['propagate'] = ((string) $this->element['propagate'] == 'true') && \count($languages) > 2; + $this->canDo['propagate'] = ((string) $this->element['propagate'] === 'true') && \count($languages) > 2; // Prepare Urls $linkArticles = (new Uri())->setPath(Uri::base(true) . '/index.php'); @@ -83,6 +83,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) ]); $linkArticle = clone $linkArticles; $linkArticle->setVar('view', 'article'); + $linkCheckin = (new Uri())->setPath(Uri::base(true) . '/index.php'); $linkCheckin->setQuery([ 'option' => 'com_content', @@ -91,7 +92,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) Session::getFormToken() => 1, ]); - if ($language) { + if ($language !== '' && $language !== '0') { $linkArticles->setVar('forcedLanguage', $language); $linkArticle->setVar('forcedLanguage', $language); @@ -105,6 +106,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) $urlSelect = $linkArticles; $urlEdit = clone $linkArticle; $urlEdit->setVar('task', 'article.edit'); + $urlNew = clone $linkArticle; $urlNew->setVar('task', 'article.add'); @@ -132,23 +134,21 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) */ protected function getValueTitle() { - $value = (int) $this->value ?: ''; + $value = (int) $this->value !== 0 ? (int) $this->value : ''; $title = ''; - if ($value) { - try { - $db = $this->getDatabase(); - $query = $db->getQuery(true) - ->select($db->quoteName('title')) - ->from($db->quoteName('#__content')) - ->where($db->quoteName('id') . ' = :value') - ->bind(':value', $value, ParameterType::INTEGER); - $db->setQuery($query); - - $title = $db->loadResult(); - } catch (\Throwable $e) { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); - } + try { + $db = $this->getDatabase(); + $query = $db->getQuery(true) + ->select($db->quoteName('title')) + ->from($db->quoteName('#__content')) + ->where($db->quoteName('id') . ' = :value') + ->bind(':value', $value, ParameterType::INTEGER); + $db->setQuery($query); + + $title = $db->loadResult(); + } catch (\Throwable $throwable) { + Factory::getApplication()->enqueueMessage($throwable->getMessage(), 'error'); } return $title ?: $value; diff --git a/administrator/components/com_content/src/Helper/ContentHelper.php b/administrator/components/com_content/src/Helper/ContentHelper.php index 46aa32889767d..7249350a33263 100644 --- a/administrator/components/com_content/src/Helper/ContentHelper.php +++ b/administrator/components/com_content/src/Helper/ContentHelper.php @@ -69,9 +69,7 @@ public static function filterTransitions(array $transitions, int $pk, int $workf return array_values( array_filter( $transitions, - function ($var) use ($pk, $workflowId) { - return \in_array($var['from_stage_id'], [-1, $pk]) && $workflowId == $var['workflow_id']; - } + fn ($var) => \in_array($var['from_stage_id'], [-1, $pk]) && $workflowId == $var['workflow_id'] ) ); } @@ -136,7 +134,7 @@ public static function onPrepareForm(Form $form, $data) $option = Text::sprintf('COM_WORKFLOW_INHERIT_WORKFLOW', Text::_($defaulttitle)); - if (!empty($categories)) { + if ($categories !== []) { $categories = array_reverse($categories); $query = $db->getQuery(true); @@ -167,7 +165,7 @@ public static function onPrepareForm(Form $form, $data) break; } - if ($workflow_id = (int) $workflow_id) { + if ($workflow_id = (int) $workflow_id !== 0) { $title = $db->loadResult(); if (!\is_null($title)) { diff --git a/administrator/components/com_content/src/Model/ArticleModel.php b/administrator/components/com_content/src/Model/ArticleModel.php index 6474be7a2753f..d55bb9efa3024 100644 --- a/administrator/components/com_content/src/Model/ArticleModel.php +++ b/administrator/components/com_content/src/Model/ArticleModel.php @@ -26,12 +26,14 @@ use Joomla\CMS\MVC\Model\WorkflowModelInterface; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\String\PunycodeHelper; +use Joomla\CMS\Table\Table; use Joomla\CMS\Table\TableInterface; use Joomla\CMS\Tag\TaggableTableInterface; use Joomla\CMS\UCM\UCMType; use Joomla\CMS\Versioning\VersionableModelTrait; use Joomla\CMS\Workflow\Workflow; use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper; +use Joomla\Component\Categories\Administrator\Model\CategoryModel; use Joomla\Component\Content\Administrator\Event\Model\FeatureEvent; use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; use Joomla\Database\ParameterType; @@ -84,7 +86,7 @@ class ArticleModel extends AdminModel implements WorkflowModelInterface * @var string * @since 4.0.0 */ - protected $event_before_change_featured = null; + protected $event_before_change_featured; /** * The event to trigger after changing featured status one or more items. @@ -92,7 +94,7 @@ class ArticleModel extends AdminModel implements WorkflowModelInterface * @var string * @since 4.0.0 */ - protected $event_after_change_featured = null; + protected $event_after_change_featured; /** * Constructor. @@ -106,7 +108,7 @@ class ArticleModel extends AdminModel implements WorkflowModelInterface */ public function __construct($config = [], ?MVCFactoryInterface $factory = null, ?FormFactoryInterface $formFactory = null) { - $config['events_map'] = $config['events_map'] ?? []; + $config['events_map'] ??= []; $config['events_map'] = array_merge( ['featured' => 'content'], @@ -117,9 +119,9 @@ public function __construct($config = [], ?MVCFactoryInterface $factory = null, // Set the featured status change events $this->event_before_change_featured = $config['event_before_change_featured'] ?? $this->event_before_change_featured; - $this->event_before_change_featured = $this->event_before_change_featured ?? 'onContentBeforeChangeFeatured'; + $this->event_before_change_featured ??= 'onContentBeforeChangeFeatured'; $this->event_after_change_featured = $config['event_after_change_featured'] ?? $this->event_after_change_featured; - $this->event_after_change_featured = $this->event_after_change_featured ?? 'onContentAfterChangeFeatured'; + $this->event_after_change_featured ??= 'onContentAfterChangeFeatured'; $this->setUpWorkflow('com_content.article'); } @@ -170,6 +172,7 @@ protected function cleanupPostBatchCopy(TableInterface $table, $newId, $oldId) $oldItem = $this->getTable(); $oldItem->load($oldId); + $fields = FieldsHelper::getFields('com_content.article', $oldItem, true); $fieldsData = []; @@ -202,7 +205,7 @@ protected function batchMove($value, $pks, $contexts) // Set some needed variables. $this->user = $this->getCurrentUser(); $this->table = $this->getTable(); - $this->tableClassName = \get_class($this->table); + $this->tableClassName = $this->table::class; $this->contentType = new UCMType(); $this->type = $this->contentType->getTypeByTable($this->tableClassName); } @@ -329,7 +332,7 @@ protected function canEditState($record) /** * Prepare and sanitise the table data prior to saving. * - * @param \Joomla\CMS\Table\Table $table A Table object. + * @param Table $table A Table object. * * @return void * @@ -398,7 +401,7 @@ public function getItem($pk = null) $registry = new Registry($item->urls); $item->urls = $registry->toArray(); - $item->articletext = ($item->fulltext !== null && trim($item->fulltext) != '') ? $item->introtext . '
' . $item->fulltext : $item->introtext; + $item->articletext = ($item->fulltext !== null && trim($item->fulltext) !== '') ? $item->introtext . '
' . $item->fulltext : $item->introtext; if (!empty($item->id)) { $item->tags = new TagsHelper(); @@ -492,7 +495,7 @@ public function getForm($data = [], $loadData = true) : (int) $assignedCatids; // Try to get the category from the category field - if (empty($assignedCatids)) { + if ($assignedCatids === 0) { $assignedCatids = $formField->getAttribute('default', null); if (!$assignedCatids) { @@ -523,7 +526,7 @@ public function getForm($data = [], $loadData = true) ? (int) reset($catIds) : (int) $catIds; - if (!$catId) { + if ($catId === 0) { $catId = (int) $form->getFieldAttribute('catid', 'default', 0); } } @@ -587,15 +590,15 @@ protected function loadFormData() ((isset($filters['published']) && $filters['published'] !== '') ? $filters['published'] : null) ) ); - $data->set('catid', $app->getInput()->getInt('catid', (!empty($filters['category_id']) ? $filters['category_id'] : null))); + $data->set('catid', $app->getInput()->getInt('catid', (empty($filters['category_id']) ? null : $filters['category_id']))); if ($app->isClient('administrator')) { - $data->set('language', $app->getInput()->getString('language', (!empty($filters['language']) ? $filters['language'] : null))); + $data->set('language', $app->getInput()->getString('language', (empty($filters['language']) ? null : $filters['language']))); } $data->set( 'access', - $app->getInput()->getInt('access', (!empty($filters['access']) ? $filters['access'] : $app->get('access'))) + $app->getInput()->getInt('access', (empty($filters['access']) ? $app->get('access') : $filters['access'])) ); } } @@ -625,10 +628,8 @@ protected function loadFormData() */ public function validate($form, $data, $group = null) { - if (!$this->getCurrentUser()->authorise('core.admin', 'com_content')) { - if (isset($data['rules'])) { - unset($data['rules']); - } + if (!$this->getCurrentUser()->authorise('core.admin', 'com_content') && isset($data['rules'])) { + unset($data['rules']); } return parent::validate($form, $data, $group); @@ -682,14 +683,14 @@ public function save($data) if ($createCategory && $this->canCreateCategory()) { $category = [ // Remove #new# prefix, if exists. - 'title' => strpos($data['catid'], '#new#') === 0 ? substr($data['catid'], 5) : $data['catid'], + 'title' => str_starts_with((string) $data['catid'], '#new#') ? substr((string) $data['catid'], 5) : $data['catid'], 'parent_id' => 1, 'extension' => 'com_content', 'language' => $data['language'], 'published' => 1, ]; - /** @var \Joomla\Component\Categories\Administrator\Model\CategoryModel $categoryModel */ + /** @var CategoryModel $categoryModel */ $categoryModel = Factory::getApplication()->bootComponent('com_categories') ->getMVCFactory()->createModel('Category', 'Administrator', ['ignore_request' => true]); @@ -709,7 +710,7 @@ public function save($data) foreach ($data['urls'] as $i => $url) { if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) { - if (preg_match('~^#[a-zA-Z]{1}[a-zA-Z0-9-_:.]*$~', $check['urls'][$i]) == 1) { + if (preg_match('~^#[a-zA-Z]{1}[a-zA-Z0-9-_:.]*$~', (string) $check['urls'][$i]) == 1) { $data['urls'][$i] = $check['urls'][$i]; } else { $data['urls'][$i] = PunycodeHelper::urlToPunycode($url); @@ -731,21 +732,13 @@ public function save($data) if ($app->isClient('site')) { $origTable->load($input->getInt('a_id')); - if ($origTable->title === $data['title']) { - /** - * If title of article is not changed, set alias to original article alias so that Joomla! will generate - * new Title and Alias for the copied article - */ - $data['alias'] = $origTable->alias; - } else { - $data['alias'] = ''; - } + $data['alias'] = $origTable->title === $data['title'] ? $origTable->alias : ''; } else { $origTable->load($input->getInt('id')); } if ($data['title'] == $origTable->title) { - list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); + [$title, $alias] = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); $data['title'] = $title; $data['alias'] = $alias; } elseif ($data['alias'] == $origTable->alias) { @@ -754,42 +747,34 @@ public function save($data) } // Automatic handling of alias for empty fields - if (\in_array($input->get('task'), ['apply', 'save', 'save2new']) && (!isset($data['id']) || (int) $data['id'] == 0)) { - if ($data['alias'] == null) { - if ($app->get('unicodeslugs') == 1) { - $data['alias'] = OutputFilter::stringUrlUnicodeSlug($data['title']); - } else { - $data['alias'] = OutputFilter::stringURLSafe($data['title']); - } - - $table = $this->getTable(); - - if ($table->load(['alias' => $data['alias'], 'catid' => $data['catid']])) { - $msg = Text::_('COM_CONTENT_SAVE_WARNING'); - } - - list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); - $data['alias'] = $alias; - - if (isset($msg)) { - $app->enqueueMessage($msg, 'warning'); - } + if (\in_array($input->get('task'), ['apply', 'save', 'save2new']) && (!isset($data['id']) || (int) $data['id'] == 0) && $data['alias'] == null) { + if ($app->get('unicodeslugs') == 1) { + $data['alias'] = OutputFilter::stringUrlUnicodeSlug($data['title']); + } else { + $data['alias'] = OutputFilter::stringURLSafe($data['title']); + } + $table = $this->getTable(); + if ($table->load(['alias' => $data['alias'], 'catid' => $data['catid']])) { + $msg = Text::_('COM_CONTENT_SAVE_WARNING'); + } + [$title, $alias] = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); + $data['alias'] = $alias; + if (isset($msg)) { + $app->enqueueMessage($msg, 'warning'); } } if (parent::save($data)) { // Check if featured is set and if not managed by workflow - if (isset($data['featured']) && !$this->bootComponent('com_content')->isFunctionalityUsed('core.featured', 'com_content.article')) { - if ( - !$this->featured( - $this->getState($this->getName() . '.id'), - $data['featured'], - $data['featured_up'] ?? null, - $data['featured_down'] ?? null - ) - ) { - return false; - } + if ( + isset($data['featured']) && !$this->bootComponent('com_content')->isFunctionalityUsed('core.featured', 'com_content.article') && !$this->featured( + $this->getState($this->getName() . '.id'), + $data['featured'], + $data['featured_up'] ?? null, + $data['featured_down'] ?? null + ) + ) { + return false; } $this->workflowAfterSave($data); @@ -815,6 +800,7 @@ public function featured($pks, $value = 0, $featuredUp = null, $featuredDown = n // Sanitize the ids. $pks = (array) $pks; $pks = ArrayHelper::toInteger($pks); + $value = (int) $value; $context = $this->option . '.' . $this->name; @@ -890,7 +876,7 @@ public function featured($pks, $value = 0, $featuredUp = null, $featuredDown = n $oldFeatured = $db->loadColumn(); // Update old featured articles - if (\count($oldFeatured)) { + if (\count($oldFeatured) > 0) { $query = $db->getQuery(true) ->update($db->quoteName('#__content_frontpage')) ->set( @@ -910,7 +896,7 @@ public function featured($pks, $value = 0, $featuredUp = null, $featuredDown = n $newFeatured = array_diff($pks, $oldFeatured); // Featuring. - if ($newFeatured) { + if ($newFeatured !== []) { $query = $db->getQuery(true) ->insert($db->quoteName('#__content_frontpage')) ->columns( @@ -937,8 +923,8 @@ public function featured($pks, $value = 0, $featuredUp = null, $featuredDown = n $db->execute(); } } - } catch (\Exception $e) { - $this->setError($e->getMessage()); + } catch (\Exception $exception) { + $this->setError($exception->getMessage()); return false; } diff --git a/administrator/components/com_content/src/Model/ArticlesModel.php b/administrator/components/com_content/src/Model/ArticlesModel.php index ac02ff4299142..77d3a44f844bb 100644 --- a/administrator/components/com_content/src/Model/ArticlesModel.php +++ b/administrator/components/com_content/src/Model/ArticlesModel.php @@ -12,6 +12,7 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; @@ -92,7 +93,7 @@ public function __construct($config = [], ?MVCFactoryInterface $factory = null) * @param array $data data * @param boolean $loadData load current data * - * @return \Joomla\CMS\Form\Form|null The Form object or null if the form can't be found + * @return Form|null The Form object or null if the form can't be found * * @since 3.2 */ @@ -361,18 +362,18 @@ protected function getListQuery() } // Case: Using both categories filter and by level filter - if (\count($categoryId)) { + if ($categoryId !== []) { $categoryId = ArrayHelper::toInteger($categoryId); $categoryTable = Table::getInstance('Category', '\\Joomla\\CMS\\Table\\'); $subCatItemsWhere = []; - foreach ($categoryId as $key => $filter_catid) { + foreach ($categoryId as $filter_catid) { $categoryTable->load($filter_catid); // Because values to $query->bind() are passed by reference, using $query->bindArray() here instead to prevent overwriting. $valuesToBind = [$categoryTable->lft, $categoryTable->rgt]; - if ($level) { + if ($level !== 0) { $valuesToBind[] = $level + $categoryTable->level - 1; } @@ -381,7 +382,7 @@ protected function getListQuery() $categoryWhere = $db->quoteName('c.lft') . ' >= ' . $bounded[0] . ' AND ' . $db->quoteName('c.rgt') . ' <= ' . $bounded[1]; - if ($level) { + if ($level !== 0) { $categoryWhere .= ' AND ' . $db->quoteName('c.level') . ' <= ' . $bounded[2]; } @@ -389,7 +390,7 @@ protected function getListQuery() } $query->where('(' . implode(' OR ', $subCatItemsWhere) . ')'); - } elseif ($level = (int) $level) { + } elseif ($level = $level !== 0) { // Case: Using only the by level filter $query->where($db->quoteName('c.level') . ' <= :level') ->bind(':level', $level, ParameterType::INTEGER); @@ -418,25 +419,25 @@ protected function getListQuery() $search = $this->getState('filter.search'); if (!empty($search)) { - if (stripos($search, 'id:') === 0) { - $search = (int) substr($search, 3); + if (stripos((string) $search, 'id:') === 0) { + $search = (int) substr((string) $search, 3); $query->where($db->quoteName('a.id') . ' = :search') ->bind(':search', $search, ParameterType::INTEGER); - } elseif (stripos($search, 'author:') === 0) { - $search = '%' . substr($search, 7) . '%'; + } elseif (stripos((string) $search, 'author:') === 0) { + $search = '%' . substr((string) $search, 7) . '%'; $query->where('(' . $db->quoteName('ua.name') . ' LIKE :search1 OR ' . $db->quoteName('ua.username') . ' LIKE :search2)') ->bind([':search1', ':search2'], $search); - } elseif (stripos($search, 'content:') === 0) { - $search = '%' . substr($search, 8) . '%'; + } elseif (stripos((string) $search, 'content:') === 0) { + $search = '%' . substr((string) $search, 8) . '%'; $query->where('(' . $db->quoteName('a.introtext') . ' LIKE :search1 OR ' . $db->quoteName('a.fulltext') . ' LIKE :search2)') ->bind([':search1', ':search2'], $search); - } elseif (stripos($search, 'checkedout:') === 0) { - $search = '%' . substr($search, 11) . '%'; + } elseif (stripos((string) $search, 'checkedout:') === 0) { + $search = '%' . substr((string) $search, 11) . '%'; $query->where('(' . $db->quoteName('uc.name') . ' LIKE :search1 OR ' . $db->quoteName('uc.username') . ' LIKE :search2)' . ' AND ' . $db->quoteName('a.checked_out') . ' IS NOT NULL') ->bind([':search1', ':search2'], $search); } else { - $search = '%' . str_replace(' ', '%', trim($search)) . '%'; + $search = '%' . str_replace(' ', '%', trim((string) $search)) . '%'; $query->where( '(' . $db->quoteName('a.title') . ' LIKE :search1 OR ' . $db->quoteName('a.alias') . ' LIKE :search2' . ' OR ' . $db->quoteName('a.note') . ' LIKE :search3)' @@ -477,7 +478,7 @@ protected function getListQuery() '(' . $subQuery . ') AS ' . $db->quoteName('tagmap'), $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id') ); - } elseif ($tag = (int) $tag) { + } elseif ($tag = (int) $tag !== 0) { $query->join( 'INNER', $db->quoteName('#__contentitem_tag_map', 'tagmap'), @@ -578,11 +579,11 @@ public function getTransitions() $where = []; - if (\count($stage_ids)) { + if ($stage_ids !== []) { $where[] = $db->quoteName('t.from_stage_id') . ' IN (' . implode(',', $query->bindArray($stage_ids)) . ')'; } - if (\count($workflow_ids)) { + if ($workflow_ids !== []) { $where[] = '(' . $db->quoteName('t.from_stage_id') . ' = -1 AND ' . $db->quoteName('t.workflow_id') . ' IN (' . implode(',', $query->bindArray($workflow_ids)) . '))'; } @@ -600,8 +601,8 @@ public function getTransitions() $this->cache[$store] = $transitions; } - } catch (\RuntimeException $e) { - $this->setError($e->getMessage()); + } catch (\RuntimeException $runtimeException) { + $this->setError($runtimeException->getMessage()); return false; } diff --git a/administrator/components/com_content/src/Model/FeatureModel.php b/administrator/components/com_content/src/Model/FeatureModel.php index a47894f1606cf..32d6f52595c34 100644 --- a/administrator/components/com_content/src/Model/FeatureModel.php +++ b/administrator/components/com_content/src/Model/FeatureModel.php @@ -10,6 +10,8 @@ namespace Joomla\Component\Content\Administrator\Model; +use Joomla\CMS\Table\Table; + // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects @@ -28,7 +30,7 @@ class FeatureModel extends ArticleModel * @param string $prefix A prefix for the table class name. Optional. * @param array $config Configuration array for model. Optional. * - * @return \Joomla\CMS\Table\Table A database object + * @return Table A database object * * @since 1.6 */ diff --git a/administrator/components/com_content/src/Service/HTML/Icon.php b/administrator/components/com_content/src/Service/HTML/Icon.php index fe1782260de47..61513d64849d3 100644 --- a/administrator/components/com_content/src/Service/HTML/Icon.php +++ b/administrator/components/com_content/src/Service/HTML/Icon.php @@ -64,9 +64,7 @@ public function create($category, $params, $attribs = [], $legacy = false) $attribs['class'] = 'btn btn-primary'; } - $button = HTMLHelper::_('link', Route::_($url), $text, $attribs); - - return $button; + return HTMLHelper::_('link', Route::_($url), $text, $attribs); } /** @@ -114,9 +112,8 @@ public function edit($article, $params, $attribs = [], $legacy = false) $text = LayoutHelper::render('joomla.content.icons.edit_lock', ['article' => $article, 'tooltip' => $tooltip, 'legacy' => $legacy]); $attribs['aria-describedby'] = 'editarticle-' . (int) $article->id; - $output = HTMLHelper::_('link', '#', $text, $attribs); - return $output; + return HTMLHelper::_('link', '#', $text, $attribs); } $contentUrl = RouteHelper::getArticleRoute($article->slug, $article->catid, $article->language); @@ -131,9 +128,8 @@ public function edit($article, $params, $attribs = [], $legacy = false) $text = LayoutHelper::render('joomla.content.icons.edit', ['article' => $article, 'tooltip' => $tooltip, 'legacy' => $legacy]); $attribs['aria-describedby'] = 'editarticle-' . (int) $article->id; - $output = HTMLHelper::_('link', Route::_($url), $text, $attribs); - return $output; + return HTMLHelper::_('link', Route::_($url), $text, $attribs); } /** diff --git a/administrator/components/com_content/src/Table/ArticleTable.php b/administrator/components/com_content/src/Table/ArticleTable.php index 8ae718974f259..3f656cc8bbf56 100644 --- a/administrator/components/com_content/src/Table/ArticleTable.php +++ b/administrator/components/com_content/src/Table/ArticleTable.php @@ -10,6 +10,8 @@ namespace Joomla\Component\Content\Administrator\Table; +use Joomla\CMS\Table\Content; + // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects @@ -19,6 +21,6 @@ * * @since 1.5 */ -class ArticleTable extends \Joomla\CMS\Table\Content +class ArticleTable extends Content { } diff --git a/administrator/components/com_content/src/View/Article/HtmlView.php b/administrator/components/com_content/src/View/Article/HtmlView.php index 83f31df49212d..78d617b00c8cb 100644 --- a/administrator/components/com_content/src/View/Article/HtmlView.php +++ b/administrator/components/com_content/src/View/Article/HtmlView.php @@ -12,6 +12,7 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Text; @@ -23,6 +24,7 @@ use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Content\Administrator\Model\ArticleModel; use Joomla\Component\Content\Site\Helper\RouteHelper; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -38,7 +40,7 @@ class HtmlView extends BaseHtmlView /** * The \JForm object * - * @var \Joomla\CMS\Form\Form + * @var Form */ protected $form; @@ -59,7 +61,7 @@ class HtmlView extends BaseHtmlView /** * The actions the user is authorised to perform * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $canDo; @@ -113,7 +115,7 @@ public function display($tpl = null) } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -163,7 +165,7 @@ protected function addToolbar() $user = $this->getCurrentUser(); $userId = $user->id; $isNew = ($this->item->id == 0); - $checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $userId); + $checkedOut = !\is_null($this->item->checked_out) && $this->item->checked_out != $userId; $toolbar = $this->getDocument()->getToolbar(); // Built the actions for new and existing records. @@ -273,7 +275,7 @@ protected function addModalToolbar() $user = $this->getCurrentUser(); $userId = $user->id; $isNew = ($this->item->id == 0); - $checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $userId); + $checkedOut = !\is_null($this->item->checked_out) && $this->item->checked_out != $userId; $toolbar = $this->getDocument()->getToolbar(); // Build the actions for new and existing records. diff --git a/administrator/components/com_content/src/View/Articles/HtmlView.php b/administrator/components/com_content/src/View/Articles/HtmlView.php index 0cee1695afe44..4659852b7124e 100644 --- a/administrator/components/com_content/src/View/Articles/HtmlView.php +++ b/administrator/components/com_content/src/View/Articles/HtmlView.php @@ -12,16 +12,19 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Toolbar\Button\DropdownButton; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Content\Administrator\Extension\ContentComponent; use Joomla\Component\Content\Administrator\Helper\ContentHelper; use Joomla\Component\Content\Administrator\Model\ArticlesModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -44,21 +47,21 @@ class HtmlView extends BaseHtmlView /** * The pagination object * - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination */ protected $pagination; /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $state; /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form */ public $filterForm; @@ -120,7 +123,7 @@ public function display($tpl = null) $this->vote = PluginHelper::isEnabled('content', 'vote'); $this->hits = ComponentHelper::getParams('com_content')->get('record_hits', 1) == 1; - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + if (\count($this->items) === 0 && $this->isEmptyState = $model->getIsEmptyState()) { $this->setLayout('emptystate'); } diff --git a/administrator/components/com_content/src/View/Featured/HtmlView.php b/administrator/components/com_content/src/View/Featured/HtmlView.php index 8cf0f4f49dda2..b8e8cc466b001 100644 --- a/administrator/components/com_content/src/View/Featured/HtmlView.php +++ b/administrator/components/com_content/src/View/Featured/HtmlView.php @@ -11,16 +11,19 @@ namespace Joomla\Component\Content\Administrator\View\Featured; use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Form\Form; use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Toolbar\Button\DropdownButton; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Content\Administrator\Extension\ContentComponent; use Joomla\Component\Content\Administrator\Helper\ContentHelper; use Joomla\Component\Content\Administrator\Model\FeaturedModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -33,6 +36,11 @@ */ class HtmlView extends BaseHtmlView { + /** + * @var bool + */ + public $vote; + public $hits; /** * An array of items * @@ -43,21 +51,21 @@ class HtmlView extends BaseHtmlView /** * The pagination object * - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination */ protected $pagination; /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $state; /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form */ public $filterForm; @@ -103,7 +111,7 @@ public function display($tpl = null) $this->vote = PluginHelper::isEnabled('content', 'vote'); $this->hits = ComponentHelper::getParams('com_content')->get('record_hits', 1); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + if (\count($this->items) === 0 && $this->isEmptyState = $model->getIsEmptyState()) { $this->setLayout('emptystate'); } @@ -114,7 +122,7 @@ public function display($tpl = null) } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -158,7 +166,7 @@ protected function addToolbar() $childBar = $dropdown->getChildToolbar(); - if (\count($this->transitions)) { + if (\count($this->transitions) !== 0) { $childBar->separatorButton('transition-headline', 'COM_CONTENT_RUN_TRANSITIONS') ->buttonClass('text-center py-2 h3'); diff --git a/administrator/components/com_content/tmpl/articles/default.php b/administrator/components/com_content/tmpl/articles/default.php index 862896a10057c..30301e027adde 100644 --- a/administrator/components/com_content/tmpl/articles/default.php +++ b/administrator/components/com_content/tmpl/articles/default.php @@ -39,11 +39,11 @@ $listDirn = $this->escape($this->state->get('list.direction')); $saveOrder = $listOrder == 'a.ordering'; -if (strpos($listOrder, 'publish_up') !== false) { +if (str_contains((string) $listOrder, 'publish_up')) { $orderingColumn = 'publish_up'; -} elseif (strpos($listOrder, 'publish_down') !== false) { +} elseif (str_contains((string) $listOrder, 'publish_down')) { $orderingColumn = 'publish_down'; -} elseif (strpos($listOrder, 'modified') !== false) { +} elseif (str_contains((string) $listOrder, 'modified')) { $orderingColumn = 'modified'; } else { $orderingColumn = 'created'; @@ -152,7 +152,7 @@ class="js-draggable" data-url="" data-direction="" data-nested="true" class="js-draggable" data-url="" data-direction="" data-nested="true"> items as $i => $item) : $item->max_ordering = 0; @@ -268,10 +268,8 @@ $CurrentCatUrl = Route::_('index.php?option=com_categories&task=category.edit&id=' . $item->catid . '&extension=com_content'); $EditCatTxt = Text::_('COM_CONTENT_EDIT_CATEGORY'); echo Text::_('JCATEGORY') . ': '; - if ($item->category_level != '1') : - if ($item->parent_category_level != '1') : - echo ' » '; - endif; + if ($item->category_level != '1' && $item->parent_category_level != '1') : + echo ' » '; endif; if ($this->getLanguage()->isRtl()) { if ($canEditCat || $canEditOwnCat) : diff --git a/administrator/components/com_content/tmpl/articles/emptystate.php b/administrator/components/com_content/tmpl/articles/emptystate.php index 90cf4415edadb..d588f6e3fe247 100644 --- a/administrator/components/com_content/tmpl/articles/emptystate.php +++ b/administrator/components/com_content/tmpl/articles/emptystate.php @@ -1,5 +1,7 @@ 'COM_CONTENT', 'formURL' => 'index.php?option=com_content&view=articles', diff --git a/administrator/components/com_content/tmpl/articles/modal.php b/administrator/components/com_content/tmpl/articles/modal.php index 1d498b8a16b2a..dd79505539abb 100644 --- a/administrator/components/com_content/tmpl/articles/modal.php +++ b/administrator/components/com_content/tmpl/articles/modal.php @@ -112,7 +112,7 @@ } $link = RouteHelper::getArticleRoute($item->id, $item->catid, $item->language); - $itemHtml = '' . $item->title . ''; + $itemHtml = '' . $item->title . ''; ?> diff --git a/administrator/components/com_content/tmpl/featured/default.php b/administrator/components/com_content/tmpl/featured/default.php index df58b6aa66b58..dffda4b1a0711 100644 --- a/administrator/components/com_content/tmpl/featured/default.php +++ b/administrator/components/com_content/tmpl/featured/default.php @@ -39,11 +39,11 @@ $listDirn = $this->escape($this->state->get('list.direction')); $saveOrder = $listOrder == 'fp.ordering'; -if (strpos($listOrder, 'publish_up') !== false) { +if (str_contains((string) $listOrder, 'publish_up')) { $orderingColumn = 'publish_up'; -} elseif (strpos($listOrder, 'publish_down') !== false) { +} elseif (str_contains((string) $listOrder, 'publish_down')) { $orderingColumn = 'publish_down'; -} elseif (strpos($listOrder, 'modified') !== false) { +} elseif (str_contains((string) $listOrder, 'modified')) { $orderingColumn = 'modified'; } else { $orderingColumn = 'created'; @@ -152,7 +152,7 @@ class="js-draggable" data-url="" data-direction="" class="js-draggable" data-url="" data-direction=""> items); ?> items as $i => $item) : @@ -262,10 +262,8 @@ $CurrentCatUrl = Route::_('index.php?option=com_categories&task=category.edit&id=' . $item->catid . '&extension=com_content'); $EditCatTxt = Text::_('COM_CONTENT_EDIT_CATEGORY'); echo Text::_('JCATEGORY') . ': '; - if ($item->category_level != '1') : - if ($item->parent_category_level != '1') : - echo ' » '; - endif; + if ($item->category_level != '1' && $item->parent_category_level != '1') : + echo ' » '; endif; if ($this->getLanguage()->isRtl()) { if ($canEditCat || $canEditOwnCat) : diff --git a/administrator/components/com_content/tmpl/featured/emptystate.php b/administrator/components/com_content/tmpl/featured/emptystate.php index 3f20dbd6f98e9..2ab0c24b29d5a 100644 --- a/administrator/components/com_content/tmpl/featured/emptystate.php +++ b/administrator/components/com_content/tmpl/featured/emptystate.php @@ -1,5 +1,7 @@ 'COM_CONTENT', 'formURL' => 'index.php?option=com_content&view=featured', diff --git a/administrator/components/com_contenthistory/src/Controller/HistoryController.php b/administrator/components/com_contenthistory/src/Controller/HistoryController.php index 317fc8e17849c..cd2c344e5302f 100644 --- a/administrator/components/com_contenthistory/src/Controller/HistoryController.php +++ b/administrator/components/com_contenthistory/src/Controller/HistoryController.php @@ -12,6 +12,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Router\Route; use Joomla\CMS\Session\Session; @@ -33,7 +34,7 @@ class HistoryController extends AdminController * @param string $prefix The prefix for the model * @param array $config An additional array of parameters * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model + * @return BaseDatabaseModel The model * * @since 3.2 */ @@ -59,7 +60,7 @@ public function keep() // Remove zero values resulting from input filter $cid = array_filter($cid); - if (empty($cid)) { + if ($cid === []) { $this->app->enqueueMessage(Text::_('COM_CONTENTHISTORY_NO_ITEM_SELECTED'), 'warning'); } else { // Get the model. diff --git a/administrator/components/com_contenthistory/src/Controller/PreviewController.php b/administrator/components/com_contenthistory/src/Controller/PreviewController.php index d966244884656..f8c9f85b062ac 100644 --- a/administrator/components/com_contenthistory/src/Controller/PreviewController.php +++ b/administrator/components/com_contenthistory/src/Controller/PreviewController.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Contenthistory\Administrator\Controller; use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -30,7 +31,7 @@ class PreviewController extends BaseController * @param string $prefix The prefix for the model * @param array $config An additional array of parameters * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model + * @return BaseDatabaseModel The model * * @since 3.2 */ diff --git a/administrator/components/com_contenthistory/src/Helper/ContenthistoryHelper.php b/administrator/components/com_contenthistory/src/Helper/ContenthistoryHelper.php index 6dcab10af041b..8d01819420760 100644 --- a/administrator/components/com_contenthistory/src/Helper/ContenthistoryHelper.php +++ b/administrator/components/com_contenthistory/src/Helper/ContenthistoryHelper.php @@ -76,7 +76,7 @@ public static function decodeFields($jsonString) if (\is_object($object)) { foreach ($object as $name => $value) { - if (!\is_null($value) && $subObject = json_decode($value)) { + if (!\is_null($value) && $subObject = json_decode((string) $value)) { $object->$name = $subObject; } } @@ -107,35 +107,31 @@ public static function getFormValues($object, ContentType $typesTable) $expandedObjectArray = static::createObjectArray($object); static::loadLanguageFiles($typesTable->type_alias); - if ($formFile = static::getFormFile($typesTable)) { - if ($xml = simplexml_load_file($formFile)) { - // Now we need to get all of the labels from the form - $fieldArray = $xml->xpath('//field'); - $fieldArray = array_merge($fieldArray, $xml->xpath('//fields')); - - foreach ($fieldArray as $field) { - if ($label = (string) $field->attributes()->label) { - $labels[(string) $field->attributes()->name] = Text::_($label); - } + if (($formFile = static::getFormFile($typesTable)) && $xml = simplexml_load_file($formFile)) { + // Now we need to get all of the labels from the form + $fieldArray = $xml->xpath('//field'); + $fieldArray = array_merge($fieldArray, $xml->xpath('//fields')); + foreach ($fieldArray as $field) { + $label = (string) $field->attributes()->label; + if ($label !== '' && $label !== '0') { + $labels[(string) $field->attributes()->name] = Text::_($label); } + } + // Get values for any list type fields + $listFieldArray = $xml->xpath('//field[@type="list" or @type="radio"]'); + foreach ($listFieldArray as $field) { + $name = (string) $field->attributes()->name; - // Get values for any list type fields - $listFieldArray = $xml->xpath('//field[@type="list" or @type="radio"]'); - - foreach ($listFieldArray as $field) { - $name = (string) $field->attributes()->name; - - if (isset($expandedObjectArray[$name])) { - $optionFieldArray = $field->xpath('option[@value="' . $expandedObjectArray[$name] . '"]'); - - $valueText = null; + if (isset($expandedObjectArray[$name])) { + $optionFieldArray = $field->xpath('option[@value="' . $expandedObjectArray[$name] . '"]'); - if (\is_array($optionFieldArray) && \count($optionFieldArray)) { - $valueText = trim((string) $optionFieldArray[0]); - } + $valueText = null; - $values[(string) $field->attributes()->name] = Text::_($valueText); + if (\is_array($optionFieldArray) && \count($optionFieldArray)) { + $valueText = trim((string) $optionFieldArray[0]); } + + $values[(string) $field->attributes()->name] = Text::_($valueText); } } } @@ -160,19 +156,16 @@ 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) && 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 = is_file($path . $file) ? $path . $file : false; + return JPATH_ROOT . '/' . $options->formFile; } + $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'); - return $result; + return is_file($path . $file) ? $path . $file : false; } /** @@ -201,7 +194,7 @@ public static function getLookupValue($lookup, $value) try { $result = $db->loadResult(); - } catch (\Exception $e) { + } catch (\Exception) { // Ignore any errors and just return false return false; } @@ -222,11 +215,9 @@ public static function getLookupValue($lookup, $value) */ public static function hideFields($object, ContentType $typeTable) { - if ($options = json_decode($typeTable->content_history_options)) { - if (isset($options->hideFields) && \is_array($options->hideFields)) { - foreach ($options->hideFields as $field) { - unset($object->$field); - } + if (($options = json_decode($typeTable->content_history_options)) && (isset($options->hideFields) && \is_array($options->hideFields))) { + foreach ($options->hideFields as $field) { + unset($object->$field); } } @@ -246,16 +237,17 @@ public static function loadLanguageFiles($typeAlias) { $aliasArray = explode('.', $typeAlias); - if (\is_array($aliasArray) && \count($aliasArray) == 2) { - $component = ($aliasArray[1] == 'category') ? 'com_categories' : $aliasArray[0]; + if (\count($aliasArray) == 2) { + $component = ($aliasArray[1] === 'category') ? 'com_categories' : $aliasArray[0]; $lang = Factory::getLanguage(); /** * Loading language file from the administrator/language directory then * loading language file from the administrator/components/extension/language directory */ - $lang->load($component, JPATH_ADMINISTRATOR) - || $lang->load($component, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + if (!$lang->load($component, JPATH_ADMINISTRATOR)) { + $lang->load($component, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + } // Force loading of backend global language file $lang->load('joomla', Path::clean(JPATH_ADMINISTRATOR)); @@ -327,9 +319,8 @@ public static function prepareData(ContentHistory $table) $formValues = static::getFormValues($object, $typesTable); $object = static::mergeLabels($object, $formValues); $object = static::hideFields($object, $typesTable); - $object = static::processLookupFields($object, $typesTable); - return $object; + return static::processLookupFields($object, $typesTable); } /** @@ -345,15 +336,13 @@ public static function prepareData(ContentHistory $table) */ public static function processLookupFields($object, ContentType $typesTable) { - if ($options = json_decode($typesTable->content_history_options)) { - if (isset($options->displayLookup) && \is_array($options->displayLookup)) { - foreach ($options->displayLookup as $lookup) { - $sourceColumn = $lookup->sourceColumn ?? false; - $sourceValue = $object->$sourceColumn->value ?? false; - - if ($sourceColumn && $sourceValue && ($lookupValue = static::getLookupValue($lookup, $sourceValue))) { - $object->$sourceColumn->value = $lookupValue; - } + if (($options = json_decode($typesTable->content_history_options)) && (isset($options->displayLookup) && \is_array($options->displayLookup))) { + foreach ($options->displayLookup as $lookup) { + $sourceColumn = $lookup->sourceColumn ?? false; + $sourceValue = $object->$sourceColumn->value ?? false; + + if ($sourceColumn && $sourceValue && ($lookupValue = static::getLookupValue($lookup, $sourceValue))) { + $object->$sourceColumn->value = $lookupValue; } } } diff --git a/administrator/components/com_contenthistory/src/Model/HistoryModel.php b/administrator/components/com_contenthistory/src/Model/HistoryModel.php index 73470f5645422..7c0dab751ad91 100644 --- a/administrator/components/com_contenthistory/src/Model/HistoryModel.php +++ b/administrator/components/com_contenthistory/src/Model/HistoryModel.php @@ -96,9 +96,8 @@ protected function canEdit($record) $typeAlias = implode('.', $typeAlias); $contentTypeTable->load(['type_alias' => $typeAlias]); $typeEditables = (array) Factory::getApplication()->getUserState(str_replace('.', '.edit.', $contentTypeTable->type_alias) . '.id'); - $result = \in_array((int) $id, $typeEditables); - return $result; + return \in_array((int) $id, $typeEditables); } /** @@ -152,7 +151,7 @@ public function delete(&$pks) if ($error) { try { Log::add($error, Log::WARNING, 'jerror'); - } catch (\RuntimeException $exception) { + } catch (\RuntimeException) { Factory::getApplication()->enqueueMessage($error, 'warning'); } @@ -161,7 +160,7 @@ public function delete(&$pks) try { Log::add(Text::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), Log::WARNING, 'jerror'); - } catch (\RuntimeException $exception) { + } catch (\RuntimeException) { Factory::getApplication()->enqueueMessage(Text::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), 'warning'); } @@ -259,7 +258,7 @@ public function keep(&$pks) if ($error) { try { Log::add($error, Log::WARNING, 'jerror'); - } catch (\RuntimeException $exception) { + } catch (\RuntimeException) { Factory::getApplication()->enqueueMessage($error, 'warning'); } @@ -268,7 +267,7 @@ public function keep(&$pks) try { Log::add(Text::_('COM_CONTENTHISTORY_ERROR_KEEP_NOT_PERMITTED'), Log::WARNING, 'jerror'); - } catch (\RuntimeException $exception) { + } catch (\RuntimeException) { Factory::getApplication()->enqueueMessage(Text::_('COM_CONTENTHISTORY_ERROR_KEEP_NOT_PERMITTED'), 'warning'); } @@ -381,6 +380,7 @@ protected function getSha1Hash() Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/' . $typeAlias[0] . '/tables'); $typeTable = $this->getTable('ContentType'); $typeTable->load(['type_alias' => $typeAlias[0] . '.' . $typeAlias[1]]); + $contentTable = $typeTable->getContentTable(); if ($contentTable && $contentTable->load($typeAlias[2])) { diff --git a/administrator/components/com_contenthistory/src/View/Compare/HtmlView.php b/administrator/components/com_contenthistory/src/View/Compare/HtmlView.php index 4874bdfeed373..0b8afa517b59a 100644 --- a/administrator/components/com_contenthistory/src/View/Compare/HtmlView.php +++ b/administrator/components/com_contenthistory/src/View/Compare/HtmlView.php @@ -13,6 +13,7 @@ use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\Component\Contenthistory\Administrator\Model\CompareModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -35,7 +36,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $state; @@ -57,7 +58,7 @@ public function display($tpl = null) $this->items = $model->getItems(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_contenthistory/src/View/History/HtmlView.php b/administrator/components/com_contenthistory/src/View/History/HtmlView.php index 279adb37c1b0c..1eeffc024f3eb 100644 --- a/administrator/components/com_contenthistory/src/View/History/HtmlView.php +++ b/administrator/components/com_contenthistory/src/View/History/HtmlView.php @@ -20,6 +20,7 @@ use Joomla\CMS\Toolbar\Toolbar; use Joomla\CMS\Toolbar\ToolbarFactoryInterface; use Joomla\Component\Contenthistory\Administrator\Model\HistoryModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -49,7 +50,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $state; @@ -79,7 +80,7 @@ public function display($tpl = null) $this->pagination = $model->getPagination(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_contenthistory/src/View/Preview/HtmlView.php b/administrator/components/com_contenthistory/src/View/Preview/HtmlView.php index 59f7bbaf25ae4..bc957e6c3d964 100644 --- a/administrator/components/com_contenthistory/src/View/Preview/HtmlView.php +++ b/administrator/components/com_contenthistory/src/View/Preview/HtmlView.php @@ -14,6 +14,7 @@ use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\Component\Contenthistory\Administrator\Model\PreviewModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -36,7 +37,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $state; @@ -64,7 +65,7 @@ public function display($tpl = null) } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_contenthistory/tmpl/preview/preview.php b/administrator/components/com_contenthistory/tmpl/preview/preview.php index fca9e66163ee0..a492bbf2b18b8 100644 --- a/administrator/components/com_contenthistory/tmpl/preview/preview.php +++ b/administrator/components/com_contenthistory/tmpl/preview/preview.php @@ -39,14 +39,14 @@ - item->data as $name => $value) : ?> + item->data as $value) : ?> value)) : ?> label; ?> - value as $subName => $subValue) : ?> + value as $subValue) : ?> value)) : ?> value = (\is_object($subValue->value) || \is_array($subValue->value)) ? \json_encode($subValue->value, \JSON_UNESCAPED_UNICODE) : $subValue->value; ?> diff --git a/administrator/components/com_cpanel/src/Controller/DisplayController.php b/administrator/components/com_cpanel/src/Controller/DisplayController.php index b9ede3f88e7a4..a088b9b71d1d3 100644 --- a/administrator/components/com_cpanel/src/Controller/DisplayController.php +++ b/administrator/components/com_cpanel/src/Controller/DisplayController.php @@ -10,6 +10,7 @@ namespace Joomla\Component\Cpanel\Administrator\Controller; +use Joomla\CMS\Application\ApplicationHelper; use Joomla\CMS\MVC\Controller\BaseController; use Joomla\CMS\Router\Route; @@ -75,12 +76,12 @@ public function addModule() $appendLink .= '&function=' . $function; } - if (substr($position, 0, 6) != 'cpanel') { + if (!str_starts_with((string) $position, 'cpanel')) { $position = 'cpanel'; } // Administrator - $clientId = (\Joomla\CMS\Application\ApplicationHelper::getClientInfo('administrator', true))->id; + $clientId = (ApplicationHelper::getClientInfo('administrator', true))->id; $this->app->setUserState('com_modules.modules.' . $clientId . '.filter.position', $position); $this->app->setUserState('com_modules.modules.client_id', (string) $clientId); diff --git a/administrator/components/com_cpanel/src/View/Cpanel/HtmlView.php b/administrator/components/com_cpanel/src/View/Cpanel/HtmlView.php index 1d5a34a7e5a0c..f71dee1c499f6 100644 --- a/administrator/components/com_cpanel/src/View/Cpanel/HtmlView.php +++ b/administrator/components/com_cpanel/src/View/Cpanel/HtmlView.php @@ -33,21 +33,21 @@ class HtmlView extends BaseHtmlView * * @var array */ - protected $modules = null; + protected $modules; /** * Array of cpanel modules * * @var array */ - protected $quickicons = null; + protected $quickicons; /** * Moduleposition to load * * @var string */ - protected $position = null; + protected $position; /** * Execute and display a template script. @@ -69,14 +69,15 @@ public function display($tpl = null) $parts = explode('.', $dashboard); $component = $parts[0]; - if (strpos($component, 'com_') === false) { + if (!str_contains($component, 'com_')) { $component = 'com_' . $component; } // Need to load the language file $lang = $this->getLanguage(); - $lang->load($component, JPATH_BASE) - || $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component); + if (!$lang->load($component, JPATH_BASE)) { + $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component); + } $lang->load($component); // Lookup dashboard attributes from component manifest file @@ -101,7 +102,7 @@ public function display($tpl = null) // Try building a title $prefix = strtoupper($component) . '_DASHBOARD'; - $sectionkey = !empty($parts[1]) ? '_' . strtoupper($parts[1]) : ''; + $sectionkey = empty($parts[1]) ? '' : '_' . strtoupper($parts[1]); $key = $prefix . $sectionkey . '_TITLE'; $keyIcon = $prefix . $sectionkey . '_ICON'; diff --git a/administrator/components/com_fields/src/Controller/DisplayController.php b/administrator/components/com_fields/src/Controller/DisplayController.php index d35845b3d6c81..ea5da6a53d648 100644 --- a/administrator/components/com_fields/src/Controller/DisplayController.php +++ b/administrator/components/com_fields/src/Controller/DisplayController.php @@ -57,7 +57,7 @@ public function display($cachable = false, $urlparams = false) // Check for edit form. if ($vName == 'field' && !$this->checkEditId('com_fields.edit.field', $id)) { // Somehow the person just went to the form - we don't allow that. - if (!\count($this->app->getMessageQueue())) { + if (\count($this->app->getMessageQueue()) === 0) { $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error'); } diff --git a/administrator/components/com_fields/src/Controller/FieldController.php b/administrator/components/com_fields/src/Controller/FieldController.php index 24682c186ce79..0f70a25c5060a 100644 --- a/administrator/components/com_fields/src/Controller/FieldController.php +++ b/administrator/components/com_fields/src/Controller/FieldController.php @@ -95,7 +95,7 @@ protected function allowAdd($data = []) */ protected function allowEdit($data = [], $key = 'id') { - $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + $recordId = (int) isset($data[$key]) !== 0 ? $data[$key] : 0; $user = $this->app->getIdentity(); // Zero record (id:0), return component edit permission by calling parent controller method diff --git a/administrator/components/com_fields/src/Controller/FieldsController.php b/administrator/components/com_fields/src/Controller/FieldsController.php index 9c2120c45f95e..0206a9cf8f470 100644 --- a/administrator/components/com_fields/src/Controller/FieldsController.php +++ b/administrator/components/com_fields/src/Controller/FieldsController.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Fields\Administrator\Controller; use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -39,7 +40,7 @@ class FieldsController extends AdminController * @param string $prefix The prefix for the PHP class name. * @param array $config Array of configuration parameters. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel + * @return BaseDatabaseModel * * @since 3.7.0 */ diff --git a/administrator/components/com_fields/src/Controller/GroupController.php b/administrator/components/com_fields/src/Controller/GroupController.php index 6572227d11fe3..6c4256d606ab2 100644 --- a/administrator/components/com_fields/src/Controller/GroupController.php +++ b/administrator/components/com_fields/src/Controller/GroupController.php @@ -117,7 +117,7 @@ protected function allowAdd($data = []) */ protected function allowEdit($data = [], $key = 'parent_id') { - $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + $recordId = (int) isset($data[$key]) !== 0 ? $data[$key] : 0; $user = $this->app->getIdentity(); // Zero record (parent_id:0), return component edit permission by calling parent controller method @@ -180,9 +180,8 @@ protected function postSaveHook(BaseDatabaseModel $model, $validData = []) protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') { $append = parent::getRedirectToItemAppend($recordId); - $append .= '&context=' . $this->input->get('context'); - return $append; + return $append . ('&context=' . $this->input->get('context')); } /** @@ -195,8 +194,7 @@ protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') protected function getRedirectToListAppend() { $append = parent::getRedirectToListAppend(); - $append .= '&context=' . $this->input->get('context'); - return $append; + return $append . ('&context=' . $this->input->get('context')); } } diff --git a/administrator/components/com_fields/src/Controller/GroupsController.php b/administrator/components/com_fields/src/Controller/GroupsController.php index 252caf302ddb9..28954bfc2b94b 100644 --- a/administrator/components/com_fields/src/Controller/GroupsController.php +++ b/administrator/components/com_fields/src/Controller/GroupsController.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Fields\Administrator\Controller; use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -39,7 +40,7 @@ class GroupsController extends AdminController * @param string $prefix The prefix for the PHP class name. * @param array $config Array of configuration parameters. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel + * @return BaseDatabaseModel * * @since 3.7.0 */ diff --git a/administrator/components/com_fields/src/Field/ComponentsFieldgroupField.php b/administrator/components/com_fields/src/Field/ComponentsFieldgroupField.php index 0a7f763baf9fc..9a09f68b68c88 100644 --- a/administrator/components/com_fields/src/Field/ComponentsFieldgroupField.php +++ b/administrator/components/com_fields/src/Field/ComponentsFieldgroupField.php @@ -58,7 +58,7 @@ protected function getOptions() $options = []; - if (\count($items)) { + if (\count($items) > 0) { $lang = Factory::getLanguage(); $components = []; @@ -73,8 +73,9 @@ protected function getOptions() if (!empty($availableActions)) { // Load language $source = JPATH_ADMINISTRATOR . '/components/' . $item->value; - $lang->load($item->value . 'sys', JPATH_ADMINISTRATOR) - || $lang->load($item->value . 'sys', $source); + if (!$lang->load($item->value . 'sys', JPATH_ADMINISTRATOR)) { + $lang->load($item->value . 'sys', $source); + } // Translate component name $item->text = Text::_($item->text); @@ -83,7 +84,7 @@ protected function getOptions() } } - if (empty($components)) { + if ($components === []) { return []; } diff --git a/administrator/components/com_fields/src/Field/ComponentsFieldsField.php b/administrator/components/com_fields/src/Field/ComponentsFieldsField.php index fecd3715fd762..744ee45c0eaf2 100644 --- a/administrator/components/com_fields/src/Field/ComponentsFieldsField.php +++ b/administrator/components/com_fields/src/Field/ComponentsFieldsField.php @@ -58,7 +58,7 @@ protected function getOptions() $options = []; - if (\count($items)) { + if (\count($items) > 0) { $lang = Factory::getLanguage(); $components = []; @@ -73,8 +73,9 @@ protected function getOptions() if (!empty($availableActions)) { // Load language $source = JPATH_ADMINISTRATOR . '/components/' . $item->value; - $lang->load($item->value . 'sys', JPATH_ADMINISTRATOR) - || $lang->load($item->value . 'sys', $source); + if (!$lang->load($item->value . 'sys', JPATH_ADMINISTRATOR)) { + $lang->load($item->value . 'sys', $source); + } // Translate component name $item->text = Text::_($item->text); @@ -83,7 +84,7 @@ protected function getOptions() } } - if (empty($components)) { + if ($components === []) { return []; } diff --git a/administrator/components/com_fields/src/Field/FieldLayoutField.php b/administrator/components/com_fields/src/Field/FieldLayoutField.php index 95216b097eadb..c7a1795f36892 100644 --- a/administrator/components/com_fields/src/Field/FieldLayoutField.php +++ b/administrator/components/com_fields/src/Field/FieldLayoutField.php @@ -45,10 +45,10 @@ class FieldLayoutField extends FormField */ protected function getInput() { - $extension = explode('.', $this->form->getValue('context')); + $extension = explode('.', (string) $this->form->getValue('context')); $extension = $extension[0]; - if ($extension) { + if ($extension !== '' && $extension !== '0') { // Get the database object and a new query object. $db = $this->getDatabase(); $query = $db->getQuery(true); @@ -86,7 +86,7 @@ protected function getInput() foreach ($component_layouts as $i => $file) { // Add an option to the component group - $value = basename($file, '.php'); + $value = basename((string) $file, '.php'); $component_layouts[$i] = $value; if ($value === 'render') { @@ -115,7 +115,7 @@ protected function getInput() } foreach ($files as $i => $file) { - $value = basename($file, '.php'); + $value = basename((string) $file, '.php'); // Remove the default "render.php" or layout files that exist in the component folder if ($value === 'render' || \in_array($value, $component_layouts)) { @@ -123,7 +123,7 @@ protected function getInput() } } - if (\count($files)) { + if ($files !== []) { // Create the group for the template $groups[$template->name] = []; $groups[$template->name]['id'] = $this->id . '_' . $template->element; @@ -132,7 +132,7 @@ protected function getInput() foreach ($files as $file) { // Add an option to the template group - $value = basename($file, '.php'); + $value = basename((string) $file, '.php'); $groups[$template->name]['items'][] = HTMLHelper::_('select.option', $value, $value); } } @@ -141,7 +141,7 @@ protected function getInput() // Compute attributes for the grouped list $attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; - $attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : ''; + $attr .= $this->element['class'] ? ' class="' . $this->element['class'] . '"' : ''; // Prepare HTML code $html = []; @@ -157,7 +157,7 @@ protected function getInput() ['id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected] ); - return implode($html); + return implode('', $html); } return ''; diff --git a/administrator/components/com_fields/src/Field/FieldcontextsField.php b/administrator/components/com_fields/src/Field/FieldcontextsField.php index 4d049efc6a83e..892652b4fe313 100644 --- a/administrator/components/com_fields/src/Field/FieldcontextsField.php +++ b/administrator/components/com_fields/src/Field/FieldcontextsField.php @@ -54,7 +54,7 @@ protected function getInput() */ protected function getOptions() { - $parts = explode('.', $this->value); + $parts = explode('.', (string) $this->value); $component = Factory::getApplication()->bootComponent($parts[0]); diff --git a/administrator/components/com_fields/src/Field/SubfieldsField.php b/administrator/components/com_fields/src/Field/SubfieldsField.php index c8dc4cfeba751..66e0ddb20032e 100644 --- a/administrator/components/com_fields/src/Field/SubfieldsField.php +++ b/administrator/components/com_fields/src/Field/SubfieldsField.php @@ -85,9 +85,7 @@ protected function getOptions() // Sorting the fields based on the text which is displayed usort( $options, - function ($a, $b) { - return strcmp($a->text, $b->text); - } + fn ($a, $b) => strcmp($a->text, $b->text) ); if (\count($options) == 0) { diff --git a/administrator/components/com_fields/src/Field/TypeField.php b/administrator/components/com_fields/src/Field/TypeField.php index 4514da0b584a8..cf7eebd0c71a7 100644 --- a/administrator/components/com_fields/src/Field/TypeField.php +++ b/administrator/components/com_fields/src/Field/TypeField.php @@ -73,9 +73,7 @@ protected function getOptions() // Sorting the fields based on the text which is displayed usort( $options, - function ($a, $b) { - return strcmp($a->text, $b->text); - } + fn ($a, $b) => strcmp($a->text, $b->text) ); // Load scripts diff --git a/administrator/components/com_fields/src/Helper/FieldsHelper.php b/administrator/components/com_fields/src/Helper/FieldsHelper.php index 96b05e66eb986..fdd9137cee54d 100644 --- a/administrator/components/com_fields/src/Helper/FieldsHelper.php +++ b/administrator/components/com_fields/src/Helper/FieldsHelper.php @@ -41,12 +41,12 @@ class FieldsHelper /** * @var FieldsModel */ - private static $fieldsCache = null; + private static $fieldsCache; /** * @var FieldModel */ - private static $fieldCache = null; + private static $fieldCache; /** * Extracts the component and section from the context string which has to @@ -175,9 +175,7 @@ public static function getFields( PluginHelper::importPlugin('fields', null, true, $dispatcher); $fieldIds = array_map( - function ($f) { - return $f->id; - }, + fn ($f) => $f->id, $fields ); @@ -226,10 +224,8 @@ function ($f) { ]))->getArgument('result', []); if (\is_array($value)) { - $value = array_filter($value, function ($v) { - return $v !== '' && $v !== null; - }); - $value = $value ? implode(' ', $value) : ''; + $value = array_filter($value, fn ($v) => $v !== '' && $v !== null); + $value = $value !== [] ? implode(' ', $value) : ''; } /* @@ -288,7 +284,7 @@ public static function render($context, $layoutFile, $displayData) if ($value == '') { // Trying to render the layout on Fields itself - $value = LayoutHelper::render($layoutFile, $displayData, null, ['component' => 'com_fields','client' => 0]); + return LayoutHelper::render($layoutFile, $displayData, null, ['component' => 'com_fields','client' => 0]); } return $value; @@ -333,7 +329,7 @@ public static function prepareForm($context, Form $form, $data) ? (int) reset($assignedCatids) : (int) $assignedCatids; - if (!$assignedCatids && $formField = $form->getField('catid')) { + if ($assignedCatids === 0 && $formField = $form->getField('catid')) { $assignedCatids = $formField->getAttribute('default', null); if (!$assignedCatids) { @@ -586,7 +582,7 @@ public static function getAssignedCategoriesIds($fieldId) { $fieldId = (int) $fieldId; - if (!$fieldId) { + if ($fieldId === 0) { return []; } @@ -615,7 +611,7 @@ public static function getAssignedCategoriesTitles($fieldId) { $fieldId = (int) $fieldId; - if (!$fieldId) { + if ($fieldId === 0) { return []; } @@ -652,8 +648,8 @@ public static function getFieldsPluginId() try { $result = (int) $db->loadResult(); - } catch (\RuntimeException $e) { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + } catch (\RuntimeException $runtimeException) { + Factory::getApplication()->enqueueMessage($runtimeException->getMessage(), 'error'); $result = 0; } diff --git a/administrator/components/com_fields/src/Model/FieldModel.php b/administrator/components/com_fields/src/Model/FieldModel.php index 1b8031d1042b7..761b5284a9b5c 100644 --- a/administrator/components/com_fields/src/Model/FieldModel.php +++ b/administrator/components/com_fields/src/Model/FieldModel.php @@ -10,6 +10,7 @@ namespace Joomla\Component\Fields\Administrator\Model; +use Joomla\CMS\Categories\CategoryInterface; use Joomla\CMS\Categories\CategoryServiceInterface; use Joomla\CMS\Categories\SectionNotFoundException; use Joomla\CMS\Component\ComponentHelper; @@ -49,7 +50,7 @@ class FieldModel extends AdminModel * * @since 3.7.0 */ - public $typeAlias = null; + public $typeAlias; /** * @var string @@ -144,14 +145,12 @@ public function save($data) $origTable->load($input->getInt('id')); if ($data['title'] == $origTable->title) { - list($title, $name) = $this->generateNewTitle($data['group_id'], $data['name'], $data['title']); + [$title, $name] = $this->generateNewTitle($data['group_id'], $data['name'], $data['title']); $data['title'] = $title; $data['label'] = $title; $data['name'] = $name; - } else { - if ($data['name'] == $origTable->name) { - $data['name'] = ''; - } + } elseif ($data['name'] == $origTable->name) { + $data['name'] = ''; } $data['state'] = 0; @@ -245,7 +244,7 @@ public function save($data) ->bind(':fieldid', $fieldId, ParameterType::INTEGER); // If new values are set, delete only old values. Otherwise delete all values. - if ($names) { + if ($names !== []) { $query->whereNotIn($db->quoteName('value'), $names, ParameterType::STRING); } @@ -295,7 +294,7 @@ private function checkDefaultValue($data) // Create the fields object $obj = (object) $data; $obj->params = new Registry($obj->params); - $obj->fieldparams = new Registry(!empty($obj->fieldparams) ? $obj->fieldparams : []); + $obj->fieldparams = new Registry(empty($obj->fieldparams) ? [] : $obj->fieldparams); // Prepare the dom $dom = new \DOMDocument(); @@ -329,8 +328,8 @@ private function checkDefaultValue($data) if ($rule instanceof DatabaseAwareInterface) { try { $rule->setDatabase($this->getDatabase()); - } catch (DatabaseNotFoundException $e) { - @trigger_error(\sprintf('Database must be set, this will not be caught anymore in 5.0.'), E_USER_DEPRECATED); + } catch (DatabaseNotFoundException) { + @trigger_error('Database must be set, this will not be caught anymore in 5.0.', E_USER_DEPRECATED); $rule->setDatabase(Factory::getContainer()->get(DatabaseInterface::class)); } } @@ -340,7 +339,7 @@ private function checkDefaultValue($data) $value = $data['default_value']; if ($data['type'] === 'checkboxes') { - $value = explode(',', $value); + $value = explode(',', (string) $value); } elseif ($element['multiple'] && \is_string($value) && \is_array(json_decode($value, true))) { $value = (array)json_decode($value); } @@ -350,8 +349,8 @@ private function checkDefaultValue($data) // Check if the test succeeded return $result === true ?: Text::_('COM_FIELDS_FIELD_INVALID_DEFAULT_VALUE'); - } catch (\UnexpectedValueException $e) { - return $e->getMessage(); + } catch (\UnexpectedValueException $unexpectedValueException) { + return $unexpectedValueException->getMessage(); } } @@ -371,7 +370,7 @@ private function getParams($params) } if (\is_array($params)) { - $params = (object) $params; + return (object) $params; } return $params; @@ -485,11 +484,10 @@ public function delete(&$pks) $success = parent::delete($pks); if ($success) { - $pks = (array) $pks; $pks = ArrayHelper::toInteger($pks); $pks = array_filter($pks); - if (!empty($pks)) { + if ($pks !== []) { // Delete Values $query = $db->getQuery(true); @@ -627,10 +625,10 @@ public function setFieldValue($fieldId, $itemId, $value) if ($oldValue === null) { // No records available, doing normal insert $needsInsert = true; - } elseif (\count($value) == 1 && \count((array) $oldValue) == 1) { + } elseif (\count($value) === 1 && \count((array) $oldValue) === 1) { // Only a single row value update can be done when not empty $needsUpdate = \is_array($value[0]) ? \count($value[0]) : \strlen($value[0]); - $needsDelete = !$needsUpdate; + $needsDelete = $needsUpdate === 0; } else { // Multiple values, we need to purge the data and do a new // insert @@ -716,7 +714,7 @@ public function getFieldValue($fieldId, $itemId) */ public function getFieldValues(array $fieldIds, $itemId) { - if (!$fieldIds) { + if ($fieldIds === []) { return []; } @@ -939,19 +937,19 @@ protected function loadFormData() $filters = (array) $app->getUserState('com_fields.fields.filter'); $data->set('state', $input->getInt('state', ((isset($filters['state']) && $filters['state'] !== '') ? $filters['state'] : null))); - $data->set('language', $input->getString('language', (!empty($filters['language']) ? $filters['language'] : null))); - $data->set('group_id', $input->getString('group_id', (!empty($filters['group_id']) ? $filters['group_id'] : null))); + $data->set('language', $input->getString('language', (empty($filters['language']) ? null : $filters['language']))); + $data->set('group_id', $input->getString('group_id', (empty($filters['group_id']) ? null : $filters['group_id']))); $data->set( 'assigned_cat_ids', $input->get( 'assigned_cat_ids', - (!empty($filters['assigned_cat_ids']) ? (array)$filters['assigned_cat_ids'] : [0]), + (empty($filters['assigned_cat_ids']) ? [0] : (array)$filters['assigned_cat_ids']), 'array' ) ); $data->set( 'access', - $input->getInt('access', (!empty($filters['access']) ? $filters['access'] : $app->get('access'))) + $input->getInt('access', (empty($filters['access']) ? $app->get('access') : $filters['access'])) ); // Set the type if available from the request @@ -983,10 +981,8 @@ protected function loadFormData() */ public function validate($form, $data, $group = null) { - if (!$this->getCurrentUser()->authorise('core.admin', 'com_fields')) { - if (isset($data['rules'])) { - unset($data['rules']); - } + if (!$this->getCurrentUser()->authorise('core.admin', 'com_fields') && isset($data['rules'])) { + unset($data['rules']); } return parent::validate($form, $data, $group); @@ -1060,11 +1056,11 @@ function () use ($component, $section) { // Try to get the categories for this component and section try { $cat = $componentObject->getCategory([], $section ?: ''); - } catch (SectionNotFoundException $e) { + } catch (SectionNotFoundException) { // Not found for component and section -> Now try once more without the section, so only component try { $cat = $componentObject->getCategory(); - } catch (SectionNotFoundException $e) { + } catch (SectionNotFoundException) { // If we haven't found it now, return (no categories available for this component) return null; } @@ -1076,7 +1072,7 @@ function () use ($component, $section) { )(); // If we found categories, and if the root category has children, set them in the form - if ($cat && $cat->get('root')->hasChildren()) { + if ($cat instanceof CategoryInterface && $cat->get('root')->hasChildren()) { $form->setFieldAttribute('assigned_cat_ids', 'extension', $cat->getExtension()); } else { // Else remove the field from the form @@ -1225,7 +1221,7 @@ protected function batchMove($value, $pks, $contexts) // Set the variables $user = $this->getCurrentUser(); $table = $this->getTable(); - $context = explode('.', Factory::getApplication()->getUserState('com_fields.fields.context')); + $context = explode('.', (string) Factory::getApplication()->getUserState('com_fields.fields.context')); $value = (int) $value; foreach ($pks as $pk) { diff --git a/administrator/components/com_fields/src/Model/FieldsModel.php b/administrator/components/com_fields/src/Model/FieldsModel.php index aa6b8c112edc3..95246bdff1629 100644 --- a/administrator/components/com_fields/src/Model/FieldsModel.php +++ b/administrator/components/com_fields/src/Model/FieldsModel.php @@ -10,9 +10,11 @@ namespace Joomla\Component\Fields\Administrator\Model; +use Joomla\CMS\Categories\CategoryInterface; use Joomla\CMS\Categories\CategoryServiceInterface; use Joomla\CMS\Categories\SectionNotFoundException; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\CMS\MVC\Model\ListModel; use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; @@ -213,11 +215,11 @@ function () use ($parts) { // Try to get the categories for this component and section try { $cat = $componentObject->getCategory([], $parts[1] ?: ''); - } catch (SectionNotFoundException $e) { + } catch (SectionNotFoundException) { // Not found for component and section -> Now try once more without the section, so only component try { $cat = $componentObject->getCategory(); - } catch (SectionNotFoundException $e) { + } catch (SectionNotFoundException) { // If we haven't found it now, return (no categories available for this component) return null; } @@ -228,7 +230,7 @@ function () use ($parts) { } )(); - if ($cat) { + if ($cat instanceof CategoryInterface) { foreach ($categories as $assignedCatIds) { // Check if we have the actual category $parent = $cat->get($assignedCatIds); @@ -336,12 +338,12 @@ function () use ($parts) { $search = $this->getState('filter.search'); if (!empty($search)) { - if (stripos($search, 'id:') === 0) { - $search = (int) substr($search, 3); + if (stripos((string) $search, 'id:') === 0) { + $search = (int) substr((string) $search, 3); $query->where($db->quoteName('a.id') . ' = :id') ->bind(':id', $search, ParameterType::INTEGER); - } elseif (stripos($search, 'author:') === 0) { - $search = '%' . substr($search, 7) . '%'; + } elseif (stripos((string) $search, 'author:') === 0) { + $search = '%' . substr((string) $search, 7) . '%'; $query->where( '(' . $db->quoteName('ua.name') . ' LIKE :name OR ' . @@ -351,7 +353,7 @@ function () use ($parts) { ->bind(':name', $search) ->bind(':username', $search); } else { - $search = '%' . str_replace(' ', '%', trim($search)) . '%'; + $search = '%' . str_replace(' ', '%', trim((string) $search)) . '%'; $query->where( '(' . $db->quoteName('a.title') . ' LIKE :title OR ' . @@ -413,7 +415,7 @@ protected function _getList($query, $limitstart = 0, $limit = 0) * @param array $data data * @param boolean $loadData load current data * - * @return \Joomla\CMS\Form\Form|bool the Form object or false + * @return Form|bool the Form object or false * * @since 3.7.0 */ diff --git a/administrator/components/com_fields/src/Model/GroupModel.php b/administrator/components/com_fields/src/Model/GroupModel.php index 69caf97134ff0..268c724d73035 100644 --- a/administrator/components/com_fields/src/Model/GroupModel.php +++ b/administrator/components/com_fields/src/Model/GroupModel.php @@ -35,7 +35,7 @@ class GroupModel extends AdminModel * * @since 3.7.0 */ - public $typeAlias = null; + public $typeAlias; /** * Allowed batch commands @@ -283,10 +283,8 @@ protected function preprocessForm(Form $form, $data, $group = 'content') */ public function validate($form, $data, $group = null) { - if (!$this->getCurrentUser()->authorise('core.admin', 'com_fields')) { - if (isset($data['rules'])) { - unset($data['rules']); - } + if (!$this->getCurrentUser()->authorise('core.admin', 'com_fields') && isset($data['rules'])) { + unset($data['rules']); } return parent::validate($form, $data, $group); @@ -312,20 +310,20 @@ protected function loadFormData() // Pre-select some filters (Status, Language, Access) in edit form if those have been selected in Field Group Manager if (!$data->id) { // Check for which context the Field Group Manager is used and get selected fields - $context = substr($app->getUserState('com_fields.groups.filter.context', ''), 4); + $context = substr((string) $app->getUserState('com_fields.groups.filter.context', ''), 4); $filters = (array) $app->getUserState('com_fields.groups.' . $context . '.filter'); $data->set( 'state', - $input->getInt('state', (!empty($filters['state']) ? $filters['state'] : null)) + $input->getInt('state', (empty($filters['state']) ? null : $filters['state'])) ); $data->set( 'language', - $input->getString('language', (!empty($filters['language']) ? $filters['language'] : null)) + $input->getString('language', (empty($filters['language']) ? null : $filters['language'])) ); $data->set( 'access', - $input->getInt('access', (!empty($filters['access']) ? $filters['access'] : $app->get('access'))) + $input->getInt('access', (empty($filters['access']) ? $app->get('access') : $filters['access'])) ); } } diff --git a/administrator/components/com_fields/src/Model/GroupsModel.php b/administrator/components/com_fields/src/Model/GroupsModel.php index 5ad10277f1c23..1366aa9ddd29c 100644 --- a/administrator/components/com_fields/src/Model/GroupsModel.php +++ b/administrator/components/com_fields/src/Model/GroupsModel.php @@ -187,12 +187,12 @@ protected function getListQuery() $search = $this->getState('filter.search'); if (!empty($search)) { - if (stripos($search, 'id:') === 0) { - $search = (int) substr($search, 3); + if (stripos((string) $search, 'id:') === 0) { + $search = (int) substr((string) $search, 3); $query->where($db->quoteName('a.id') . ' = :search') ->bind(':search', $search, ParameterType::INTEGER); } else { - $search = '%' . str_replace(' ', '%', trim($search)) . '%'; + $search = '%' . str_replace(' ', '%', trim((string) $search)) . '%'; $query->where($db->quoteName('a.title') . ' LIKE :search') ->bind(':search', $search); } diff --git a/administrator/components/com_fields/src/Plugin/FieldsPlugin.php b/administrator/components/com_fields/src/Plugin/FieldsPlugin.php index 4aa87df598cfc..db168d8db304c 100644 --- a/administrator/components/com_fields/src/Plugin/FieldsPlugin.php +++ b/administrator/components/com_fields/src/Plugin/FieldsPlugin.php @@ -10,6 +10,7 @@ namespace Joomla\Component\Fields\Administrator\Plugin; +use Joomla\CMS\Application\CMSApplication; use Joomla\CMS\Event\CustomFields\GetTypesEvent; use Joomla\CMS\Event\CustomFields\PrepareDomEvent; use Joomla\CMS\Event\CustomFields\PrepareFieldEvent; @@ -43,7 +44,7 @@ abstract class FieldsPlugin extends CMSPlugin /** * Application object. * - * @var \Joomla\CMS\Application\CMSApplication + * @var CMSApplication * @since 4.0.0 */ protected $app; @@ -153,7 +154,7 @@ public function onCustomFieldsGetTypes() // The language key $key = strtoupper($layout); - if ($key != strtoupper($this->_name)) { + if ($key !== strtoupper($this->_name)) { $key = strtoupper($this->_name) . '_' . $layout; } @@ -222,10 +223,9 @@ public function onCustomFieldsPrepareField($context, $item, $field) // Render the layout ob_start(); include $path; - $output = ob_get_clean(); // Return the output - return $output; + return ob_get_clean(); } /** @@ -288,7 +288,7 @@ public function onCustomFieldsPrepareDom($field, \DOMElement $parent, Form $form foreach ($params->toArray() as $key => $param) { if (\is_array($param)) { // Multidimensional arrays (eg. list options) can't be transformed properly - $param = \count($param) == \count($param, COUNT_RECURSIVE) ? implode(',', $param) : ''; + $param = \count($param) === \count($param, COUNT_RECURSIVE) ? implode(',', $param) : ''; } if ($param === '' || (!\is_string($param) && !is_numeric($param))) { @@ -343,7 +343,7 @@ public function onContentPrepareForm(Form $form, $data) protected function getFormPath(Form $form, $data) { // Check if the field form is calling us - if (strpos($form->getName(), 'com_fields.field') !== 0) { + if (!str_starts_with($form->getName(), 'com_fields.field')) { return null; } diff --git a/administrator/components/com_fields/src/Table/FieldTable.php b/administrator/components/com_fields/src/Table/FieldTable.php index ad8b124da1a49..7696e078c87c8 100644 --- a/administrator/components/com_fields/src/Table/FieldTable.php +++ b/administrator/components/com_fields/src/Table/FieldTable.php @@ -133,7 +133,7 @@ public function bind($src, $ignore = '') public function check() { // Check for valid name - if (trim($this->title) == '') { + if (trim($this->title) === '') { $this->setError(Text::_('COM_FIELDS_MUSTCONTAIN_A_TITLE_FIELD')); return false; @@ -145,7 +145,7 @@ public function check() $this->name = ApplicationHelper::stringURLSafe($this->name, $this->language); - if (trim(str_replace('-', '', $this->name)) == '') { + if (trim(str_replace('-', '', $this->name)) === '') { $this->name = StringHelper::increment($this->name, 'dash'); } @@ -174,7 +174,7 @@ public function check() $user = $this->getCurrentUser(); // Set created date if not set. - if (!(int) $this->created_time) { + if ((int) $this->created_time === 0) { $this->created_time = $date; } @@ -183,7 +183,7 @@ public function check() $this->modified_time = $date; $this->modified_by = $user->id; } else { - if (!(int) $this->modified_time) { + if ((int) $this->modified_time === 0) { $this->modified_time = $this->created_time; } @@ -313,7 +313,7 @@ private function getAssetId($name) if ($result = $db->loadResult()) { $assetId = (int) $result; - if ($assetId) { + if ($assetId !== 0) { return $assetId; } } diff --git a/administrator/components/com_fields/src/Table/GroupTable.php b/administrator/components/com_fields/src/Table/GroupTable.php index b72a7145c44da..89e2e062fc049 100644 --- a/administrator/components/com_fields/src/Table/GroupTable.php +++ b/administrator/components/com_fields/src/Table/GroupTable.php @@ -100,7 +100,7 @@ public function bind($src, $ignore = '') public function check() { // Check for a title. - if (trim($this->title) == '') { + if (trim($this->title) === '') { $this->setError(Text::_('COM_FIELDS_MUSTCONTAIN_A_TITLE_GROUP')); return false; @@ -110,7 +110,7 @@ public function check() $user = $this->getCurrentUser(); // Set created date if not set. - if (!(int) $this->created) { + if ((int) $this->created === 0) { $this->created = $date; } @@ -118,7 +118,7 @@ public function check() $this->modified = $date; $this->modified_by = $user->id; } else { - if (!(int) $this->modified) { + if ((int) $this->modified === 0) { $this->modified = $this->created; } @@ -211,7 +211,7 @@ protected function _getAssetParentId(?Table $table = null, $id = null) ->bind(':name', $component[0]); $db->setQuery($query); - if ($assetId = (int) $db->loadResult()) { + if ($assetId = (int) $db->loadResult() !== 0) { return $assetId; } diff --git a/administrator/components/com_fields/src/View/Field/HtmlView.php b/administrator/components/com_fields/src/View/Field/HtmlView.php index 788807326a21b..44d5773fec937 100644 --- a/administrator/components/com_fields/src/View/Field/HtmlView.php +++ b/administrator/components/com_fields/src/View/Field/HtmlView.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Fields\Administrator\View\Field; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; @@ -19,6 +20,7 @@ use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Fields\Administrator\Model\FieldModel; use Joomla\Filesystem\Path; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -31,8 +33,9 @@ */ class HtmlView extends BaseHtmlView { + public $canDo; /** - * @var \Joomla\CMS\Form\Form + * @var Form * * @since 3.7.0 */ @@ -46,7 +49,7 @@ class HtmlView extends BaseHtmlView protected $item; /** - * @var \Joomla\Registry\Registry + * @var Registry * * @since 3.7.0 */ @@ -75,7 +78,7 @@ public function display($tpl = null) $this->canDo = ContentHelper::getActions($this->state->get('field.component'), 'field', $this->item->id); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -102,7 +105,7 @@ protected function addToolbar() $toolbar = $this->getDocument()->getToolbar(); $isNew = ($this->item->id == 0); - $checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $userId); + $checkedOut = !\is_null($this->item->checked_out) && $this->item->checked_out != $userId; // Avoid nonsense situation. if ($component == 'com_fields') { @@ -111,15 +114,16 @@ protected function addToolbar() // Load component language file $lang = $this->getLanguage(); - $lang->load($component, JPATH_ADMINISTRATOR) - || $lang->load($component, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + if (!$lang->load($component, JPATH_ADMINISTRATOR)) { + $lang->load($component, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + } - $title = Text::sprintf('COM_FIELDS_VIEW_FIELD_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', Text::_(strtoupper($component))); + $title = Text::sprintf('COM_FIELDS_VIEW_FIELD_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', Text::_(strtoupper((string) $component))); // Prepare the toolbar. ToolbarHelper::title( $title, - 'puzzle field-' . ($isNew ? 'add' : 'edit') . ' ' . substr($component, 4) . ($section ? "-$section" : '') . '-field-' . + 'puzzle field-' . ($isNew ? 'add' : 'edit') . ' ' . substr((string) $component, 4) . ($section ? '-' . $section : '') . '-field-' . ($isNew ? 'add' : 'edit') ); diff --git a/administrator/components/com_fields/src/View/Fields/HtmlView.php b/administrator/components/com_fields/src/View/Fields/HtmlView.php index 35c6e2608139e..4e0f02f6c1c60 100644 --- a/administrator/components/com_fields/src/View/Fields/HtmlView.php +++ b/administrator/components/com_fields/src/View/Fields/HtmlView.php @@ -11,11 +11,13 @@ namespace Joomla\Component\Fields\Administrator\View\Fields; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Router\Route; use Joomla\CMS\Toolbar\Button\DropdownButton; @@ -23,6 +25,7 @@ use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; use Joomla\Component\Fields\Administrator\Model\FieldsModel; use Joomla\Filesystem\Path; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -36,7 +39,7 @@ class HtmlView extends BaseHtmlView { /** - * @var \Joomla\CMS\Form\Form + * @var Form * * @since 3.7.0 */ @@ -57,14 +60,14 @@ class HtmlView extends BaseHtmlView protected $items; /** - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination * * @since 3.7.0 */ protected $pagination; /** - * @var \Joomla\Registry\Registry + * @var Registry * * @since 3.7.0 */ @@ -93,7 +96,7 @@ public function display($tpl = null) $this->activeFilters = $model->getActiveFilters(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -139,13 +142,14 @@ protected function addToolbar() // Load extension language file $lang = $this->getLanguage(); - $lang->load($component, JPATH_ADMINISTRATOR) - || $lang->load($component, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + if (!$lang->load($component, JPATH_ADMINISTRATOR)) { + $lang->load($component, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + } - $title = Text::sprintf('COM_FIELDS_VIEW_FIELDS_TITLE', Text::_(strtoupper($component))); + $title = Text::sprintf('COM_FIELDS_VIEW_FIELDS_TITLE', Text::_(strtoupper((string) $component))); // Prepare the toolbar. - ToolbarHelper::title($title, 'puzzle-piece fields ' . substr($component, 4) . ($section ? "-$section" : '') . '-fields'); + ToolbarHelper::title($title, 'puzzle-piece fields ' . substr((string) $component, 4) . ($section ? '-' . $section : '') . '-fields'); if ($canDo->get('core.create')) { $toolbar->addNew('field.add'); diff --git a/administrator/components/com_fields/src/View/Group/HtmlView.php b/administrator/components/com_fields/src/View/Group/HtmlView.php index b6ebc8d9bd778..528340a93ef84 100644 --- a/administrator/components/com_fields/src/View/Group/HtmlView.php +++ b/administrator/components/com_fields/src/View/Group/HtmlView.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Fields\Administrator\View\Group; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; @@ -20,6 +21,7 @@ use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; use Joomla\Component\Fields\Administrator\Model\GroupModel; use Joomla\Filesystem\Path; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -33,7 +35,7 @@ class HtmlView extends BaseHtmlView { /** - * @var \Joomla\CMS\Form\Form + * @var Form * * @since 3.7.0 */ @@ -47,7 +49,7 @@ class HtmlView extends BaseHtmlView protected $item; /** - * @var \Joomla\Registry\Registry + * @var Registry * * @since 3.7.0 */ @@ -56,7 +58,7 @@ class HtmlView extends BaseHtmlView /** * The actions the user is authorised to perform * - * @var \Joomla\Registry\Registry + * @var Registry * * @since 3.7.0 */ @@ -90,7 +92,7 @@ public function display($tpl = null) $this->canDo = ContentHelper::getActions($component, 'fieldgroup', $this->item->id); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -122,7 +124,7 @@ protected function addToolbar() $canDo = $this->canDo; $isNew = ($this->item->id == 0); - $checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $userId); + $checkedOut = !\is_null($this->item->checked_out) && $this->item->checked_out != $userId; // Avoid nonsense situation. if ($component == 'com_fields') { @@ -131,15 +133,16 @@ protected function addToolbar() // Load component language file $lang = $this->getLanguage(); - $lang->load($component, JPATH_ADMINISTRATOR) - || $lang->load($component, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + if (!$lang->load($component, JPATH_ADMINISTRATOR)) { + $lang->load($component, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + } - $title = Text::sprintf('COM_FIELDS_VIEW_GROUP_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', Text::_(strtoupper($component))); + $title = Text::sprintf('COM_FIELDS_VIEW_GROUP_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', Text::_(strtoupper((string) $component))); // Prepare the toolbar. ToolbarHelper::title( $title, - 'puzzle-piece field-' . ($isNew ? 'add' : 'edit') . ' ' . substr($component, 4) . '-group-' . + 'puzzle-piece field-' . ($isNew ? 'add' : 'edit') . ' ' . substr((string) $component, 4) . '-group-' . ($isNew ? 'add' : 'edit') ); diff --git a/administrator/components/com_fields/src/View/Groups/HtmlView.php b/administrator/components/com_fields/src/View/Groups/HtmlView.php index be2bf889e2050..ac87aa86af5df 100644 --- a/administrator/components/com_fields/src/View/Groups/HtmlView.php +++ b/administrator/components/com_fields/src/View/Groups/HtmlView.php @@ -11,11 +11,13 @@ namespace Joomla\Component\Fields\Administrator\View\Groups; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Router\Route; use Joomla\CMS\Toolbar\Button\DropdownButton; @@ -23,6 +25,7 @@ use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; use Joomla\Component\Fields\Administrator\Model\GroupsModel; use Joomla\Filesystem\Path; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -36,7 +39,7 @@ class HtmlView extends BaseHtmlView { /** - * @var \Joomla\CMS\Form\Form + * @var Form * * @since 3.7.0 */ @@ -57,14 +60,14 @@ class HtmlView extends BaseHtmlView protected $items; /** - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination * * @since 3.7.0 */ protected $pagination; /** - * @var \Joomla\Registry\Registry + * @var Registry * * @since 3.7.0 */ @@ -93,7 +96,7 @@ public function display($tpl = null) $this->activeFilters = $model->getActiveFilters(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -141,13 +144,14 @@ protected function addToolbar() // Load component language file $lang = $this->getLanguage(); - $lang->load($component, JPATH_ADMINISTRATOR) - || $lang->load($component, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + if (!$lang->load($component, JPATH_ADMINISTRATOR)) { + $lang->load($component, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + } - $title = Text::sprintf('COM_FIELDS_VIEW_GROUPS_TITLE', Text::_(strtoupper($component))); + $title = Text::sprintf('COM_FIELDS_VIEW_GROUPS_TITLE', Text::_(strtoupper((string) $component))); // Prepare the toolbar. - ToolbarHelper::title($title, 'puzzle-piece fields ' . substr($component, 4) . '-groups'); + ToolbarHelper::title($title, 'puzzle-piece fields ' . substr((string) $component, 4) . '-groups'); if ($canDo->get('core.create')) { $toolbar->addNew('group.add'); diff --git a/administrator/components/com_fields/tmpl/fields/default.php b/administrator/components/com_fields/tmpl/fields/default.php index 77b27cce1aa81..490c31c7f1ad1 100644 --- a/administrator/components/com_fields/tmpl/fields/default.php +++ b/administrator/components/com_fields/tmpl/fields/default.php @@ -36,7 +36,7 @@ $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); $ordering = ($listOrder == 'a.ordering'); -$saveOrder = ($listOrder == 'a.ordering' && strtolower($listDirn) == 'asc'); +$saveOrder = ($listOrder == 'a.ordering' && strtolower((string) $listDirn) === 'asc'); // The category object of the component $category = Categories::getInstance(str_replace('com_', '', $component) . '.' . $section); @@ -110,7 +110,7 @@ class="js-draggable" data-url="" data-direction="" data-nested="true" class="js-draggable" data-url="" data-direction="" data-nested="true"> items as $i => $item) : ?> diff --git a/administrator/components/com_fields/tmpl/groups/default.php b/administrator/components/com_fields/tmpl/groups/default.php index d72ad1d5cb4c9..126b76ff3e776 100644 --- a/administrator/components/com_fields/tmpl/groups/default.php +++ b/administrator/components/com_fields/tmpl/groups/default.php @@ -40,7 +40,7 @@ $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); $ordering = ($listOrder == 'a.ordering'); -$saveOrder = ($listOrder == 'a.ordering' && strtolower($listDirn) == 'asc'); +$saveOrder = ($listOrder == 'a.ordering' && strtolower((string) $listDirn) === 'asc'); if ($saveOrder && !empty($this->items)) { $saveOrderingUrl = 'index.php?option=com_fields&task=groups.saveOrderAjax&tmpl=component&' . Session::getFormToken() . '=1'; @@ -102,7 +102,7 @@ class="js-draggable" data-url="" data-direction="" data-nested="true" class="js-draggable" data-url="" data-direction="" data-nested="true"> items as $i => $item) : ?> diff --git a/administrator/components/com_finder/src/Controller/DisplayController.php b/administrator/components/com_finder/src/Controller/DisplayController.php index 4178ae969931d..97587b3a77340 100644 --- a/administrator/components/com_finder/src/Controller/DisplayController.php +++ b/administrator/components/com_finder/src/Controller/DisplayController.php @@ -53,7 +53,7 @@ public function display($cachable = false, $urlparams = []) // Check for edit form. if ($view === 'filter' && $layout === 'edit' && !$this->checkEditId('com_finder.edit.filter', $filterId)) { // Somehow the person just went to the form - we don't allow that. - if (!\count($this->app->getMessageQueue())) { + if (\count($this->app->getMessageQueue()) === 0) { $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $filterId), 'error'); } diff --git a/administrator/components/com_finder/src/Controller/FilterController.php b/administrator/components/com_finder/src/Controller/FilterController.php index 068c4adc3f6f4..d6418192b6acb 100644 --- a/administrator/components/com_finder/src/Controller/FilterController.php +++ b/administrator/components/com_finder/src/Controller/FilterController.php @@ -14,6 +14,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\FormController; use Joomla\CMS\Router\Route; +use Joomla\Component\Finder\Administrator\Model\FilterModel; use Joomla\Utilities\ArrayHelper; // phpcs:disable PSR1.Files.SideEffects @@ -42,12 +43,12 @@ public function save($key = null, $urlVar = null) // Check for request forgeries. $this->checkToken(); - /** @var \Joomla\Component\Finder\Administrator\Model\FilterModel $model */ + /** @var FilterModel $model */ $model = $this->getModel(); $table = $model->getTable(); $data = $this->input->post->get('jform', [], 'array'); $checkin = $table->hasField('checked_out'); - $context = "$this->option.edit.$this->context"; + $context = \sprintf('%s.edit.%s', $this->option, $this->context); $task = $this->getTask(); // Determine the name of the primary key for the data. @@ -78,7 +79,7 @@ public function save($key = null, $urlVar = null) // Check-in the original row. if ($checkin && $model->checkin($data[$key]) === false) { // Check-in failed. Go back to the item and display a notice. - if (!\count($this->app->getMessageQueue())) { + if (\count($this->app->getMessageQueue()) === 0) { $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError()), 'error'); } diff --git a/administrator/components/com_finder/src/Controller/FiltersController.php b/administrator/components/com_finder/src/Controller/FiltersController.php index 89c02dc0c1a17..e7dc69dc6f388 100644 --- a/administrator/components/com_finder/src/Controller/FiltersController.php +++ b/administrator/components/com_finder/src/Controller/FiltersController.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Finder\Administrator\Controller; use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -38,7 +39,7 @@ class FiltersController extends AdminController * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model. + * @return BaseDatabaseModel The model. * * @since 2.5 */ diff --git a/administrator/components/com_finder/src/Controller/IndexController.php b/administrator/components/com_finder/src/Controller/IndexController.php index 3faa50301b642..ea9fff5191e34 100644 --- a/administrator/components/com_finder/src/Controller/IndexController.php +++ b/administrator/components/com_finder/src/Controller/IndexController.php @@ -13,8 +13,10 @@ use Joomla\CMS\Event\Finder\GarbageCollectionEvent; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Plugin\PluginHelper; use Joomla\Component\Finder\Administrator\Indexer\Indexer; +use Joomla\Component\Finder\Administrator\Model\IndexModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -34,7 +36,7 @@ class IndexController extends AdminController * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model. + * @return BaseDatabaseModel The model. * * @since 2.5 */ @@ -86,7 +88,7 @@ public function purge() set_time_limit(0); } - /** @var \Joomla\Component\Finder\Administrator\Model\IndexModel $model */ + /** @var IndexModel $model */ $model = $this->getModel('Index', 'Administrator'); // Attempt to purge the index. diff --git a/administrator/components/com_finder/src/Controller/IndexerController.php b/administrator/components/com_finder/src/Controller/IndexerController.php index ce5696d82b2e5..d96dff7dc6b2c 100644 --- a/administrator/components/com_finder/src/Controller/IndexerController.php +++ b/administrator/components/com_finder/src/Controller/IndexerController.php @@ -18,6 +18,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Log\Log; use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\CMS\Object\CMSObject; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Session\Session; use Joomla\Component\Finder\Administrator\Indexer\Adapter; @@ -65,7 +66,7 @@ public function start() // Log the start try { Log::add('Starting the indexer', Log::INFO); - } catch (\RuntimeException $exception) { + } catch (\RuntimeException) { // Informational log only } @@ -97,15 +98,15 @@ public function start() $output = ob_get_contents(); // Finder plugins should not create output of any kind. If there is output, that very likely is the result of a PHP error. - if (trim($output)) { + if (trim($output) !== '' && trim($output) !== '0') { throw new \Exception(Text::_('COM_FINDER_AN_ERROR_HAS_OCCURRED')); } // Send the response. static::sendResponse($state); - } catch (\Exception $e) { + } catch (\Exception $exception) { // Catch an exception and return the response. - static::sendResponse($e); + static::sendResponse($exception); } } @@ -137,7 +138,7 @@ public function batch() // Log the start try { Log::add('Starting the indexer batch process', Log::INFO); - } catch (\RuntimeException $exception) { + } catch (\RuntimeException) { // Informational log only } @@ -172,7 +173,7 @@ public function batch() $lang = $this->app->getLanguage(); // Get the document properties. - $attributes = [ + [ 'charset' => 'utf-8', 'lineend' => 'unix', 'tab' => ' ', @@ -196,23 +197,23 @@ public function batch() // Log batch completion and memory high-water mark. try { Log::add('Batch completed, peak memory usage: ' . number_format(memory_get_peak_usage(true)) . ' bytes', Log::INFO); - } catch (\RuntimeException $exception) { + } catch (\RuntimeException) { // Informational log only } $output = ob_get_contents(); // Finder plugins should not create output of any kind. If there is output, that very likely is the result of a PHP error. - if (trim($output)) { + if (trim($output) !== '' && trim($output) !== '0') { throw new \Exception(Text::_('COM_FINDER_INDEXER_ERROR_PLUGIN_FAILURE')); } // Send the response. static::sendResponse($state); - } catch (\Exception $e) { + } catch (\Exception $exception) { // Catch an exception and return the response. // Send the response. - static::sendResponse($e); + static::sendResponse($exception); } } @@ -254,15 +255,15 @@ public function optimize() $output = ob_get_contents(); // Finder plugins should not create output of any kind. If there is output, that very likely is the result of a PHP error. - if (trim($output)) { + if (trim($output) !== '' && trim($output) !== '0') { throw new \Exception(Text::_('COM_FINDER_AN_ERROR_HAS_OCCURRED')); } // Send the response. static::sendResponse($state); - } catch (\Exception $e) { + } catch (\Exception $exception) { // Catch an exception and return the response. - static::sendResponse($e); + static::sendResponse($exception); } } @@ -271,7 +272,7 @@ public function optimize() * can be an \Exception object for when an error has occurred or * a CMSObject for a good response. * - * @param \Joomla\CMS\Object\CMSObject|\Exception $data CMSObject on success, \Exception on error. [optional] + * @param CMSObject|\Exception $data CMSObject on success, \Exception on error. [optional] * * @return void * @@ -293,7 +294,7 @@ public static function sendResponse($data = null) if ($data instanceof \Exception) { try { Log::add($data->getMessage(), Log::ERROR); - } catch (\RuntimeException $exception) { + } catch (\RuntimeException) { // Informational log only } @@ -415,10 +416,10 @@ class_alias(DebugAdapter::class, Adapter::class); $state->rendered = $output; echo json_encode($state); - } catch (\Exception $e) { + } catch (\Exception $exception) { // Catch an exception and return the response. // Send the response. - static::sendResponse($e); + static::sendResponse($exception); } } } diff --git a/administrator/components/com_finder/src/Controller/MapsController.php b/administrator/components/com_finder/src/Controller/MapsController.php index 2d82754789a1c..78ce6c092551e 100644 --- a/administrator/components/com_finder/src/Controller/MapsController.php +++ b/administrator/components/com_finder/src/Controller/MapsController.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Finder\Administrator\Controller; use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -38,7 +39,7 @@ class MapsController extends AdminController * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model. + * @return BaseDatabaseModel The model. * * @since 1.6 */ diff --git a/administrator/components/com_finder/src/Field/BranchesField.php b/administrator/components/com_finder/src/Field/BranchesField.php index 5ce952350fec6..f0de12f861df8 100644 --- a/administrator/components/com_finder/src/Field/BranchesField.php +++ b/administrator/components/com_finder/src/Field/BranchesField.php @@ -40,7 +40,7 @@ class BranchesField extends ListField * * @since 3.5 */ - public function getOptions() + protected function getOptions() { Factory::getApplication()->bootComponent('com_finder'); diff --git a/administrator/components/com_finder/src/Field/ContentmapField.php b/administrator/components/com_finder/src/Field/ContentmapField.php index e35a26205d31a..ea005dc8e581d 100644 --- a/administrator/components/com_finder/src/Field/ContentmapField.php +++ b/administrator/components/com_finder/src/Field/ContentmapField.php @@ -63,7 +63,7 @@ protected function getGroups() try { $contentMap = $db->loadObjectList(); - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { return []; } diff --git a/administrator/components/com_finder/src/Field/ContenttypesField.php b/administrator/components/com_finder/src/Field/ContenttypesField.php index 45d78df38e5be..f4740ce610ea9 100644 --- a/administrator/components/com_finder/src/Field/ContenttypesField.php +++ b/administrator/components/com_finder/src/Field/ContenttypesField.php @@ -43,7 +43,7 @@ class ContenttypesField extends ListField * * @since 3.6.0 */ - public function getOptions() + protected function getOptions() { $lang = Factory::getLanguage(); $options = []; @@ -59,8 +59,8 @@ public function getOptions() try { $contentTypes = $db->loadObjectList(); - } catch (\RuntimeException $e) { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + } catch (\RuntimeException $runtimeException) { + Factory::getApplication()->enqueueMessage($runtimeException->getMessage(), 'error'); } // Translate. diff --git a/administrator/components/com_finder/src/Field/SearchfilterField.php b/administrator/components/com_finder/src/Field/SearchfilterField.php index 7925b42e01ab9..b953ba4f73ee3 100644 --- a/administrator/components/com_finder/src/Field/SearchfilterField.php +++ b/administrator/components/com_finder/src/Field/SearchfilterField.php @@ -40,7 +40,7 @@ class SearchfilterField extends ListField * * @since 2.5 */ - public function getOptions() + protected function getOptions() { // Build the query. $db = $this->getDatabase(); diff --git a/administrator/components/com_finder/src/Helper/FinderHelper.php b/administrator/components/com_finder/src/Helper/FinderHelper.php index 3bdff6d9604c9..50f87acff4792 100644 --- a/administrator/components/com_finder/src/Helper/FinderHelper.php +++ b/administrator/components/com_finder/src/Helper/FinderHelper.php @@ -42,6 +42,6 @@ public static function getFinderPluginId() { $pluginRecord = ExtensionHelper::getExtensionRecord('finder', 'plugin', null, 'content'); - return $pluginRecord !== null ? $pluginRecord->extension_id : 0; + return $pluginRecord instanceof \stdClass ? $pluginRecord->extension_id : 0; } } diff --git a/administrator/components/com_finder/src/Helper/LanguageHelper.php b/administrator/components/com_finder/src/Helper/LanguageHelper.php index 34380b58f57ef..01e0f53bcdb0e 100644 --- a/administrator/components/com_finder/src/Helper/LanguageHelper.php +++ b/administrator/components/com_finder/src/Helper/LanguageHelper.php @@ -144,8 +144,9 @@ public static function loadPluginLanguage() // Load language file for each plugin. foreach ($plugins as $plugin) { - $lang->load($plugin->name, JPATH_ADMINISTRATOR) - || $lang->load($plugin->name, JPATH_PLUGINS . '/finder/' . $plugin->element); + if (!$lang->load($plugin->name, JPATH_ADMINISTRATOR)) { + $lang->load($plugin->name, JPATH_PLUGINS . '/finder/' . $plugin->element); + } } } } diff --git a/administrator/components/com_finder/src/Indexer/Adapter.php b/administrator/components/com_finder/src/Indexer/Adapter.php index d554f0c5b6799..ad0c37b392a14 100644 --- a/administrator/components/com_finder/src/Indexer/Adapter.php +++ b/administrator/components/com_finder/src/Indexer/Adapter.php @@ -804,11 +804,11 @@ protected function getItemMenuTitle($url) } // Instantiate the params. - $params = json_decode($params); + $params = json_decode((string) $params); // Get the page title if it is set. if (isset($params->page_title) && $params->page_title) { - $return = $params->page_title; + return $params->page_title; } return $return; diff --git a/administrator/components/com_finder/src/Indexer/DebugAdapter.php b/administrator/components/com_finder/src/Indexer/DebugAdapter.php index 11f5ea49d0f7d..7d94ef730df8b 100644 --- a/administrator/components/com_finder/src/Indexer/DebugAdapter.php +++ b/administrator/components/com_finder/src/Indexer/DebugAdapter.php @@ -804,11 +804,11 @@ protected function getItemMenuTitle($url) } // Instantiate the params. - $params = json_decode($params); + $params = json_decode((string) $params); // Get the page title if it is set. if (isset($params->page_title) && $params->page_title) { - $return = $params->page_title; + return $params->page_title; } return $return; @@ -919,16 +919,12 @@ protected function translateState($item, $category = null) } // Translate the state - switch ($item) { - case 1: - case 2: - // Published and archived items only should return a published state - return 1; - - default: - // All other states should return an unpublished state - return 0; - } + return match ($item) { + // Published and archived items only should return a published state + 1, 2 => 1, + // All other states should return an unpublished state + default => 0, + }; } /** diff --git a/administrator/components/com_finder/src/Indexer/Helper.php b/administrator/components/com_finder/src/Indexer/Helper.php index b57cdbdb83de8..3c462e8e93b12 100644 --- a/administrator/components/com_finder/src/Indexer/Helper.php +++ b/administrator/components/com_finder/src/Indexer/Helper.php @@ -475,12 +475,12 @@ public static function prepareContent($text, $params = null, ?Result $item = nul $content = Table::getInstance('Content'); $content->text = $text; - if ($item) { + if ($item instanceof Result) { $content->bind((array) $item); $content->bind($item->getElements()); } - if ($item && !empty($item->context)) { + if ($item instanceof Result && !empty($item->context)) { $content->context = $item->context; } diff --git a/administrator/components/com_finder/src/Indexer/Indexer.php b/administrator/components/com_finder/src/Indexer/Indexer.php index 13a9823d724f1..23ed3899a36aa 100644 --- a/administrator/components/com_finder/src/Indexer/Indexer.php +++ b/administrator/components/com_finder/src/Indexer/Indexer.php @@ -15,6 +15,7 @@ use Joomla\CMS\Object\CMSObject; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Profiler\Profiler; +use Joomla\Database\DatabaseDriver; use Joomla\Database\DatabaseInterface; use Joomla\Database\ParameterType; use Joomla\Database\QueryInterface; @@ -99,7 +100,7 @@ class Indexer /** * Database driver cache. * - * @var \Joomla\Database\DatabaseDriver + * @var DatabaseDriver * @since 3.8.0 */ protected $db; @@ -121,8 +122,8 @@ class Indexer */ public function __construct(?DatabaseInterface $db = null) { - if ($db === null) { - @trigger_error(\sprintf('Database will be mandatory in 5.0.'), E_USER_DEPRECATED); + if (!$db instanceof DatabaseInterface) { + @trigger_error('Database will be mandatory in 5.0.', E_USER_DEPRECATED); $db = Factory::getContainer()->get(DatabaseInterface::class); } @@ -186,7 +187,7 @@ public static function getState() */ $memory_table_limit = (int) ($heapsize->Value / 800); $data->options->set('memory_table_limit', $memory_table_limit); - } catch (\Exception $e) { + } catch (\Exception) { // Something failed. We fall back to a reasonable guess. $data->options->set('memory_table_limit', 7500); } @@ -279,8 +280,9 @@ public static function resetState() */ public function index($item, $format = 'html') { - // Mark beforeIndexing in the profiler. - static::$profiler ? static::$profiler->mark('beforeIndexing') : null; + if (static::$profiler) { + static::$profiler->mark('beforeIndexing'); + } $db = $this->db; $serverType = strtolower($db->getServerType()); @@ -327,8 +329,9 @@ public function index($item, $format = 'html') Taxonomy::removeMaps($linkId); } - // Mark afterUnmapping in the profiler. - static::$profiler ? static::$profiler->mark('afterUnmapping') : null; + if (static::$profiler) { + static::$profiler->mark('afterUnmapping'); + } // Perform cleanup on the item data. $item->publish_start_date = (int) $item->publish_start_date != 0 ? $item->publish_start_date : null; @@ -377,8 +380,9 @@ public function index($item, $format = 'html') // Set up the variables we will need during processing. $count = 0; - // Mark afterLinking in the profiler. - static::$profiler ? static::$profiler->mark('afterLinking') : null; + if (static::$profiler) { + static::$profiler->mark('afterLinking'); + } // Truncate the tokens tables. $db->truncateTable('#__finder_tokens'); @@ -468,8 +472,9 @@ public function index($item, $format = 'html') } } - // Mark afterProcessing in the profiler. - static::$profiler ? static::$profiler->mark('afterProcessing') : null; + if (static::$profiler) { + static::$profiler->mark('afterProcessing'); + } /* * At this point, all of the item's content has been parsed, tokenized @@ -510,8 +515,9 @@ public function index($item, $format = 'html') $db->execute(); } - // Mark afterAggregating in the profiler. - static::$profiler ? static::$profiler->mark('afterAggregating') : null; + if (static::$profiler) { + static::$profiler->mark('afterAggregating'); + } /* * When we pulled down all of the aggregate data, we did a LEFT JOIN @@ -546,7 +552,7 @@ public function index($item, $format = 'html') ->innerJoin($db->quoteName('#__finder_terms', 't'), 't.term = ta.term AND t.language = ta.language') ->where('ta.term_id = 0'); - if ($serverType == 'mysql') { + if ($serverType === 'mysql') { $query->set($db->quoteName('ta.term_id') . ' = ' . $db->quoteName('t.term_id')); } else { $query->set($db->quoteName('term_id') . ' = ' . $db->quoteName('t.term_id')); @@ -555,8 +561,9 @@ public function index($item, $format = 'html') $db->setQuery($query); $db->execute(); - // Mark afterTerms in the profiler. - static::$profiler ? static::$profiler->mark('afterTerms') : null; + if (static::$profiler) { + static::$profiler->mark('afterTerms'); + } /* * After we've made sure that all of the terms are in the terms table @@ -567,7 +574,7 @@ public function index($item, $format = 'html') ->update($db->quoteName('#__finder_terms', 't')) ->innerJoin($db->quoteName('#__finder_tokens_aggregate', 'ta'), 'ta.term_id = t.term_id'); - if ($serverType == 'mysql') { + if ($serverType === 'mysql') { $query->set($db->quoteName('t.links') . ' = t.links + 1'); } else { $query->set($db->quoteName('links') . ' = t.links + 1'); @@ -576,8 +583,9 @@ public function index($item, $format = 'html') $db->setQuery($query); $db->execute(); - // Mark afterTerms in the profiler. - static::$profiler ? static::$profiler->mark('afterTerms') : null; + if (static::$profiler) { + static::$profiler->mark('afterTerms'); + } /* * At this point, the aggregate table contains a record for each @@ -599,8 +607,9 @@ public function index($item, $format = 'html') ); $db->execute(); - // Mark afterMapping in the profiler. - static::$profiler ? static::$profiler->mark('afterMapping') : null; + if (static::$profiler) { + static::$profiler->mark('afterMapping'); + } // Update the signature. $object = serialize($item); @@ -615,8 +624,9 @@ public function index($item, $format = 'html') $db->setQuery($query); $db->execute(); - // Mark afterSigning in the profiler. - static::$profiler ? static::$profiler->mark('afterSigning') : null; + if (static::$profiler) { + static::$profiler->mark('afterSigning'); + } // Truncate the tokens tables. $db->truncateTable('#__finder_tokens'); @@ -627,8 +637,9 @@ public function index($item, $format = 'html') // Toggle the token tables back to memory tables. $this->toggleTables(true); - // Mark afterTruncating in the profiler. - static::$profiler ? static::$profiler->mark('afterTruncating') : null; + if (static::$profiler) { + static::$profiler->mark('afterTruncating'); + } // Trigger a plugin event after indexing PluginHelper::importPlugin('finder'); @@ -774,7 +785,7 @@ public function optimize() ]; foreach ($tables as $table) { - if ($serverType == 'mysql') { + if ($serverType === 'mysql') { $db->setQuery('OPTIMIZE TABLE ' . $db->quoteName($table)); $db->execute(); } else { @@ -987,7 +998,7 @@ protected function toggleTables($memory) return true; } - if (strtolower($this->db->getServerType()) != 'mysql') { + if (strtolower($this->db->getServerType()) !== 'mysql') { $supported = false; return true; @@ -1008,7 +1019,7 @@ protected function toggleTables($memory) // Set the tokens aggregate table to Memory. $db->setQuery('ALTER TABLE ' . $db->quoteName('#__finder_tokens_aggregate') . ' ENGINE = MEMORY'); $db->execute(); - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { $supported = false; return true; diff --git a/administrator/components/com_finder/src/Indexer/Language.php b/administrator/components/com_finder/src/Indexer/Language.php index 805ad349a2ece..e7c223feb7afa 100644 --- a/administrator/components/com_finder/src/Indexer/Language.php +++ b/administrator/components/com_finder/src/Indexer/Language.php @@ -56,7 +56,7 @@ class Language * @var Stemmer * @since 4.0.0 */ - protected $stemmer = null; + protected $stemmer; /** * Method to construct the language object. @@ -75,13 +75,13 @@ public function __construct($locale = null) } try { - foreach (StemmerFactory::LANGS as $classname => $isoCodes) { + foreach (StemmerFactory::LANGS as $isoCodes) { if (\in_array($this->language, $isoCodes)) { $this->stemmer = StemmerFactory::create($this->language); break; } } - } catch (NotFoundException $e) { + } catch (NotFoundException) { // We don't have a stemmer for the language } } @@ -147,14 +147,14 @@ public function tokenise($input) */ $input = StringHelper::strtolower($input); $input = preg_replace('#[^\pL\pM\pN\p{Pi}\p{Pf}\'+-.,]+#mui', ' ', $input); - $input = preg_replace('#(^|\s)[+-,]+([\pL\pM]+)#mui', ' $1', $input); - $input = preg_replace('#([\pL\pM\pN]+)[+-.,]+(\s|$)#mui', '$1 ', $input); - $input = preg_replace('#([\pL\pM]+)[+.,]+([\pL\pM]+)#muiU', '$1 $2', $input); - $input = preg_replace('#(^|\s)[\'+-.,]+(\s|$)#mui', ' ', $input); - $input = preg_replace('#(^|\s)[\p{Pi}\p{Pf}]+(\s|$)#mui', ' ', $input); - $input = preg_replace('#[' . $quotes . ']+#mui', '\'', $input); - $input = preg_replace('#\s+#mui', ' ', $input); - $input = trim($input); + $input = preg_replace('#(^|\s)[+-,]+([\pL\pM]+)#mui', ' $1', (string) $input); + $input = preg_replace('#([\pL\pM\pN]+)[+-.,]+(\s|$)#mui', '$1 ', (string) $input); + $input = preg_replace('#([\pL\pM]+)[+.,]+([\pL\pM]+)#muiU', '$1 $2', (string) $input); + $input = preg_replace('#(^|\s)[\'+-.,]+(\s|$)#mui', ' ', (string) $input); + $input = preg_replace('#(^|\s)[\p{Pi}\p{Pf}]+(\s|$)#mui', ' ', (string) $input); + $input = preg_replace('#[' . $quotes . ']+#mui', "'", (string) $input); + $input = preg_replace('#\s+#mui', ' ', (string) $input); + $input = trim((string) $input); // Explode the normalized string to get the terms. $terms = explode(' ', $input); diff --git a/administrator/components/com_finder/src/Indexer/Language/El.php b/administrator/components/com_finder/src/Indexer/Language/El.php index a99a38178993c..f445b30c9cd91 100644 --- a/administrator/components/com_finder/src/Indexer/Language/El.php +++ b/administrator/components/com_finder/src/Indexer/Language/El.php @@ -40,7 +40,7 @@ class El extends Language * * @since 4.0.0 */ - public function __construct($locale = null) + public function __construct() { // Override parent constructor since we don't need to load an external stemmer } @@ -184,9 +184,7 @@ public function stem($token) $exceptS2 = '/^(ΑΝ|ΑΦ|ΓΕ|ΓΙΓΑΝΤΟΑΦ|ΓΚΕ|ΔΗΜΟΚΡΑΤ|ΚΟΜ|ΓΚ|Μ|Π|ΠΟΥΚΑΜ|ΟΛΟ|ΛΑΡ)$/'; if ($token == "ΙΣΑ") { - $token = "ΙΣ"; - - return $token; + return "ΙΣ"; } if (preg_match($re, $token, $match)) { @@ -403,7 +401,7 @@ public function stem($token) $token = $match[1]; $re = '/(ΟΚ|ΜΑΜ|ΜΑΝ|ΜΠΑΜΠ|ΠΑΤΕΡ|ΓΙΑΓΙ|ΝΤΑΝΤ|ΚΥΡ|ΘΕΙ|ΠΕΘΕΡ)$/'; - if (!preg_match($re, $token)) { + if (\in_array(preg_match($re, $token), [0, false], true)) { $token .= "ΑΔ"; } } @@ -669,7 +667,7 @@ public function stem($token) if ( (preg_match($exept18, $token) || preg_match($exept19, $token)) - && !(preg_match($exept17, $token) || preg_match($exept20, $token)) + && (\in_array(preg_match($exept17, $token), [0, false], true) && \in_array(preg_match($exept20, $token), [0, false], true)) ) { $token .= "ΑΓ"; } diff --git a/administrator/components/com_finder/src/Indexer/Language/Zh.php b/administrator/components/com_finder/src/Indexer/Language/Zh.php index 5e8217e1d3301..8eb4ee8a626a9 100644 --- a/administrator/components/com_finder/src/Indexer/Language/Zh.php +++ b/administrator/components/com_finder/src/Indexer/Language/Zh.php @@ -44,7 +44,7 @@ class Zh extends Language * * @since 4.0.0 */ - public function __construct($locale = null) + public function __construct() { // Override parent constructor since we don't need to load an external stemmer } diff --git a/administrator/components/com_finder/src/Indexer/Parser.php b/administrator/components/com_finder/src/Indexer/Parser.php index 76b58e3b70bdb..6e55d9953ddfd 100644 --- a/administrator/components/com_finder/src/Indexer/Parser.php +++ b/administrator/components/com_finder/src/Indexer/Parser.php @@ -52,7 +52,7 @@ public static function getInstance($format) } // Setup the adapter for the parser. - $class = '\\Joomla\\Component\\Finder\\Administrator\\Indexer\\Parser\\' . ucfirst($format); + $class = '\\Joomla\\Component\\Finder\\Administrator\\Indexer\\Parser\\' . ucfirst((string) $format); // Check if a parser exists for the format. if (class_exists($class)) { diff --git a/administrator/components/com_finder/src/Indexer/Parser/Html.php b/administrator/components/com_finder/src/Indexer/Parser/Html.php index ac569bbe45117..5241823d852b4 100644 --- a/administrator/components/com_finder/src/Indexer/Parser/Html.php +++ b/administrator/components/com_finder/src/Indexer/Parser/Html.php @@ -77,7 +77,7 @@ public function parse($input) ')\b/i', ' $1$2', $input); // Strip HTML tags. - $input = strip_tags($input); + $input = strip_tags((string) $input); return parent::parse($input); } diff --git a/administrator/components/com_finder/src/Indexer/Parser/Rtf.php b/administrator/components/com_finder/src/Indexer/Parser/Rtf.php index 2fcbdbf3e097e..a0d73ab5635e1 100644 --- a/administrator/components/com_finder/src/Indexer/Parser/Rtf.php +++ b/administrator/components/com_finder/src/Indexer/Parser/Rtf.php @@ -40,8 +40,7 @@ protected function process($input) // Remove control characters. $input = str_replace(['{', '}', "\\\n"], [' ', ' ', "\n"], $input); $input = preg_replace('#\\\([^;]+?);#m', ' ', $input); - $input = preg_replace('#\\\[\'a-zA-Z0-9]+#mi', ' ', $input); - return $input; + return preg_replace('#\\\[\'a-zA-Z0-9]+#mi', ' ', (string) $input); } } diff --git a/administrator/components/com_finder/src/Indexer/Query.php b/administrator/components/com_finder/src/Indexer/Query.php index 61b1bd4cd9b5f..b4c4e81438955 100644 --- a/administrator/components/com_finder/src/Indexer/Query.php +++ b/administrator/components/com_finder/src/Indexer/Query.php @@ -207,8 +207,8 @@ class Query */ public function __construct($options, ?DatabaseInterface $db = null) { - if ($db === null) { - @trigger_error(\sprintf('Database will be mandatory in 5.0.'), E_USER_DEPRECATED); + if (!$db instanceof DatabaseInterface) { + @trigger_error('Database will be mandatory in 5.0.', E_USER_DEPRECATED); $db = Factory::getContainer()->get(DatabaseInterface::class); } @@ -221,13 +221,13 @@ public function __construct($options, ?DatabaseInterface $db = null) $this->empty = !empty($options['empty']); // Get the input language. - $this->language = !empty($options['language']) ? $options['language'] : Helper::getDefaultLanguage(); + $this->language = empty($options['language']) ? Helper::getDefaultLanguage() : $options['language']; // Get the matching mode. $this->mode = 'AND'; // Set the word matching mode - $this->wordmode = !empty($options['word_match']) ? $options['word_match'] : 'exact'; + $this->wordmode = empty($options['word_match']) ? 'exact' : $options['word_match']; // Initialize the temporary date storage. $this->dates = new Registry(); @@ -286,7 +286,7 @@ public function __construct($options, ?DatabaseInterface $db = null) // Check if we have a query string. if (!empty($this->input)) { $this->search = true; - } elseif ($this->empty && (!empty($this->filter) || !empty($this->filters) || !empty($this->date1) || !empty($this->date2))) { + } elseif ($this->empty && (!empty($this->filter) || $this->filters !== [] || !empty($this->date1) || !empty($this->date2))) { // Check if we can search without a query string. $this->search = true; } else { @@ -418,7 +418,7 @@ public function getIncludedTermIds() // Iterate through the included tokens and compile the matching terms. foreach ($this->included as $item) { // Check if we have any terms. - if (empty($item->matches)) { + if ($item->matches === []) { continue; } @@ -537,12 +537,12 @@ protected function processStaticTaxonomy($filterId) $filters = ArrayHelper::toInteger($filters); // Remove any values of zero. - if (\in_array(0, $filters, true) !== false) { + if (\in_array(0, $filters, true)) { unset($filters[array_search(0, $filters, true)]); } // Check if we have any real input. - if (empty($filters)) { + if ($filters === []) { return true; } @@ -597,12 +597,12 @@ protected function processDynamicTaxonomy($filters) $filters = ArrayHelper::toInteger($filters); // Remove any values of zero. - if (\in_array(0, $filters, true) !== false) { + if (\in_array(0, $filters, true)) { unset($filters[array_search(0, $filters, true)]); } // Check if we have any real input. - if (empty($filters)) { + if ($filters === []) { return true; } @@ -741,7 +741,8 @@ protected function processString($input, $lang, $mode) $input = html_entity_decode($input, ENT_QUOTES, 'UTF-8'); $input = StringHelper::strtolower($input); $input = preg_replace('#\s+#mi', ' ', $input); - $input = trim($input); + $input = trim((string) $input); + $debug = Factory::getApplication()->get('debug_lang'); $params = ComponentHelper::getParams('com_finder'); @@ -847,7 +848,7 @@ protected function processString($input, $lang, $mode) // Clean up the input string again. $input = str_replace($matches[0], '', $input); $input = preg_replace('#\s+#mi', ' ', $input); - $input = trim($input); + $input = trim((string) $input); } } @@ -871,7 +872,7 @@ protected function processString($input, $lang, $mode) $len = StringHelper::strlen($matches[0][$key]); // Add any terms that are before this phrase to the stack. - if (trim(StringHelper::substr($input, 0, $pos))) { + if (trim(StringHelper::substr($input, 0, $pos)) !== '' && trim(StringHelper::substr($input, 0, $pos)) !== '0') { $terms = array_merge($terms, explode(' ', trim(StringHelper::substr($input, 0, $pos)))); } @@ -880,7 +881,7 @@ protected function processString($input, $lang, $mode) // Clean up the input string again. $input = preg_replace('#\s+#mi', ' ', $input); - $input = trim($input); + $input = trim((string) $input); // Get the number of words in the phrase. $parts = explode(' ', $match); @@ -892,7 +893,7 @@ protected function processString($input, $lang, $mode) $parts = \array_slice($parts, $tuplecount); // If the chunk is not empty, add it as a phrase. - if (\count($chunk)) { + if ($chunk !== []) { $phrases[] = implode(' ', $chunk); $terms[] = implode(' ', $chunk); } @@ -910,7 +911,7 @@ protected function processString($input, $lang, $mode) $chunk[] = array_shift($parts); // If the chunk is not empty, add it as a phrase. - if (\count($chunk)) { + if ($chunk !== []) { $phrases[] = implode(' ', $chunk); $terms[] = implode(' ', $chunk); } @@ -1149,7 +1150,7 @@ protected function processString($input, $lang, $mode) // Tokenize the phrase. $token = Helper::tokenize($phrases[$i], $lang, true); - if (!\count($token)) { + if (\count($token) === 0) { continue; } @@ -1204,7 +1205,7 @@ protected function processString($input, $lang, $mode) } // Set the required flag for the token. - $token->required = $mode === 'AND' ? (!$token->phrase) : false; + $token->required = $mode === 'AND' && !$token->phrase; // Add the token to the appropriate stack. if ($token->required || (bool) $token->matches) { @@ -1272,7 +1273,7 @@ protected function getTokenData($token) ->bind(':searchStem', $searchStem, ParameterType::STRING); $query->where('t.phrase = 0') - ->where('t.language IN (\'*\',' . $db->quote($token->language) . ')'); + ->where("t.language IN ('*'," . $db->quote($token->language) . ')'); } // Get the terms. @@ -1292,7 +1293,7 @@ protected function getTokenData($token) } // If no matches were found, try to find a similar but better token. - if (empty($token->matches)) { + if ($token->matches === []) { // Create a database query to get the similar terms. $query->clear() ->select('DISTINCT t.term_id AS id, t.term AS term') diff --git a/administrator/components/com_finder/src/Indexer/Result.php b/administrator/components/com_finder/src/Indexer/Result.php index 6b8911227c968..05dce68431352 100644 --- a/administrator/components/com_finder/src/Indexer/Result.php +++ b/administrator/components/com_finder/src/Indexer/Result.php @@ -351,7 +351,7 @@ public function removeInstruction($group, $property) // Check if the group exists. We can't remove instructions for unknown groups. if (\array_key_exists($group, $this->instructions)) { // Search for the property in the group. - $key = array_search($property, $this->instructions[$group]); + $key = array_search($property, $this->instructions[$group], true); // If the property was found, remove it. if ($key !== false) { @@ -395,7 +395,7 @@ public function getTaxonomy($branch = null) public function addTaxonomy($branch, $title, $state = 1, $access = 1, $language = '*') { // We can't add taxonomies with empty titles - if (!trim($title)) { + if (trim($title) === '' || trim($title) === '0') { return; } @@ -430,7 +430,7 @@ public function addTaxonomy($branch, $title, $state = 1, $access = 1, $language public function addNestedTaxonomy($branch, ImmutableNodeInterface $contentNode, $state = 1, $access = 1, $language = '*') { // We can't add taxonomies with empty titles - if (!trim($contentNode->title)) { + if (trim($contentNode->title) === '' || trim($contentNode->title) === '0') { return; } diff --git a/administrator/components/com_finder/src/Indexer/Taxonomy.php b/administrator/components/com_finder/src/Indexer/Taxonomy.php index 6808f23dacc23..20d0d49c15412 100644 --- a/administrator/components/com_finder/src/Indexer/Taxonomy.php +++ b/administrator/components/com_finder/src/Indexer/Taxonomy.php @@ -284,9 +284,10 @@ public static function addMap($linkId, $nodeId) ->where($db->quoteName('node_id') . ' = ' . (int) $nodeId); $db->setQuery($query); $db->execute(); + $id = (int) $db->loadResult(); - if (!$id) { + if ($id === 0) { $map = new \stdClass(); $map->link_id = (int) $linkId; $map->node_id = (int) $nodeId; @@ -357,6 +358,7 @@ public static function getNodeByTitle($branch, $title) // Get the node. $query->setLimit(1); + $db->setQuery($query); return $db->loadObject(); @@ -405,9 +407,8 @@ public static function removeOrphanMaps() ->where($db->quoteName('link_id') . ' NOT IN (' . $query2 . ')'); $db->setQuery($query); $db->execute(); - $count = $db->getAffectedRows(); - return $count; + return $db->getAffectedRows(); } /** @@ -439,7 +440,7 @@ public static function removeOrphanNodes() $db->setQuery($query); $nodes = $db->loadColumn(); - if (!\count($nodes)) { + if (\count($nodes) === 0) { break; } @@ -465,7 +466,7 @@ public static function removeOrphanNodes() */ public static function getTaxonomy($id = 0) { - if (!\count(self::$taxonomies)) { + if (\count(self::$taxonomies) === 0) { $db = Factory::getDbo(); $query = $db->getQuery(true); @@ -481,11 +482,7 @@ public static function getTaxonomy($id = 0) return self::$taxonomies; } - if (isset(self::$taxonomies[$id])) { - return self::$taxonomies[$id]; - } - - return false; + return self::$taxonomies[$id] ?? false; } /** @@ -499,7 +496,7 @@ public static function getTaxonomy($id = 0) */ public static function getBranch($title = '') { - if (!\count(self::$branches)) { + if (\count(self::$branches) === 0) { $taxonomies = self::getTaxonomy(); foreach ($taxonomies as $t) { @@ -513,10 +510,6 @@ public static function getBranch($title = '') return self::$branches; } - if (isset(self::$branches[$title])) { - return self::$branches[$title]; - } - - return false; + return self::$branches[$title] ?? false; } } diff --git a/administrator/components/com_finder/src/Indexer/Token.php b/administrator/components/com_finder/src/Indexer/Token.php index cc4147dd60a2b..0ba2ffc688614 100644 --- a/administrator/components/com_finder/src/Indexer/Token.php +++ b/administrator/components/com_finder/src/Indexer/Token.php @@ -135,18 +135,14 @@ class Token */ public function __construct($term, $lang, $spacer = ' ') { - if (!$lang) { - $this->language = '*'; - } else { - $this->language = $lang; - } + $this->language = $lang ?: '*'; // Tokens can be a single word or an array of words representing a phrase. if (\is_array($term)) { // Populate the token instance. $langs = array_fill(0, \count($term), $lang); $this->term = implode($spacer, $term); - $this->stem = implode($spacer, array_map([Helper::class, 'stem'], $term, $langs)); + $this->stem = implode($spacer, array_map(Helper::stem(...), $term, $langs)); $this->numeric = false; $this->common = false; $this->phrase = true; @@ -164,7 +160,7 @@ public function __construct($term, $lang, $spacer = ' ') // Populate the token instance. $this->term = $term; $this->stem = Helper::stem($this->term, $lang); - $this->numeric = (is_numeric($this->term) || (bool) preg_match('#^[0-9,.\-\+]+$#', $this->term)); + $this->numeric = (is_numeric($this->term) || (bool) preg_match('#^[0-9,.\-\+]+$#', (string) $this->term)); $this->common = $this->numeric ? false : Helper::isCommon($this->term, $lang); $this->phrase = false; $this->length = StringHelper::strlen($this->term); @@ -179,7 +175,7 @@ public function __construct($term, $lang, $spacer = ' ') */ $this->weight = min($this->length, 15) / 15; $this->weight = $this->common === true ? $this->weight / 8 : $this->weight; - $this->weight = $this->numeric === true ? $this->weight * 1.5 : $this->weight; + $this->weight = $this->numeric ? $this->weight * 1.5 : $this->weight; $this->weight = round($this->weight, 4); } } diff --git a/administrator/components/com_finder/src/Model/FiltersModel.php b/administrator/components/com_finder/src/Model/FiltersModel.php index ec05f535ba67e..acf14008c3235 100644 --- a/administrator/components/com_finder/src/Model/FiltersModel.php +++ b/administrator/components/com_finder/src/Model/FiltersModel.php @@ -77,7 +77,7 @@ protected function getListQuery() // Check for a search filter. if ($search = $this->getState('filter.search')) { - $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%')); + $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim((string) $search), true) . '%')); $query->where($db->quoteName('a.title') . ' LIKE ' . $search); } diff --git a/administrator/components/com_finder/src/Model/IndexModel.php b/administrator/components/com_finder/src/Model/IndexModel.php index e6dbe7da260fc..e1f0433f50dd1 100644 --- a/administrator/components/com_finder/src/Model/IndexModel.php +++ b/administrator/components/com_finder/src/Model/IndexModel.php @@ -16,6 +16,7 @@ use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\CMS\MVC\Model\ListModel; use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\Table\Table; use Joomla\Database\QueryInterface; // phpcs:disable PSR1.Files.SideEffects @@ -223,11 +224,11 @@ protected function getListQuery() $search = $this->getState('filter.search'); if (!empty($search)) { - $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%')); + $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim((string) $search), true) . '%')); $orSearchSql = $db->quoteName('l.title') . ' LIKE ' . $search . ' OR ' . $db->quoteName('l.url') . ' LIKE ' . $search; // Filter by indexdate only if $search doesn't contains non-ascii characters - if (!preg_match('/[^\x00-\x7F]/', $search)) { + if (\in_array(preg_match('/[^\x00-\x7F]/', $search), [0, false], true)) { $orSearchSql .= ' OR ' . $query->castAsChar($db->quoteName('l.indexdate')) . ' LIKE ' . $search; } @@ -319,7 +320,7 @@ public function getTotalIndexed() * @param string $prefix A prefix for the table class name. [optional] * @param array $config Configuration array for model. [optional] * - * @return \Joomla\CMS\Table\Table A database object + * @return Table A database object * * @since 2.5 */ @@ -354,6 +355,7 @@ public function purge() // Truncate the taxonomy table and insert the root node. $db->truncateTable('#__finder_taxonomy'); + $root = (object) [ 'id' => 1, 'parent_id' => 0, diff --git a/administrator/components/com_finder/src/Model/MapsModel.php b/administrator/components/com_finder/src/Model/MapsModel.php index 98231c4d188bf..12d58756ef639 100644 --- a/administrator/components/com_finder/src/Model/MapsModel.php +++ b/administrator/components/com_finder/src/Model/MapsModel.php @@ -16,6 +16,7 @@ use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\CMS\MVC\Model\ListModel; use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\Table\Table; use Joomla\Database\DatabaseQuery; use Joomla\Database\QueryInterface; @@ -210,7 +211,7 @@ protected function getListQuery() // Filter the maps over the search string if set. if ($search = $this->getState('filter.search')) { - $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%')); + $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim((string) $search), true) . '%')); $query->where('a.title LIKE ' . $search); } @@ -268,7 +269,7 @@ protected function getStoreId($id = '') * @param string $prefix A prefix for the table class name. [optional] * @param array $config Configuration array for model. [optional] * - * @return \Joomla\CMS\Table\Table A database object + * @return Table A database object * * @since 2.5 */ diff --git a/administrator/components/com_finder/src/Model/SearchesModel.php b/administrator/components/com_finder/src/Model/SearchesModel.php index 5cdff1385b1c2..ebb05b5d61c93 100644 --- a/administrator/components/com_finder/src/Model/SearchesModel.php +++ b/administrator/components/com_finder/src/Model/SearchesModel.php @@ -118,7 +118,7 @@ protected function getListQuery() // Filter by search in title if ($search = $this->getState('filter.search')) { - $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%')); + $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim((string) $search), true) . '%')); $query->where($db->quoteName('a.searchterm') . ' LIKE ' . $search); } @@ -140,11 +140,7 @@ public function getItems() $items = parent::getItems(); foreach ($items as $item) { - if (\is_resource($item->query)) { - $item->query = unserialize(stream_get_contents($item->query)); - } else { - $item->query = unserialize($item->query); - } + $item->query = \is_resource($item->query) ? unserialize(stream_get_contents($item->query)) : unserialize($item->query); } return $items; @@ -163,8 +159,8 @@ public function reset() try { $db->truncateTable('#__finder_logging'); - } catch (\RuntimeException $e) { - $this->setError($e->getMessage()); + } catch (\RuntimeException $runtimeException) { + $this->setError($runtimeException->getMessage()); return false; } diff --git a/administrator/components/com_finder/src/Model/StatisticsModel.php b/administrator/components/com_finder/src/Model/StatisticsModel.php index 8845712b15b58..629044562271d 100644 --- a/administrator/components/com_finder/src/Model/StatisticsModel.php +++ b/administrator/components/com_finder/src/Model/StatisticsModel.php @@ -78,8 +78,9 @@ public function getData() $plugins = PluginHelper::getPlugin('finder'); foreach ($plugins as $plugin) { - $lang->load('plg_finder_' . $plugin->name . '.sys', JPATH_ADMINISTRATOR) - || $lang->load('plg_finder_' . $plugin->name . '.sys', JPATH_PLUGINS . '/finder/' . $plugin->name); + if (!$lang->load('plg_finder_' . $plugin->name . '.sys', JPATH_ADMINISTRATOR)) { + $lang->load('plg_finder_' . $plugin->name . '.sys', JPATH_PLUGINS . '/finder/' . $plugin->name); + } } return $data; diff --git a/administrator/components/com_finder/src/Response/Response.php b/administrator/components/com_finder/src/Response/Response.php index 28dc80ffeb5e5..e2bfa375c9483 100644 --- a/administrator/components/com_finder/src/Response/Response.php +++ b/administrator/components/com_finder/src/Response/Response.php @@ -152,7 +152,7 @@ public function __construct($state) // Log the error try { Log::add($state->getMessage(), Log::ERROR); - } catch (\RuntimeException $exception) { + } catch (\RuntimeException) { // Informational log only } @@ -170,8 +170,8 @@ public function __construct($state) $this->startTime = $state->startTime; $this->endTime = Factory::getDate()->toSql(); - $this->start = !empty($state->start) ? (int) $state->start : 0; - $this->complete = !empty($state->complete) ? (int) $state->complete : 0; + $this->start = empty($state->start) ? 0 : (int) $state->start; + $this->complete = empty($state->complete) ? 0 : (int) $state->complete; // Set the appropriate messages. if ($this->totalItems <= 0 && $this->complete) { diff --git a/administrator/components/com_finder/src/Service/HTML/Filter.php b/administrator/components/com_finder/src/Service/HTML/Filter.php index 7e511918dd9c1..019b18011058a 100644 --- a/administrator/components/com_finder/src/Service/HTML/Filter.php +++ b/administrator/components/com_finder/src/Service/HTML/Filter.php @@ -14,6 +14,7 @@ use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Text; +use Joomla\CMS\WebAsset\WebAssetManager; use Joomla\Component\Finder\Administrator\Helper\LanguageHelper; use Joomla\Component\Finder\Administrator\Indexer\Query; use Joomla\Database\DatabaseAwareTrait; @@ -69,7 +70,7 @@ public function slider($options = []) try { $filter = $db->loadObject(); - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { return null; } @@ -100,7 +101,7 @@ public function slider($options = []) try { $branches = $db->loadObjectList('id'); - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { return null; } @@ -141,7 +142,7 @@ public function slider($options = []) try { $nodes = $db->loadObjectList('id'); - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { return null; } @@ -191,9 +192,7 @@ public function slider($options = []) $html .= HTMLHelper::_('bootstrap.endSlide'); } - $html .= HTMLHelper::_('bootstrap.endAccordion'); - - return $html; + return $html . HTMLHelper::_('bootstrap.endAccordion'); } /** @@ -238,7 +237,7 @@ public function select($idxQuery, $options) try { $filter = $db->loadObject(); - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { return null; } @@ -273,7 +272,7 @@ public function select($idxQuery, $options) try { $branches = $db->loadObjectList('id'); - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { return null; } @@ -321,7 +320,7 @@ public function select($idxQuery, $options) try { $bv->nodes = $db->loadObjectList('id'); - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { return null; } @@ -412,9 +411,7 @@ public function select($idxQuery, $options) $html .= ''; } - $html .= ''; - - return $html; + return $html . ''; } /** @@ -445,7 +442,7 @@ public function dates($idxQuery, $options) // Load the CSS/JS resources. if ($loadMedia) { - /** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */ + /** @var WebAssetManager $wa */ $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); $wa->useStyle('com_finder.dates'); } diff --git a/administrator/components/com_finder/src/Service/HTML/Finder.php b/administrator/components/com_finder/src/Service/HTML/Finder.php index 642fcf86f5846..cfa362bdcc48c 100644 --- a/administrator/components/com_finder/src/Service/HTML/Finder.php +++ b/administrator/components/com_finder/src/Service/HTML/Finder.php @@ -50,7 +50,7 @@ public function typeslist() try { $rows = $db->loadObjectList(); - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { return []; } @@ -87,8 +87,8 @@ public function mapslist() try { $branches = $db->loadObjectList(); - } catch (\RuntimeException $e) { - Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); + } catch (\RuntimeException $runtimeException) { + Factory::getApplication()->enqueueMessage($runtimeException->getMessage(), 'error'); } // Translate. diff --git a/administrator/components/com_finder/src/Service/HTML/Query.php b/administrator/components/com_finder/src/Service/HTML/Query.php index 2f2a6ffaafa50..5c6d83ee41434 100644 --- a/administrator/components/com_finder/src/Service/HTML/Query.php +++ b/administrator/components/com_finder/src/Service/HTML/Query.php @@ -41,21 +41,21 @@ public static function explained(IndexerQuery $query) // Process the required tokens. foreach ($query->included as $token) { - if ($token->required && (!isset($token->derived) || $token->derived == false)) { + if ($token->required && ($token->derived === null || $token->derived == false)) { $parts[] = '' . Text::sprintf('COM_FINDER_QUERY_TOKEN_REQUIRED', $token->term) . ''; } } // Process the optional tokens. foreach ($query->included as $token) { - if (!$token->required && (!isset($token->derived) || $token->derived == false)) { + if (!$token->required && ($token->derived === null || $token->derived == false)) { $parts[] = '' . Text::sprintf('COM_FINDER_QUERY_TOKEN_OPTIONAL', $token->term) . ''; } } // Process the excluded tokens. foreach ($query->excluded as $token) { - if (!isset($token->derived) || $token->derived === false) { + if ($token->derived === null || $token->derived === false) { $parts[] = '' . Text::sprintf('COM_FINDER_QUERY_TOKEN_EXCLUDED', $token->term) . ''; } } @@ -75,7 +75,7 @@ public static function explained(IndexerQuery $query) } // Process the taxonomy filters. - if (!empty($query->filters)) { + if ($query->filters !== []) { // Get the filters in the request. $t = Factory::getApplication()->getInput()->request->get('t', [], 'array'); @@ -106,7 +106,7 @@ public static function explained(IndexerQuery $query) } // Build the interpreted query. - return \count($parts) ? implode(Text::_('COM_FINDER_QUERY_TOKEN_GLUE'), $parts) : null; + return $parts !== [] ? implode(Text::_('COM_FINDER_QUERY_TOKEN_GLUE'), $parts) : null; } /** @@ -133,14 +133,14 @@ public static function suggested(IndexerQuery $query) // Replace the ignored keyword suggestions. foreach (array_reverse($query->ignored) as $token) { - if (isset($token->suggestion)) { + if ($token->suggestion !== null) { $suggested = str_ireplace($token->term, $token->suggestion, $suggested); } } // Replace the included keyword suggestions. foreach (array_reverse($query->included) as $token) { - if (isset($token->suggestion)) { + if ($token->suggestion !== null) { $suggested = str_ireplace($token->term, $token->suggestion, $suggested); } } diff --git a/administrator/components/com_finder/src/Table/FilterTable.php b/administrator/components/com_finder/src/Table/FilterTable.php index 6c352635379ab..c35525bc5fbe1 100644 --- a/administrator/components/com_finder/src/Table/FilterTable.php +++ b/administrator/components/com_finder/src/Table/FilterTable.php @@ -78,8 +78,8 @@ public function check() { try { parent::check(); - } catch (\Exception $e) { - $this->setError($e->getMessage()); + } catch (\Exception $exception) { + $this->setError($exception->getMessage()); return false; } @@ -129,7 +129,7 @@ public function store($updateNulls = true) $userId = $this->getCurrentUser()->id; // Set created date if not set. - if (!(int) $this->created) { + if ((int) $this->created === 0) { $this->created = $date; } @@ -142,7 +142,7 @@ public function store($updateNulls = true) $this->created_by = $userId; } - if (!(int) $this->modified) { + if ((int) $this->modified === 0) { $this->modified = $this->created; } diff --git a/administrator/components/com_finder/src/Table/MapTable.php b/administrator/components/com_finder/src/Table/MapTable.php index 9f3dada7cdcda..b7457d161d071 100644 --- a/administrator/components/com_finder/src/Table/MapTable.php +++ b/administrator/components/com_finder/src/Table/MapTable.php @@ -56,14 +56,14 @@ public function check() { try { parent::check(); - } catch (\Exception $e) { - $this->setError($e->getMessage()); + } catch (\Exception $exception) { + $this->setError($exception->getMessage()); return false; } // Check for a title. - if (trim($this->title) == '') { + if (trim($this->title) === '') { $this->setError(Text::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_CATEGORY')); return false; @@ -71,7 +71,7 @@ public function check() $this->alias = ApplicationHelper::stringURLSafe($this->title, $this->language); - if (trim($this->alias) == '') { + if (trim($this->alias) === '') { $this->alias = md5(serialize($this->getProperties())); } diff --git a/administrator/components/com_finder/src/View/Filter/HtmlView.php b/administrator/components/com_finder/src/View/Filter/HtmlView.php index dc0cbebf16502..05c1bf001f43a 100644 --- a/administrator/components/com_finder/src/View/Filter/HtmlView.php +++ b/administrator/components/com_finder/src/View/Filter/HtmlView.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Finder\Administrator\View\Filter; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; @@ -18,6 +19,8 @@ use Joomla\CMS\Toolbar\Toolbar; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Finder\Administrator\Model\FilterModel; +use Joomla\Component\Finder\Administrator\Table\FilterTable; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -33,7 +36,7 @@ class HtmlView extends BaseHtmlView /** * The filter object * - * @var \Joomla\Component\Finder\Administrator\Table\FilterTable + * @var FilterTable * * @since 3.6.2 */ @@ -42,7 +45,7 @@ class HtmlView extends BaseHtmlView /** * The Form object * - * @var \Joomla\CMS\Form\Form + * @var Form * * @since 3.6.2 */ @@ -60,7 +63,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry * * @since 3.6.2 */ @@ -106,7 +109,7 @@ public function display($tpl = null) $this->total = $model->getTotal(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -128,7 +131,7 @@ protected function addToolbar() Factory::getApplication()->getInput()->set('hidemainmenu', true); $isNew = ($this->item->filter_id == 0); - $checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $this->getCurrentUser()->id); + $checkedOut = !\is_null($this->item->checked_out) && $this->item->checked_out != $this->getCurrentUser()->id; $canDo = ContentHelper::getActions('com_finder'); $toolbar = $this->getDocument()->getToolbar(); diff --git a/administrator/components/com_finder/src/View/Filters/HtmlView.php b/administrator/components/com_finder/src/View/Filters/HtmlView.php index 2bf2d1d8315c8..d41b8d55f02cf 100644 --- a/administrator/components/com_finder/src/View/Filters/HtmlView.php +++ b/administrator/components/com_finder/src/View/Filters/HtmlView.php @@ -10,13 +10,16 @@ namespace Joomla\Component\Finder\Administrator\View\Filters; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Toolbar\Button\DropdownButton; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Finder\Administrator\Model\FiltersModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -41,7 +44,7 @@ class HtmlView extends BaseHtmlView /** * The pagination object * - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination * * @since 3.6.1 */ @@ -50,7 +53,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry * * @since 3.6.1 */ @@ -68,7 +71,7 @@ class HtmlView extends BaseHtmlView /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form * * @since 4.0.0 */ @@ -117,7 +120,7 @@ public function display($tpl = null) } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_finder/src/View/Index/HtmlView.php b/administrator/components/com_finder/src/View/Index/HtmlView.php index 04e1e72c229de..857b700cf0bde 100644 --- a/administrator/components/com_finder/src/View/Index/HtmlView.php +++ b/administrator/components/com_finder/src/View/Index/HtmlView.php @@ -10,11 +10,13 @@ namespace Joomla\Component\Finder\Administrator\View\Index; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Toolbar\Button\DropdownButton; use Joomla\CMS\Toolbar\ToolbarHelper; @@ -45,7 +47,7 @@ class HtmlView extends BaseHtmlView /** * The pagination object * - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination * * @since 3.6.1 */ @@ -90,7 +92,7 @@ class HtmlView extends BaseHtmlView /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form * * @since 4.0.0 */ @@ -148,7 +150,7 @@ public function display($tpl = null) } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_finder/src/View/Maps/HtmlView.php b/administrator/components/com_finder/src/View/Maps/HtmlView.php index 901b2c8809075..85e8b78676b05 100644 --- a/administrator/components/com_finder/src/View/Maps/HtmlView.php +++ b/administrator/components/com_finder/src/View/Maps/HtmlView.php @@ -10,14 +10,17 @@ namespace Joomla\Component\Finder\Administrator\View\Maps; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Toolbar\Button\DropdownButton; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Finder\Administrator\Helper\LanguageHelper; use Joomla\Component\Finder\Administrator\Model\MapsModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -42,7 +45,7 @@ class HtmlView extends BaseHtmlView /** * The pagination object * - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination * * @since 3.6.1 */ @@ -51,7 +54,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry * * @since 3.6.1 */ @@ -69,7 +72,7 @@ class HtmlView extends BaseHtmlView /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form * * @since 4.0.0 */ @@ -121,7 +124,7 @@ public function display($tpl = null) } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_finder/src/View/Searches/HtmlView.php b/administrator/components/com_finder/src/View/Searches/HtmlView.php index 5abd14815b037..6a2223bad79ea 100644 --- a/administrator/components/com_finder/src/View/Searches/HtmlView.php +++ b/administrator/components/com_finder/src/View/Searches/HtmlView.php @@ -11,15 +11,18 @@ namespace Joomla\Component\Finder\Administrator\View\Searches; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Router\Route; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\CMS\Uri\Uri; use Joomla\Component\Finder\Administrator\Model\SearchesModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -49,21 +52,21 @@ class HtmlView extends BaseHtmlView /** * The pagination object * - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination */ protected $pagination; /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $state; /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form * * @since 4.0.0 */ @@ -81,7 +84,7 @@ class HtmlView extends BaseHtmlView /** * The actions the user is authorised to perform * - * @var \Joomla\Registry\Registry + * @var Registry * * @since 4.0.0 */ @@ -118,12 +121,12 @@ public function display($tpl = null) $link = 'index.php?option=com_config&view=component&component=com_finder&return=' . base64_encode($uri); $output = HTMLHelper::_('link', Route::_($link), Text::_('JOPTIONS')); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + if (\count($this->items) === 0 && $this->isEmptyState = $model->getIsEmptyState()) { $this->setLayout('emptystate'); } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_finder/src/View/Statistics/HtmlView.php b/administrator/components/com_finder/src/View/Statistics/HtmlView.php index 4c82a67e0c588..c19428d66b3e7 100644 --- a/administrator/components/com_finder/src/View/Statistics/HtmlView.php +++ b/administrator/components/com_finder/src/View/Statistics/HtmlView.php @@ -12,6 +12,7 @@ use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Object\CMSObject; use Joomla\Component\Finder\Administrator\Model\StatisticsModel; // phpcs:disable PSR1.Files.SideEffects @@ -28,7 +29,7 @@ class HtmlView extends BaseHtmlView /** * The index statistics * - * @var \Joomla\CMS\Object\CMSObject + * @var CMSObject * * @since 3.6.1 */ @@ -52,7 +53,7 @@ public function display($tpl = null) $this->data = $model->getData(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_finder/tmpl/filters/emptystate.php b/administrator/components/com_finder/tmpl/filters/emptystate.php index 416a26b972689..fd6f904d70f00 100644 --- a/administrator/components/com_finder/tmpl/filters/emptystate.php +++ b/administrator/components/com_finder/tmpl/filters/emptystate.php @@ -1,5 +1,7 @@ 'COM_FINDER', 'formURL' => 'index.php?option=com_finder&view=filters', diff --git a/administrator/components/com_finder/tmpl/index/emptystate.php b/administrator/components/com_finder/tmpl/index/emptystate.php index dfbca2996ae6c..872750b839377 100644 --- a/administrator/components/com_finder/tmpl/index/emptystate.php +++ b/administrator/components/com_finder/tmpl/index/emptystate.php @@ -1,5 +1,8 @@ 'COM_FINDER', 'formURL' => 'index.php?option=com_finder&view=index', @@ -32,7 +34,7 @@ // Show warning that the content - finder plugin is disabled if ($this->finderPluginId) { - /** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */ + /** @var WebAssetManager $wa */ $wa = $this->getDocument()->getWebAssetManager(); $wa->useScript('joomla.dialog-autocreate'); diff --git a/administrator/components/com_finder/tmpl/maps/default.php b/administrator/components/com_finder/tmpl/maps/default.php index 2b9ca870ffecc..0cc87fc036e0e 100644 --- a/administrator/components/com_finder/tmpl/maps/default.php +++ b/administrator/components/com_finder/tmpl/maps/default.php @@ -103,7 +103,7 @@ ?> —', $item->level - 1); ?> escape($title); ?> - escape(trim($title, '*')) === 'Language' && Multilanguage::isEnabled()) : ?> + escape(trim((string) $title, '*')) === 'Language' && Multilanguage::isEnabled()) : ?>
diff --git a/administrator/components/com_guidedtours/src/Controller/StepsController.php b/administrator/components/com_guidedtours/src/Controller/StepsController.php index ff90a44b19dae..348660990923b 100644 --- a/administrator/components/com_guidedtours/src/Controller/StepsController.php +++ b/administrator/components/com_guidedtours/src/Controller/StepsController.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Guidedtours\Administrator\Controller; use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -31,7 +32,7 @@ class StepsController extends AdminController * @param string $prefix The class prefix. Optional. * @param array $config The array of possible config values. Optional. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel + * @return BaseDatabaseModel * * @since 4.3.0 */ diff --git a/administrator/components/com_guidedtours/src/Controller/ToursController.php b/administrator/components/com_guidedtours/src/Controller/ToursController.php index 87d53b20806a0..43da08719eab4 100644 --- a/administrator/components/com_guidedtours/src/Controller/ToursController.php +++ b/administrator/components/com_guidedtours/src/Controller/ToursController.php @@ -12,6 +12,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Router\Route; // phpcs:disable PSR1.Files.SideEffects @@ -33,7 +34,7 @@ class ToursController extends AdminController * @param string $prefix The class prefix. Optional. * @param array $config The array of possible config values. Optional. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel + * @return BaseDatabaseModel * * @since 4.3.0 */ @@ -48,14 +49,14 @@ public function duplicate() $pks = (array) $this->input->post->get('cid', [], 'int'); $pks = array_filter($pks); try { - if (empty($pks)) { + if ($pks === []) { throw new \Exception(Text::_('COM_GUIDEDTOURS_ERROR_NO_GUIDEDTOURS_SELECTED')); } $model = $this->getModel(); $model->duplicate($pks); $this->setMessage(Text::plural('COM_GUIDEDTOURS_TOURS_DUPLICATED', \count($pks))); - } catch (\Exception $e) { - $this->app->enqueueMessage($e->getMessage(), 'warning'); + } catch (\Exception $exception) { + $this->app->enqueueMessage($exception->getMessage(), 'warning'); } $this->setRedirect(Route::_('index.php?option=com_guidedtours&view=tours' . $this->getRedirectToListAppend(), false)); } diff --git a/administrator/components/com_guidedtours/src/Helper/GuidedtoursHelper.php b/administrator/components/com_guidedtours/src/Helper/GuidedtoursHelper.php index f3b6198b99b47..35837488ee349 100644 --- a/administrator/components/com_guidedtours/src/Helper/GuidedtoursHelper.php +++ b/administrator/components/com_guidedtours/src/Helper/GuidedtoursHelper.php @@ -46,7 +46,7 @@ public static function loadTranslationFiles($uid, bool $steps = false) // The uid has an extension separator so we need to check the extension language files if (strpos($uid, '.') > 0) { - list($extension, $tourid) = explode('.', $uid, 2); + [$extension, $tourid] = explode('.', $uid, 2); $source = ''; @@ -84,11 +84,11 @@ public static function loadTranslationFiles($uid, bool $steps = false) break; } - $lang->load($extension . '.' . str_replace('-', '_', $tourid), JPATH_ADMINISTRATOR) - || $lang->load($extension . '.' . str_replace('-', '_', $tourid), $source); - if ($steps) { - $lang->load($extension . '.' . str_replace('-', '_', $tourid) . '_steps', JPATH_ADMINISTRATOR) - || $lang->load($extension . '.' . str_replace('-', '_', $tourid) . '_steps', $source); + if (!$lang->load($extension . '.' . str_replace('-', '_', $tourid), JPATH_ADMINISTRATOR)) { + $lang->load($extension . '.' . str_replace('-', '_', $tourid), $source); + } + if ($steps && !$lang->load($extension . '.' . str_replace('-', '_', $tourid) . '_steps', JPATH_ADMINISTRATOR)) { + $lang->load($extension . '.' . str_replace('-', '_', $tourid) . '_steps', $source); } } else { $lang->load('guidedtours.' . str_replace('-', '_', $uid), JPATH_ADMINISTRATOR); diff --git a/administrator/components/com_guidedtours/src/Model/StepModel.php b/administrator/components/com_guidedtours/src/Model/StepModel.php index 62533efa4d150..e54fd85814a8c 100644 --- a/administrator/components/com_guidedtours/src/Model/StepModel.php +++ b/administrator/components/com_guidedtours/src/Model/StepModel.php @@ -81,8 +81,8 @@ public function save($data) $tour->load($data['tour_id']); // Language keys must include GUIDEDTOUR to prevent save issues - if (strpos($data['description'], 'GUIDEDTOUR') !== false) { - $data['description'] = strip_tags($data['description']); + if (str_contains((string) $data['description'], 'GUIDEDTOUR')) { + $data['description'] = strip_tags((string) $data['description']); } // Make sure we use the correct extension when editing an existing tour @@ -92,7 +92,7 @@ public function save($data) if ($pk > 0) { $table->load($pk); - if ((int) $table->tour_id) { + if ((int) $table->tour_id !== 0) { $data['tour_id'] = (int) $table->tour_id; } } @@ -110,7 +110,7 @@ public function save($data) /** * Prepare and sanitise the table prior to saving. * - * @param \Joomla\CMS\Table\Table $table The Table object + * @param Table $table The Table object * * @return void * @@ -220,7 +220,7 @@ protected function loadFormData() ); if (empty($data)) { - $data = $this->getItem(); + return $this->getItem(); } return $data; @@ -240,7 +240,7 @@ public function getItem($pk = null) if ($result = parent::getItem($pk)) { $app = Factory::getApplication(); - /** @var \Joomla\Component\Guidedtours\Administrator\Model\TourModel $tourModel */ + /** @var TourModel $tourModel */ $tourModel = $app->bootComponent('com_guidedtours') ->getMVCFactory()->createModel('Tour', 'Administrator', ['ignore_request' => true]); @@ -258,7 +258,7 @@ public function getItem($pk = null) $tour = $tourModel->getItem($tourId); // Sets step language to parent tour language - $result->language = !empty($tour->language) ? $tour->language : '*'; + $result->language = empty($tour->language) ? '*' : $tour->language; // Set the step's tour id $result->tour_id = $tourId; diff --git a/administrator/components/com_guidedtours/src/Model/StepsModel.php b/administrator/components/com_guidedtours/src/Model/StepsModel.php index d3daaa4685b81..268d859dfd45d 100644 --- a/administrator/components/com_guidedtours/src/Model/StepsModel.php +++ b/administrator/components/com_guidedtours/src/Model/StepsModel.php @@ -193,16 +193,16 @@ protected function getListQuery() $search = $this->getState('filter.search'); if (!empty($search)) { - if (stripos($search, 'id:') === 0) { - $search = (int) substr($search, 3); + if (stripos((string) $search, 'id:') === 0) { + $search = (int) substr((string) $search, 3); $query->where($db->quoteName('a.id') . ' = :search') ->bind(':search', $search, ParameterType::INTEGER); - } elseif (stripos($search, 'description:') === 0) { - $search = '%' . substr($search, 12) . '%'; + } elseif (stripos((string) $search, 'description:') === 0) { + $search = '%' . substr((string) $search, 12) . '%'; $query->where('(' . $db->quoteName('a.description') . ' LIKE :search1)') ->bind([':search1'], $search); } else { - $search = '%' . str_replace(' ', '%', trim($search)) . '%'; + $search = '%' . str_replace(' ', '%', trim((string) $search)) . '%'; $query->where( '(' . $db->quoteName('a.title') . ' LIKE :search1' . ' OR ' . $db->quoteName('a.description') . ' LIKE :search2' @@ -238,7 +238,7 @@ public function getItems() $app = Factory::getApplication(); $tourId = $item->tour_id; - /** @var \Joomla\Component\Guidedtours\Administrator\Model\TourModel $tourModel */ + /** @var TourModel $tourModel */ $tourModel = $app->bootComponent('com_guidedtours') ->getMVCFactory()->createModel('Tour', 'Administrator', [ 'ignore_request' => true ]); diff --git a/administrator/components/com_guidedtours/src/Model/TourModel.php b/administrator/components/com_guidedtours/src/Model/TourModel.php index 1bc1e6512c6b1..7d11630b4d7ab 100644 --- a/administrator/components/com_guidedtours/src/Model/TourModel.php +++ b/administrator/components/com_guidedtours/src/Model/TourModel.php @@ -17,6 +17,7 @@ use Joomla\CMS\MVC\Model\AdminModel; use Joomla\CMS\Object\CMSObject; use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\Table\Table; use Joomla\Component\Guidedtours\Administrator\Helper\GuidedtoursHelper; use Joomla\Database\ParameterType; use Joomla\Registry\Registry; @@ -63,8 +64,8 @@ public function save($data) $input = Factory::getApplication()->getInput(); // Language keys must include GUIDEDTOUR to prevent save issues - if (strpos($data['description'], 'GUIDEDTOUR') !== false) { - $data['description'] = strip_tags($data['description']); + if (str_contains((string) $data['description'], 'GUIDEDTOUR')) { + $data['description'] = strip_tags((string) $data['description']); } if ($input->get('task') == 'save2copy') { @@ -86,7 +87,7 @@ public function save($data) /** * Prepare and sanitise the table prior to saving. * - * @param \Joomla\CMS\Table\Table $table The Table object + * @param Table $table The Table object * * @return void * @@ -181,7 +182,7 @@ protected function loadFormData() ); if (empty($data)) { - $data = $this->getItem(); + return $this->getItem(); } return $data; @@ -198,16 +199,11 @@ protected function loadFormData() */ public function getItem($pk = null) { - $pk = (!empty($pk)) ? $pk : (int) $this->getState($this->getName() . '.id'); + $pk = (empty($pk)) ? (int) $this->getState($this->getName() . '.id') : $pk; $table = $this->getTable(); - if (\is_int($pk)) { - $result = $table->load((int) $pk); - } else { - // Attempt to load the row by uid. - $result = $table->load([ 'uid' => $pk ]); - } + $result = \is_int($pk) ? $table->load($pk) : $table->load([ 'uid' => $pk ]); // Check for a table object error. if ($result === false) { @@ -547,7 +543,7 @@ public function isAutostart($pk): bool ->from($db->quoteName('#__guidedtours')) ->where($db->quoteName('published') . ' = 1'); - if (\is_integer($pk)) { + if (\is_int($pk)) { $query->where($db->quoteName('id') . ' = :id') ->bind(':id', $pk, ParameterType::INTEGER); } else { @@ -562,7 +558,7 @@ public function isAutostart($pk): bool if ($result === null) { return false; } - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { return false; } @@ -597,7 +593,7 @@ public function saveTourUserState($id, $state = ''): bool try { $result = $db->setQuery($query)->loadResult(); - } catch (\Exception $e) { + } catch (\Exception) { return false; } @@ -616,7 +612,7 @@ public function saveTourUserState($id, $state = ''): bool ]; if (!\is_null($result)) { - $values = json_decode($result, true); + $values = json_decode((string) $result, true); // The profile is updated only when delayed. 'Completed' and 'Skipped' are final if (!empty($values) && $values['state'] === 'delayed') { diff --git a/administrator/components/com_guidedtours/src/Model/ToursModel.php b/administrator/components/com_guidedtours/src/Model/ToursModel.php index 3179b7d79f91c..fd0769b52ee50 100644 --- a/administrator/components/com_guidedtours/src/Model/ToursModel.php +++ b/administrator/components/com_guidedtours/src/Model/ToursModel.php @@ -109,7 +109,7 @@ public function getFilterForm($data = [], $loadData = true) * * @since 4.3.0 */ - public function getListQuery() + protected function getListQuery() { // Create a new query object. $db = $this->getDatabase(); @@ -207,16 +207,16 @@ public function getListQuery() $search = $this->getState('filter.search'); if (!empty($search)) { - if (stripos($search, 'id:') === 0) { - $search = (int) substr($search, 3); + if (stripos((string) $search, 'id:') === 0) { + $search = (int) substr((string) $search, 3); $query->where($db->quoteName('a.id') . ' = :search') ->bind(':search', $search, ParameterType::INTEGER); - } elseif (stripos($search, 'description:') === 0) { - $search = '%' . substr($search, 12) . '%'; + } elseif (stripos((string) $search, 'description:') === 0) { + $search = '%' . substr((string) $search, 12) . '%'; $query->where('(' . $db->quoteName('a.description') . ' LIKE :search1)') ->bind([':search1'], $search); } else { - $search = '%' . str_replace(' ', '%', trim($search)) . '%'; + $search = '%' . str_replace(' ', '%', trim((string) $search)) . '%'; $query->where( '(' . $db->quoteName('a.title') . ' LIKE :search1' . ' OR ' . $db->quoteName('a.description') . ' LIKE :search2' @@ -228,7 +228,7 @@ public function getListQuery() // Add the list ordering clause. $orderCol = $this->state->get('list.ordering', 'a.ordering'); - $orderDirn = strtoupper($this->state->get('list.direction', 'ASC')); + $orderDirn = strtoupper((string) $this->state->get('list.direction', 'ASC')); $query->order($db->escape($orderCol) . ' ' . ($orderDirn === 'DESC' ? 'DESC' : 'ASC')); diff --git a/administrator/components/com_guidedtours/src/Table/StepTable.php b/administrator/components/com_guidedtours/src/Table/StepTable.php index 777bacd8183b4..4b9296eebe505 100644 --- a/administrator/components/com_guidedtours/src/Table/StepTable.php +++ b/administrator/components/com_guidedtours/src/Table/StepTable.php @@ -89,7 +89,7 @@ public function store($updateNulls = true) $userId = $this->getCurrentUser()->id; // Set created date if not set. - if (!(int) $this->created) { + if ((int) $this->created === 0) { $this->created = $date; } @@ -103,7 +103,7 @@ public function store($updateNulls = true) $this->created_by = $userId; } - if (!(int) $this->modified) { + if ((int) $this->modified === 0) { $this->modified = $date; } diff --git a/administrator/components/com_guidedtours/src/Table/TourTable.php b/administrator/components/com_guidedtours/src/Table/TourTable.php index 65c516e9efafa..044331b831e98 100644 --- a/administrator/components/com_guidedtours/src/Table/TourTable.php +++ b/administrator/components/com_guidedtours/src/Table/TourTable.php @@ -77,7 +77,7 @@ public function store($updateNulls = true) $userId = $this->getCurrentUser()->id; // Set created date if not set. - if (!(int) $this->created) { + if ((int) $this->created === 0) { $this->created = $date; } @@ -91,7 +91,7 @@ public function store($updateNulls = true) $this->created_by = $userId; } - if (!(int) $this->modified) { + if ((int) $this->modified === 0) { $this->modified = $date; } diff --git a/administrator/components/com_guidedtours/src/View/Step/HtmlView.php b/administrator/components/com_guidedtours/src/View/Step/HtmlView.php index a25ee5be05f74..fabdc1d99641f 100644 --- a/administrator/components/com_guidedtours/src/View/Step/HtmlView.php +++ b/administrator/components/com_guidedtours/src/View/Step/HtmlView.php @@ -11,10 +11,12 @@ namespace Joomla\Component\Guidedtours\Administrator\View\Step; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Object\CMSObject; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Guidedtours\Administrator\Model\StepModel; @@ -32,7 +34,7 @@ class HtmlView extends BaseHtmlView /** * The \JForm object * - * @var \Joomla\CMS\Form\Form + * @var Form */ protected $form; @@ -53,7 +55,7 @@ class HtmlView extends BaseHtmlView /** * The actions the user is authorised to perform * - * @var \Joomla\CMS\Object\CMSObject + * @var CMSObject */ protected $canDo; @@ -76,7 +78,7 @@ public function display($tpl = null) $this->item = $model->getItem(); $this->state = $model->getState(); - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -150,7 +152,7 @@ protected function addToolbar() ToolbarHelper::divider(); $inlinehelp = (string) $this->form->getXml()->config->inlinehelp['button'] === 'show'; - $targetClass = (string) $this->form->getXml()->config->inlinehelp['targetclass'] ?: 'hide-aware-inline-help'; + $targetClass = (string) $this->form->getXml()->config->inlinehelp['targetclass'] !== '' && (string) $this->form->getXml()->config->inlinehelp['targetclass'] !== '0' ? (string) $this->form->getXml()->config->inlinehelp['targetclass'] : 'hide-aware-inline-help'; if ($inlinehelp) { ToolbarHelper::inlinehelp($targetClass); diff --git a/administrator/components/com_guidedtours/src/View/Steps/HtmlView.php b/administrator/components/com_guidedtours/src/View/Steps/HtmlView.php index 101f7df659d47..97cdb357ed751 100644 --- a/administrator/components/com_guidedtours/src/View/Steps/HtmlView.php +++ b/administrator/components/com_guidedtours/src/View/Steps/HtmlView.php @@ -11,13 +11,17 @@ namespace Joomla\Component\Guidedtours\Administrator\View\Steps; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Router\Route; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Guidedtours\Administrator\Model\StepsModel; +use Joomla\Component\Guidedtours\Administrator\Model\TourModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -40,21 +44,21 @@ class HtmlView extends BaseHtmlView /** * The pagination object * - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination */ protected $pagination; /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $state; /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form */ public $filterForm; @@ -92,12 +96,12 @@ public function display($tpl = null) $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + if (\count($this->items) === 0 && $this->isEmptyState = $model->getIsEmptyState()) { $this->setLayout('emptystate'); } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -134,12 +138,12 @@ protected function addToolbar() $app = Factory::getApplication(); $user = $app->getIdentity(); - /** @var \Joomla\Component\Guidedtours\Administrator\Model\TourModel $tourModel */ + /** @var TourModel $tourModel */ $tourModel = $app->bootComponent('com_guidedtours') ->getMVCFactory()->createModel('Tour', 'Administrator', ['ignore_request' => true]); $tour = $tourModel->getItem($this->state->get('filter.tour_id', -1)); - $title = !empty($tour->title) ? $tour->title : ''; + $title = empty($tour->title) ? '' : $tour->title; ToolbarHelper::title(Text::sprintf('COM_GUIDEDTOURS_STEPS_LIST', Text::_($title)), 'map-signs'); $arrow = $this->getLanguage()->isRtl() ? 'arrow-right' : 'arrow-left'; diff --git a/administrator/components/com_guidedtours/src/View/Tour/HtmlView.php b/administrator/components/com_guidedtours/src/View/Tour/HtmlView.php index a67a3e88bf086..2e6431c60dca9 100644 --- a/administrator/components/com_guidedtours/src/View/Tour/HtmlView.php +++ b/administrator/components/com_guidedtours/src/View/Tour/HtmlView.php @@ -11,12 +11,14 @@ namespace Joomla\Component\Guidedtours\Administrator\View\Tour; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Guidedtours\Administrator\Model\TourModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -32,7 +34,7 @@ class HtmlView extends BaseHtmlView /** * The \JForm object * - * @var \Joomla\CMS\Form\Form + * @var Form */ protected $form; @@ -53,7 +55,7 @@ class HtmlView extends BaseHtmlView /** * The actions the user is authorised to perform * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $canDo; @@ -76,7 +78,7 @@ public function display($tpl = null) $this->item = $model->getItem(); $this->state = $model->getState(); - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -151,7 +153,7 @@ protected function addToolbar() ToolbarHelper::divider(); $inlinehelp = (string) $this->form->getXml()->config->inlinehelp['button'] === 'show'; - $targetClass = (string) $this->form->getXml()->config->inlinehelp['targetclass'] ?: 'hide-aware-inline-help'; + $targetClass = (string) $this->form->getXml()->config->inlinehelp['targetclass'] !== '' && (string) $this->form->getXml()->config->inlinehelp['targetclass'] !== '0' ? (string) $this->form->getXml()->config->inlinehelp['targetclass'] : 'hide-aware-inline-help'; if ($inlinehelp) { ToolbarHelper::inlinehelp($targetClass); diff --git a/administrator/components/com_guidedtours/src/View/Tours/HtmlView.php b/administrator/components/com_guidedtours/src/View/Tours/HtmlView.php index 81aae1f4515ed..1f09214d79a36 100644 --- a/administrator/components/com_guidedtours/src/View/Tours/HtmlView.php +++ b/administrator/components/com_guidedtours/src/View/Tours/HtmlView.php @@ -10,13 +10,16 @@ namespace Joomla\Component\Guidedtours\Administrator\View\Tours; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Guidedtours\Administrator\Model\ToursModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -39,21 +42,21 @@ class HtmlView extends BaseHtmlView /** * The pagination object * - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination */ protected $pagination; /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry */ protected $state; /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form */ public $filterForm; @@ -91,12 +94,12 @@ public function display($tpl = null) $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + if (\count($this->items) === 0 && $this->isEmptyState = $model->getIsEmptyState()) { $this->setLayout('emptystate'); } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_guidedtours/tmpl/step/edit.php b/administrator/components/com_guidedtours/tmpl/step/edit.php index c47a6d07209ba..b7b9f55487b05 100644 --- a/administrator/components/com_guidedtours/tmpl/step/edit.php +++ b/administrator/components/com_guidedtours/tmpl/step/edit.php @@ -38,7 +38,7 @@ - item->id != 0 && strpos($this->item->title, 'GUIDEDTOUR') !== false) : ?> + item->id != 0 && str_contains($this->item->title, 'GUIDEDTOUR')) : ?>
form->setFieldAttribute('title_translation', 'label', Text::sprintf('COM_GUIDEDTOURS_STEP_TITLE_TRANSLATION', $lang)); ?> @@ -55,7 +55,7 @@
form->renderField('description'); ?> - item->id != 0 && strpos($this->item->description, 'GUIDEDTOUR') !== false) : ?> + item->id != 0 && str_contains($this->item->description, 'GUIDEDTOUR')) : ?> form->setFieldAttribute('description_translation', 'label', Text::sprintf('COM_GUIDEDTOURS_STEP_DESCRIPTION_TRANSLATION', $lang)); ?> form->renderField('description_translation'); ?> diff --git a/administrator/components/com_guidedtours/tmpl/steps/default.php b/administrator/components/com_guidedtours/tmpl/steps/default.php index 97a0217a49c86..c6701c94e92c8 100644 --- a/administrator/components/com_guidedtours/tmpl/steps/default.php +++ b/administrator/components/com_guidedtours/tmpl/steps/default.php @@ -17,7 +17,6 @@ use Joomla\CMS\Router\Route; use Joomla\CMS\Session\Session; use Joomla\Component\Guidedtours\Administrator\Extension\GuidedtoursComponent; -use Joomla\Component\Guidedtours\Administrator\View\Steps\HtmlView; /** @var HtmlView $this */ @@ -136,7 +135,7 @@ - class="js-draggable" data-url="" data-direction="" data-nested="true" " data-direction="" data-nested="true" > items as $i => $item) : $canEditOwn = $canEditOwnTour && $item->created_by == $userId; diff --git a/administrator/components/com_guidedtours/tmpl/steps/emptystate.php b/administrator/components/com_guidedtours/tmpl/steps/emptystate.php index 68ae26353b72f..1472c1db5aebb 100644 --- a/administrator/components/com_guidedtours/tmpl/steps/emptystate.php +++ b/administrator/components/com_guidedtours/tmpl/steps/emptystate.php @@ -1,5 +1,7 @@ 'COM_GUIDEDTOURS_STEPS', 'formURL' => 'index.php?option=com_guidedtours&view=steps', diff --git a/administrator/components/com_guidedtours/tmpl/tour/edit.php b/administrator/components/com_guidedtours/tmpl/tour/edit.php index 5bef1f3549f89..ce857b0b3dc76 100644 --- a/administrator/components/com_guidedtours/tmpl/tour/edit.php +++ b/administrator/components/com_guidedtours/tmpl/tour/edit.php @@ -41,7 +41,7 @@
- item->id != 0 && strpos($this->item->title, 'GUIDEDTOUR') !== false) : ?> + item->id != 0 && str_contains($this->item->title, 'GUIDEDTOUR')) : ?>
form->setFieldAttribute('title_translation', 'label', Text::sprintf('COM_GUIDEDTOURS_TITLE_TRANSLATION', $lang)); ?> @@ -59,7 +59,7 @@ form->renderField('url'); ?> form->renderField('description'); ?> - item->id != 0 && strpos($this->item->description, 'GUIDEDTOUR') !== false) : ?> + item->id != 0 && str_contains($this->item->description, 'GUIDEDTOUR')) : ?> form->setFieldAttribute('description_translation', 'label', Text::sprintf('COM_GUIDEDTOURS_DESCRIPTION_TRANSLATION', $lang)); ?> form->renderField('description_translation'); ?> diff --git a/administrator/components/com_guidedtours/tmpl/tours/default.php b/administrator/components/com_guidedtours/tmpl/tours/default.php index 6b1f349b562f2..9f6791167615b 100644 --- a/administrator/components/com_guidedtours/tmpl/tours/default.php +++ b/administrator/components/com_guidedtours/tmpl/tours/default.php @@ -18,7 +18,6 @@ use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; use Joomla\CMS\Session\Session; -use Joomla\Component\Guidedtours\Administrator\View\Tours\HtmlView; /** @var HtmlView $this */ @@ -29,7 +28,7 @@ try { $app = Factory::getApplication(); -} catch (Exception $e) { +} catch (Exception) { die('Failed to get app'); } @@ -149,7 +148,7 @@ - class="js-draggable" data-url="" data-direction="" data-nested="true" " data-direction="" data-nested="true" > items as $i => $item) : $canEditOwn = $canEditOwnTour && $item->created_by == $userId; diff --git a/administrator/components/com_guidedtours/tmpl/tours/emptystate.php b/administrator/components/com_guidedtours/tmpl/tours/emptystate.php index 6500a86264413..f3b9748187d58 100644 --- a/administrator/components/com_guidedtours/tmpl/tours/emptystate.php +++ b/administrator/components/com_guidedtours/tmpl/tours/emptystate.php @@ -1,5 +1,7 @@ 'COM_GUIDEDTOURS_TOURS_LIST', 'formURL' => 'index.php?option=com_guidedtours&view=tours', diff --git a/administrator/components/com_installer/src/Controller/DatabaseController.php b/administrator/components/com_installer/src/Controller/DatabaseController.php index eb155cd60938a..3f8552131edeb 100644 --- a/administrator/components/com_installer/src/Controller/DatabaseController.php +++ b/administrator/components/com_installer/src/Controller/DatabaseController.php @@ -15,6 +15,7 @@ use Joomla\CMS\Response\JsonResponse; use Joomla\CMS\Router\Route; use Joomla\Component\Installer\Administrator\Model\DatabaseModel; +use Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -48,7 +49,7 @@ public function fix() // Remove zero values resulting from input filter $cid = array_filter($cid); - if (empty($cid)) { + if ($cid === []) { $this->app->getLogger()->warning( Text::_( 'COM_INSTALLER_ERROR_NO_EXTENSIONS_SELECTED' @@ -60,7 +61,7 @@ public function fix() $model = $this->getModel('Database'); $model->fix($cid); - /** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $updateModel */ + /** @var UpdateModel $updateModel */ $updateModel = $this->app->bootComponent('com_joomlaupdate') ->getMVCFactory()->createModel('Update', 'Administrator', ['ignore_request' => true]); $updateModel->purge(); diff --git a/administrator/components/com_installer/src/Controller/DiscoverController.php b/administrator/components/com_installer/src/Controller/DiscoverController.php index 86c0a7861fab9..472cdfaf22632 100644 --- a/administrator/components/com_installer/src/Controller/DiscoverController.php +++ b/administrator/components/com_installer/src/Controller/DiscoverController.php @@ -14,6 +14,7 @@ use Joomla\CMS\MVC\Controller\BaseController; use Joomla\CMS\Response\JsonResponse; use Joomla\CMS\Router\Route; +use Joomla\Component\Installer\Administrator\Model\DiscoverModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -37,7 +38,7 @@ public function refresh() { $this->checkToken('request'); - /** @var \Joomla\Component\Installer\Administrator\Model\DiscoverModel $model */ + /** @var DiscoverModel $model */ $model = $this->getModel('discover'); $model->discover(); @@ -59,7 +60,7 @@ public function install() { $this->checkToken(); - /** @var \Joomla\Component\Installer\Administrator\Model\DiscoverModel $model */ + /** @var DiscoverModel $model */ $model = $this->getModel('discover'); $model->discover_install(); $this->setRedirect(Route::_('index.php?option=com_installer&view=discover', false)); @@ -76,7 +77,7 @@ public function purge() { $this->checkToken('request'); - /** @var \Joomla\Component\Installer\Administrator\Model\DiscoverModel $model */ + /** @var DiscoverModel $model */ $model = $this->getModel('discover'); $model->purge(); $this->setRedirect(Route::_('index.php?option=com_installer&view=discover', false), $model->_message); diff --git a/administrator/components/com_installer/src/Controller/DisplayController.php b/administrator/components/com_installer/src/Controller/DisplayController.php index 428087dd6e0c6..e68055b98ee59 100644 --- a/administrator/components/com_installer/src/Controller/DisplayController.php +++ b/administrator/components/com_installer/src/Controller/DisplayController.php @@ -51,7 +51,7 @@ public function display($cachable = false, $urlparams = false) // Check for edit form. if ($vName === 'updatesite' && $lName === 'edit' && !$this->checkEditId('com_installer.edit.updatesite', $id)) { // Somehow the person just went to the form - we don't allow that. - if (!\count($this->app->getMessageQueue())) { + if (\count($this->app->getMessageQueue()) === 0) { $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error'); } diff --git a/administrator/components/com_installer/src/Controller/InstallController.php b/administrator/components/com_installer/src/Controller/InstallController.php index 16867b0d9d944..8239b7c811877 100644 --- a/administrator/components/com_installer/src/Controller/InstallController.php +++ b/administrator/components/com_installer/src/Controller/InstallController.php @@ -17,6 +17,7 @@ use Joomla\CMS\Router\Route; use Joomla\CMS\Session\Session; use Joomla\CMS\Uri\Uri; +use Joomla\Component\Installer\Administrator\Model\InstallModel; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -45,7 +46,7 @@ public function install() throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403); } - /** @var \Joomla\Component\Installer\Administrator\Model\InstallModel $model */ + /** @var InstallModel $model */ $model = $this->getModel('install'); // @todo: Reset the users acl here as well to kill off any missing bits. diff --git a/administrator/components/com_installer/src/Controller/ManageController.php b/administrator/components/com_installer/src/Controller/ManageController.php index 27cb7b9cd4656..68f482ed39efd 100644 --- a/administrator/components/com_installer/src/Controller/ManageController.php +++ b/administrator/components/com_installer/src/Controller/ManageController.php @@ -71,7 +71,7 @@ public function publish() // Remove zero values resulting from input filter $ids = array_filter($ids); - if (empty($ids)) { + if ($ids === []) { $this->setMessage(Text::_('COM_INSTALLER_ERROR_NO_EXTENSIONS_SELECTED'), 'warning'); } else { /** @var ManageModel $model */ @@ -81,12 +81,7 @@ public function publish() if (!$model->publish($ids, $value)) { $this->setMessage(implode('
', $model->getErrors()), 'warning'); } else { - if ($value == 1) { - $ntext = 'COM_INSTALLER_N_EXTENSIONS_PUBLISHED'; - } else { - $ntext = 'COM_INSTALLER_N_EXTENSIONS_UNPUBLISHED'; - } - + $ntext = $value == 1 ? 'COM_INSTALLER_N_EXTENSIONS_PUBLISHED' : 'COM_INSTALLER_N_EXTENSIONS_UNPUBLISHED'; $this->setMessage(Text::plural($ntext, \count($ids))); } } @@ -113,7 +108,7 @@ public function remove() // Remove zero values resulting from input filter $eid = array_filter($eid); - if (!empty($eid)) { + if ($eid !== []) { /** @var ManageModel $model */ $model = $this->getModel('manage'); @@ -142,7 +137,7 @@ public function refresh() // Remove zero values resulting from input filter $uid = array_filter($uid); - if (!empty($uid)) { + if ($uid !== []) { /** @var ManageModel $model */ $model = $this->getModel('manage'); diff --git a/administrator/components/com_installer/src/Controller/UpdatesitesController.php b/administrator/components/com_installer/src/Controller/UpdatesitesController.php index 07f0271187b38..d00f50beb7756 100644 --- a/administrator/components/com_installer/src/Controller/UpdatesitesController.php +++ b/administrator/components/com_installer/src/Controller/UpdatesitesController.php @@ -14,7 +14,9 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\AdminController; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Router\Route; +use Joomla\Component\Installer\Administrator\Model\UpdatesitesModel; use Joomla\Input\Input; use Joomla\Utilities\ArrayHelper; @@ -66,7 +68,7 @@ public function __construct($config = [], ?MVCFactoryInterface $factory = null, * @param string $prefix The class prefix. Optional. * @param array $config The array of possible config values. Optional. * - * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel + * @return BaseDatabaseModel * * @since 4.0.0 */ @@ -97,12 +99,12 @@ public function publish() // Remove zero values resulting from input filter $ids = array_filter($ids); - if (empty($ids)) { + if ($ids === []) { throw new \Exception(Text::_('COM_INSTALLER_ERROR_NO_UPDATESITES_SELECTED'), 500); } // Get the model. - /** @var \Joomla\Component\Installer\Administrator\Model\UpdatesitesModel $model */ + /** @var UpdatesitesModel $model */ $model = $this->getModel('Updatesites'); // Change the state of the records. @@ -136,7 +138,7 @@ public function delete() // Remove zero values resulting from input filter $ids = array_filter($ids); - if (empty($ids)) { + if ($ids === []) { throw new \Exception(Text::_('COM_INSTALLER_ERROR_NO_UPDATESITES_SELECTED'), 500); } diff --git a/administrator/components/com_installer/src/Field/ExtensionstatusField.php b/administrator/components/com_installer/src/Field/ExtensionstatusField.php index e660d9952f013..4b5632813eda0 100644 --- a/administrator/components/com_installer/src/Field/ExtensionstatusField.php +++ b/administrator/components/com_installer/src/Field/ExtensionstatusField.php @@ -39,7 +39,7 @@ class ExtensionstatusField extends ListField * * @since 3.5 */ - public function getOptions() + protected function getOptions() { $options = InstallerHelper::getStateOptions(); diff --git a/administrator/components/com_installer/src/Field/FolderField.php b/administrator/components/com_installer/src/Field/FolderField.php index ff2ff9fddd79e..2b5f1df6540ac 100644 --- a/administrator/components/com_installer/src/Field/FolderField.php +++ b/administrator/components/com_installer/src/Field/FolderField.php @@ -39,7 +39,7 @@ class FolderField extends ListField * * @since 3.5 */ - public function getOptions() + protected function getOptions() { $options = InstallerHelper::getExtensionGroups(); diff --git a/administrator/components/com_installer/src/Field/LocationField.php b/administrator/components/com_installer/src/Field/LocationField.php index c7eba78720b7f..e3537f2dbd7ac 100644 --- a/administrator/components/com_installer/src/Field/LocationField.php +++ b/administrator/components/com_installer/src/Field/LocationField.php @@ -39,7 +39,7 @@ class LocationField extends ListField * * @since 3.5 */ - public function getOptions() + protected function getOptions() { $options = InstallerHelper::getClientOptions(); diff --git a/administrator/components/com_installer/src/Field/TypeField.php b/administrator/components/com_installer/src/Field/TypeField.php index 6329b959fab23..a5791942987c7 100644 --- a/administrator/components/com_installer/src/Field/TypeField.php +++ b/administrator/components/com_installer/src/Field/TypeField.php @@ -39,7 +39,7 @@ class TypeField extends ListField * * @since 3.5 */ - public function getOptions() + protected function getOptions() { $options = InstallerHelper::getExtensionTypes(); diff --git a/administrator/components/com_installer/src/Helper/InstallerHelper.php b/administrator/components/com_installer/src/Helper/InstallerHelper.php index f0899df2e4045..e74d378bf3038 100644 --- a/administrator/components/com_installer/src/Helper/InstallerHelper.php +++ b/administrator/components/com_installer/src/Helper/InstallerHelper.php @@ -47,7 +47,7 @@ public static function getExtensionTypes() $options = []; foreach ($types as $type) { - $options[] = HTMLHelper::_('select.option', $type, Text::_('COM_INSTALLER_TYPE_' . strtoupper($type))); + $options[] = HTMLHelper::_('select.option', $type, Text::_('COM_INSTALLER_TYPE_' . strtoupper((string) $type))); } return $options; @@ -91,13 +91,7 @@ public static function getExtensionGroups() */ public static function getClientOptions() { - // Build the filter options. - $options = []; - $options[] = HTMLHelper::_('select.option', '0', Text::_('JSITE')); - $options[] = HTMLHelper::_('select.option', '1', Text::_('JADMINISTRATOR')); - $options[] = HTMLHelper::_('select.option', '3', Text::_('JAPI')); - - return $options; + return [HTMLHelper::_('select.option', '0', Text::_('JSITE')), HTMLHelper::_('select.option', '1', Text::_('JADMINISTRATOR')), HTMLHelper::_('select.option', '3', Text::_('JAPI'))]; } /** @@ -109,14 +103,7 @@ public static function getClientOptions() */ public static function getStateOptions() { - // Build the filter options. - $options = []; - $options[] = HTMLHelper::_('select.option', '0', Text::_('JDISABLED')); - $options[] = HTMLHelper::_('select.option', '1', Text::_('JENABLED')); - $options[] = HTMLHelper::_('select.option', '2', Text::_('JPROTECTED')); - $options[] = HTMLHelper::_('select.option', '3', Text::_('JUNPROTECTED')); - - return $options; + return [HTMLHelper::_('select.option', '0', Text::_('JDISABLED')), HTMLHelper::_('select.option', '1', Text::_('JENABLED')), HTMLHelper::_('select.option', '2', Text::_('JPROTECTED')), HTMLHelper::_('select.option', '3', Text::_('JUNPROTECTED'))]; } /** @@ -159,9 +146,7 @@ function (object $entry) use ($language): string { $extensions ); $arrayValues = array_map( - function (object $entry): int { - return $entry->extension_id; - }, + fn (object $entry): int => $entry->extension_id, $extensions ); @@ -248,14 +233,14 @@ public static function getDownloadKey(CMSObject $extension): array $extension->get('folder') ); - if (!$installXmlFile) { + if (!$installXmlFile instanceof \SimpleXMLElement) { return [ 'supported' => false, 'valid' => false, ]; } - if (!isset($installXmlFile->dlid)) { + if (!property_exists($installXmlFile, 'dlid') || $installXmlFile->dlid === null) { return [ 'supported' => false, 'valid' => false, @@ -264,21 +249,19 @@ public static function getDownloadKey(CMSObject $extension): array $prefix = (string) $installXmlFile->dlid['prefix']; $suffix = (string) $installXmlFile->dlid['suffix']; - $value = substr($extension->get('extra_query'), \strlen($prefix)); + $value = substr((string) $extension->get('extra_query'), \strlen($prefix)); - if ($suffix) { + if ($suffix !== '' && $suffix !== '0') { $value = substr($value, 0, -\strlen($suffix)); } - $downloadKey = [ + return [ 'supported' => true, 'valid' => (bool) $value, 'prefix' => $prefix, 'suffix' => $suffix, 'value' => $value, ]; - - return $downloadKey; } /** @@ -302,7 +285,7 @@ public static function getExtensionDownloadKey( // Get the database driver. If it fails we cannot report whether the extension supports download keys. try { $db = Factory::getDbo(); - } catch (\Exception $e) { + } catch (\Exception) { return [ 'supported' => false, 'valid' => false, @@ -324,7 +307,7 @@ public static function getExtensionDownloadKey( try { $extension = new CMSObject($db->setQuery($query)->loadAssoc()); - } catch (\Exception $e) { + } catch (\Exception) { return [ 'supported' => false, 'valid' => false, @@ -362,9 +345,7 @@ public static function getDownloadKeySupportedSites($onlyEnabled = false): array }; $extensions = array_filter($extensions, $filterClosure); - $mapClosure = function (CMSObject $extension) { - return $extension->get('update_site_id'); - }; + $mapClosure = (fn (CMSObject $extension) => $extension->get('update_site_id')); return array_map($mapClosure, $extensions); } @@ -403,9 +384,7 @@ public static function getDownloadKeyExistsSites(bool $exists = true, $onlyEnabl $extensions = array_filter($extensions, $filterClosure); // Return only the update site IDs - $mapClosure = function (CMSObject $extension) { - return $extension->get('update_site_id'); - }; + $mapClosure = (fn (CMSObject $extension) => $extension->get('update_site_id')); return array_map($mapClosure, $extensions); } @@ -423,7 +402,7 @@ protected static function getUpdateSitesInformation(bool $onlyEnabled): array { try { $db = Factory::getDbo(); - } catch (\Exception $e) { + } catch (\Exception) { return []; } @@ -481,7 +460,7 @@ protected static function getUpdateSitesInformation(bool $onlyEnabled): array } return $items; - } catch (\Exception $e) { + } catch (\Exception) { return []; } } diff --git a/administrator/components/com_installer/src/Model/DatabaseModel.php b/administrator/components/com_installer/src/Model/DatabaseModel.php index 0c7f2caa199e5..03cffb5ef5976 100644 --- a/administrator/components/com_installer/src/Model/DatabaseModel.php +++ b/administrator/components/com_installer/src/Model/DatabaseModel.php @@ -176,7 +176,7 @@ private function fetchSchemaCache($cid = 0) $result->type === 'plugin' ? $result->folder : null ); - if ($installationXML !== null) { + if ($installationXML instanceof \SimpleXMLElement) { $folderTmp = (string) $installationXML->update->schemas->schemapath[0]; $a = explode('/', $folderTmp); array_pop($a); @@ -274,7 +274,7 @@ public function fix($cids = []) { $db = $this->getDatabase(); - foreach ($cids as $i => $cid) { + foreach ($cids as $cid) { // Load the database issues $this->fetchSchemaCache($cid); @@ -307,9 +307,8 @@ public function getItems() $this->fetchSchemaCache(); $results = parent::getItems(); - $results = $this->mergeSchemaCache($results); - return $results; + return $this->mergeSchemaCache($results); } /** @@ -380,8 +379,8 @@ protected function getListQuery() // Process search filter (update site id). $search = $this->getState('filter.search'); - if (!empty($search) && stripos($search, 'id:') === 0) { - $ids = (int) substr($search, 3); + if (!empty($search) && stripos((string) $search, 'id:') === 0) { + $ids = (int) substr((string) $search, 3); $query->where($db->quoteName('schemas.extension_id') . ' = :eid') ->bind(':eid', $ids, ParameterType::INTEGER); } @@ -479,7 +478,7 @@ public function fixSchemaVersion($changeSet, $extensionId) try { $db->execute(); - } catch (ExecutionFailureException $e) { + } catch (ExecutionFailureException) { return false; } @@ -530,11 +529,7 @@ public function compareUpdateVersion($extension) */ private function getOtherInformationMessage($status) { - $problemsMessage = []; - $problemsMessage[] = Text::sprintf('COM_INSTALLER_MSG_DATABASE_CHECKED_OK', \count($status['ok'])); - $problemsMessage[] = Text::sprintf('COM_INSTALLER_MSG_DATABASE_SKIPPED', \count($status['skipped'])); - - return $problemsMessage; + return [Text::sprintf('COM_INSTALLER_MSG_DATABASE_CHECKED_OK', \count($status['ok'])), Text::sprintf('COM_INSTALLER_MSG_DATABASE_SKIPPED', \count($status['skipped']))]; } /** @@ -550,7 +545,7 @@ private function getErrorsMessage($errors) { $errorMessages = []; - foreach ($errors as $line => $error) { + foreach ($errors as $error) { $key = 'COM_INSTALLER_MSG_DATABASE_' . $error->queryType; $messages = $error->msgElements; $file = basename($error->file); @@ -576,6 +571,7 @@ public function fixUpdateVersion($extensionId) { $table = new Extension($this->getDatabase()); $table->load($extensionId); + $cache = new Registry($table->manifest_cache); $updateVersion = $cache->get('version'); diff --git a/administrator/components/com_installer/src/Model/DiscoverModel.php b/administrator/components/com_installer/src/Model/DiscoverModel.php index eeb5fec3b761b..281b9a752e189 100644 --- a/administrator/components/com_installer/src/Model/DiscoverModel.php +++ b/administrator/components/com_installer/src/Model/DiscoverModel.php @@ -120,12 +120,10 @@ protected function getListQuery() // Process search filter. $search = $this->getState('filter.search'); - if (!empty($search)) { - if (stripos($search, 'id:') === 0) { - $ids = (int) substr($search, 3); - $query->where($db->quoteName('extension_id') . ' = :eid') - ->bind(':eid', $ids, ParameterType::INTEGER); - } + if (!empty($search) && stripos((string) $search, 'id:') === 0) { + $ids = (int) substr((string) $search, 3); + $query->where($db->quoteName('extension_id') . ' = :eid') + ->bind(':eid', $ids, ParameterType::INTEGER); } // Note: The search for name, ordering and pagination are processed by the parent InstallerModel class (in extension.php). @@ -260,7 +258,7 @@ public function purge() try { $db->execute(); - } catch (ExecutionFailureException $e) { + } catch (ExecutionFailureException) { $this->_message = Text::_('COM_INSTALLER_MSG_DISCOVER_FAILEDTOPURGEEXTENSIONS'); return false; diff --git a/administrator/components/com_installer/src/Model/InstallModel.php b/administrator/components/com_installer/src/Model/InstallModel.php index 953e90d38fbf5..6ca57c12addf5 100644 --- a/administrator/components/com_installer/src/Model/InstallModel.php +++ b/administrator/components/com_installer/src/Model/InstallModel.php @@ -20,6 +20,7 @@ use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Router\Route; +use Joomla\CMS\Table\Table; use Joomla\CMS\Updater\Update; use Joomla\CMS\Uri\Uri; use Joomla\Filesystem\Exception\FilesystemException; @@ -38,14 +39,14 @@ class InstallModel extends BaseDatabaseModel { /** - * @var \Joomla\CMS\Table\Table Table object + * @var Table Table object */ - protected $_table = null; + protected $_table; /** * @var string URL */ - protected $_url = null; + protected $_url; /** * Model context string. @@ -182,21 +183,17 @@ public function install() if (isset($package['dir']) && is_dir($package['dir'])) { $installer->setPath('source', $package['dir']); - if (!$installer->findManifest()) { - // If a manifest isn't found at the source, this may be a Joomla package; check the package directory for the Joomla manifest - if (file_exists($package['dir'] . '/administrator/manifests/files/joomla.xml')) { - // We have a Joomla package - if (\in_array($installType, ['upload', 'url'])) { - InstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']); - } - - $app->enqueueMessage( - Text::sprintf('COM_INSTALLER_UNABLE_TO_INSTALL_JOOMLA_PACKAGE', Route::_('index.php?option=com_joomlaupdate')), - 'warning' - ); - - return false; + // If a manifest isn't found at the source, this may be a Joomla package; check the package directory for the Joomla manifest + if (!$installer->findManifest() && file_exists($package['dir'] . '/administrator/manifests/files/joomla.xml')) { + // We have a Joomla package + if (\in_array($installType, ['upload', 'url'])) { + InstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']); } + $app->enqueueMessage( + Text::sprintf('COM_INSTALLER_UNABLE_TO_INSTALL_JOOMLA_PACKAGE', Route::_('index.php?option=com_joomlaupdate')), + 'warning' + ); + return false; } } @@ -214,7 +211,7 @@ public function install() // Install the package. if (!$installer->install($package['dir'])) { // There was an error installing the package. - $msg = Text::sprintf('COM_INSTALLER_INSTALL_ERROR', Text::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type']))); + $msg = Text::sprintf('COM_INSTALLER_INSTALL_ERROR', Text::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper((string) $package['type']))); $result = false; $msgType = 'error'; } else { @@ -329,8 +326,8 @@ protected function _getPackageFromUpload() // Move uploaded file. try { - File::upload($tmp_src, $tmp_dest, false, true); - } catch (FilesystemException $exception) { + File::upload($tmp_src, $tmp_dest, false); + } catch (FilesystemException) { Factory::getApplication()->enqueueMessage(Text::_('COM_INSTALLER_MSG_INSTALL_WARNINSTALLUPLOADERROR'), 'error'); return false; @@ -416,7 +413,7 @@ protected function _getPackageFromUrl() $update->loadFromXml($url); $package_url = trim($update->get('downloadurl', false)->_data); - if ($package_url) { + if ($package_url !== '' && $package_url !== '0') { $url = $package_url; } diff --git a/administrator/components/com_installer/src/Model/InstallerModel.php b/administrator/components/com_installer/src/Model/InstallerModel.php index 1ba176c78eff1..beecbebedda74 100644 --- a/administrator/components/com_installer/src/Model/InstallerModel.php +++ b/administrator/components/com_installer/src/Model/InstallerModel.php @@ -72,6 +72,7 @@ protected function _getList($query, $limitstart = 0, $limit = 0) // Replace slashes so preg_match will work $search = $this->getState('filter.search', ''); $search = str_replace('/', ' ', $search); + $db = $this->getDatabase(); // Define which fields have to be processed in a custom way because of translation. @@ -100,14 +101,14 @@ protected function _getList($query, $limitstart = 0, $limit = 0) // Check if search string exists in any of the fields to be searched. $found = 0; - foreach ($searchFields as $key => $field) { - if (!$found && preg_match('/' . $escapedSearchString . '/i', $item->{$field})) { + foreach ($searchFields as $field) { + if ($found === 0 && preg_match('/' . $escapedSearchString . '/i', (string) $item->{$field})) { $found = 1; } } // If search string was not found in any of the fields searched remove it from results array. - if (!$found) { + if ($found === 0) { unset($result[$i]); } } @@ -115,7 +116,7 @@ protected function _getList($query, $limitstart = 0, $limit = 0) // Process ordering. // Sort array object by selected ordering and selected direction. Sort is case insensitive and using locale sorting. - $result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) == 'desc' ? -1 : 1, false, true); + $result = ArrayHelper::sortObjects($result, $listOrder, strtolower((string) $listDirn) === 'desc' ? -1 : 1, false, true); // Process pagination. $total = \count($result); @@ -172,50 +173,58 @@ protected function translate(&$items) case 'component': $extension = $item->element; $source = JPATH_ADMINISTRATOR . '/components/' . $extension; - $lang->load("$extension.sys", JPATH_ADMINISTRATOR) || $lang->load("$extension.sys", $source); + if (!$lang->load($extension . '.sys', JPATH_ADMINISTRATOR)) { + $lang->load($extension . '.sys', $source); + } break; case 'file': $extension = 'files_' . $item->element; - $lang->load("$extension.sys", JPATH_SITE); + $lang->load($extension . '.sys', JPATH_SITE); break; case 'library': $parts = explode('/', $item->element); $vendor = (isset($parts[1]) ? $parts[0] : null); - $extension = 'lib_' . ($vendor ? implode('_', $parts) : $item->element); + $extension = 'lib_' . ($vendor !== null && $vendor !== '' && $vendor !== '0' ? implode('_', $parts) : $item->element); - if (!$lang->load("$extension.sys", $path)) { - $source = $path . '/libraries/' . ($vendor ? $vendor . '/' . $parts[1] : $item->element); - $lang->load("$extension.sys", $source); + if (!$lang->load($extension . '.sys', $path)) { + $source = $path . '/libraries/' . ($vendor !== null && $vendor !== '' && $vendor !== '0' ? $vendor . '/' . $parts[1] : $item->element); + $lang->load($extension . '.sys', $source); } break; case 'module': $extension = $item->element; $source = $path . '/modules/' . $extension; - $lang->load("$extension.sys", $path) || $lang->load("$extension.sys", $source); + if (!$lang->load($extension . '.sys', $path)) { + $lang->load($extension . '.sys', $source); + } break; case 'plugin': $extension = 'plg_' . $item->folder . '_' . $item->element; $source = JPATH_PLUGINS . '/' . $item->folder . '/' . $item->element; - $lang->load("$extension.sys", JPATH_ADMINISTRATOR) || $lang->load("$extension.sys", $source); + if (!$lang->load($extension . '.sys', JPATH_ADMINISTRATOR)) { + $lang->load($extension . '.sys', $source); + } break; case 'template': $extension = 'tpl_' . $item->element; $source = $path . '/templates/' . $item->element; - $lang->load("$extension.sys", $path) || $lang->load("$extension.sys", $source); + if (!$lang->load($extension . '.sys', $path)) { + $lang->load($extension . '.sys', $source); + } break; case 'package': default: $extension = $item->element; - $lang->load("$extension.sys", JPATH_SITE); + $lang->load($extension . '.sys', JPATH_SITE); break; } // Translate the extension name if possible $item->name = Text::_($item->name); - settype($item->description, 'string'); + $item->description = (string) $item->description; - if (!\in_array($item->type, ['language'])) { + if ($item->type != 'language') { $item->description = Text::_($item->description); } } diff --git a/administrator/components/com_installer/src/Model/LanguagesModel.php b/administrator/components/com_installer/src/Model/LanguagesModel.php index 3bf548db3dfb2..74378ebe76e13 100644 --- a/administrator/components/com_installer/src/Model/LanguagesModel.php +++ b/administrator/components/com_installer/src/Model/LanguagesModel.php @@ -14,6 +14,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\CMS\MVC\Model\ListModel; +use Joomla\Database\DatabaseQuery; use Joomla\String\StringHelper; // phpcs:disable PSR1.Files.SideEffects @@ -106,8 +107,8 @@ public function getItems() try { // Load the list items and add the items to the internal cache. $this->cache[$store] = $this->getLanguages(); - } catch (\RuntimeException $e) { - $this->setError($e->getMessage()); + } catch (\RuntimeException $runtimeException) { + $this->setError($runtimeException->getMessage()); return false; } @@ -131,19 +132,19 @@ protected function getLanguages() if (empty($updateSite)) { Factory::getApplication()->enqueueMessage(Text::_('COM_INSTALLER_MSG_WARNING_NO_LANGUAGES_UPDATESERVER'), 'warning'); - return; + return null; } try { $response = HttpFactory::getHttp()->get($updateSite); - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { $response = null; } if ($response === null || $response->code !== 200) { Factory::getApplication()->enqueueMessage(Text::sprintf('COM_INSTALLER_MSG_ERROR_CANT_CONNECT_TO_UPDATESERVER', $updateSite), 'error'); - return; + return null; } $updateSiteXML = simplexml_load_string($response->body); @@ -151,11 +152,11 @@ protected function getLanguages() if (!$updateSiteXML) { Factory::getApplication()->enqueueMessage(Text::sprintf('COM_INSTALLER_MSG_ERROR_CANT_RETRIEVE_XML', $updateSite), 'error'); - return; + return null; } $languages = []; - $search = strtolower($this->getState('filter.search', '')); + $search = strtolower((string) $this->getState('filter.search', '')); foreach ($updateSiteXML->extension as $extension) { $language = new \stdClass(); @@ -164,13 +165,8 @@ protected function getLanguages() $language->$key = (string) $value; } - if ($search) { - if ( - strpos(strtolower($language->name), $search) === false - && strpos(strtolower($language->element), $search) === false - ) { - continue; - } + if ($search !== '' && $search !== '0' && (!str_contains(strtolower($language->name), $search) && !str_contains(strtolower($language->element), $search))) { + continue; } $languages[$language->name] = $language; @@ -185,7 +181,7 @@ protected function getLanguages() function ($a, $b) use ($that) { $ordering = $that->getState('list.ordering', 'name'); - if (strtolower($that->getState('list.direction', 'asc')) === 'asc') { + if (strtolower((string) $that->getState('list.direction', 'asc')) === 'asc') { return StringHelper::strcmp($a->$ordering, $b->$ordering); } @@ -203,7 +199,7 @@ function ($a, $b) use ($that) { /** * Returns a record count for the updatesite. * - * @param \Joomla\Database\DatabaseQuery|string $query The query. + * @param DatabaseQuery|string $query The query. * * @return integer Number of rows for query. * diff --git a/administrator/components/com_installer/src/Model/ManageModel.php b/administrator/components/com_installer/src/Model/ManageModel.php index 841a20c16d773..9e55b8d2e18d7 100644 --- a/administrator/components/com_installer/src/Model/ManageModel.php +++ b/administrator/components/com_installer/src/Model/ManageModel.php @@ -232,14 +232,14 @@ public function remove($eid = []) // Get an installer object for the extension type $installer = Installer::getInstance(); - $row = new \Joomla\CMS\Table\Extension($this->getDatabase()); + $row = new Extension($this->getDatabase()); // Uninstall the chosen extensions $msgs = []; $result = false; foreach ($eid as $id) { - $id = trim($id); + $id = trim((string) $id); $row->load($id); $result = false; @@ -253,7 +253,7 @@ public function remove($eid = []) $langstring = 'COM_INSTALLER_TYPE_TYPE_' . strtoupper($row->type); $rowtype = Text::_($langstring); - if (strpos($rowtype, $langstring) !== false) { + if (str_contains($rowtype, $langstring)) { $rowtype = $row->type; } @@ -369,8 +369,8 @@ protected function getListQuery() // Process search filter (extension id). $search = $this->getState('filter.search'); - if (!empty($search) && stripos($search, 'id:') === 0) { - $ids = (int) substr($search, 3); + if (!empty($search) && stripos((string) $search, 'id:') === 0) { + $ids = (int) substr((string) $search, 3); $query->where($db->quoteName('extension_id') . ' = :eid') ->bind(':eid', $ids, ParameterType::INTEGER); } @@ -450,8 +450,7 @@ public function loadChangelog($eid, $source) } $layout = new FileLayout('joomla.installer.changelog'); - $output = $layout->render($entries); - return $output; + return $layout->render($entries); } } diff --git a/administrator/components/com_installer/src/Model/UpdateModel.php b/administrator/components/com_installer/src/Model/UpdateModel.php index 2cd000b8ca4a0..aa6b3aae6e834 100644 --- a/administrator/components/com_installer/src/Model/UpdateModel.php +++ b/administrator/components/com_installer/src/Model/UpdateModel.php @@ -19,6 +19,7 @@ use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\CMS\MVC\Model\ListModel; use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\Table\UpdateSite; use Joomla\CMS\Updater\Update; use Joomla\CMS\Updater\Updater; use Joomla\Database\Exception\ExecutionFailureException; @@ -145,24 +146,22 @@ protected function getListQuery() $search = $this->getState('filter.search'); if (!empty($search)) { - if (stripos($search, 'eid:') !== false) { - $sid = (int) substr($search, 4); + if (stripos((string) $search, 'eid:') !== false) { + $sid = (int) substr((string) $search, 4); $query->where($db->quoteName('u.extension_id') . ' = :sid') ->bind(':sid', $sid, ParameterType::INTEGER); + } elseif (stripos((string) $search, 'uid:') !== false) { + $suid = (int) substr((string) $search, 4); + $query->where($db->quoteName('u.update_site_id') . ' = :suid') + ->bind(':suid', $suid, ParameterType::INTEGER); + } elseif (stripos((string) $search, 'id:') !== false) { + $uid = (int) substr((string) $search, 3); + $query->where($db->quoteName('u.update_id') . ' = :uid') + ->bind(':uid', $uid, ParameterType::INTEGER); } else { - if (stripos($search, 'uid:') !== false) { - $suid = (int) substr($search, 4); - $query->where($db->quoteName('u.update_site_id') . ' = :suid') - ->bind(':suid', $suid, ParameterType::INTEGER); - } elseif (stripos($search, 'id:') !== false) { - $uid = (int) substr($search, 3); - $query->where($db->quoteName('u.update_id') . ' = :uid') - ->bind(':uid', $uid, ParameterType::INTEGER); - } else { - $search = '%' . str_replace(' ', '%', trim($search)) . '%'; - $query->where($db->quoteName('u.name') . ' LIKE :search') - ->bind(':search', $search); - } + $search = '%' . str_replace(' ', '%', trim((string) $search)) . '%'; + $query->where($db->quoteName('u.name') . ' LIKE :search') + ->bind(':search', $search); } } @@ -215,7 +214,7 @@ protected function _getList($query, $limitstart = 0, $limit = 0) $db->setQuery($query); $result = $db->loadObjectList(); $this->translate($result); - $result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) === 'desc' ? -1 : 1, true, true); + $result = ArrayHelper::sortObjects($result, $listOrder, strtolower((string) $listDirn) === 'desc' ? -1 : 1, true, true); $total = \count($result); if ($total < $limitstart) { @@ -286,7 +285,7 @@ public function purge() try { $db->truncateTable('#__updates'); - } catch (ExecutionFailureException $e) { + } catch (ExecutionFailureException) { $this->_message = Text::_('JLIB_INSTALLER_FAILED_TO_PURGE_UPDATES'); return false; @@ -352,7 +351,7 @@ public function update($uids, $minimumStability = Updater::STABILITY_STABLE) $update->loadFromXml($instance->detailsurl, $minimumStability); // Find and use extra_query from update_site if available - $updateSiteInstance = new \Joomla\CMS\Table\UpdateSite($this->getDatabase()); + $updateSiteInstance = new UpdateSite($this->getDatabase()); $updateSiteInstance->load($instance->update_site_id); if ($updateSiteInstance->extra_query) { @@ -421,7 +420,7 @@ private function install($update) $sources = $update->get('downloadSources', []); if ($extra_query = $update->get('extra_query')) { - $url .= (strpos($url, '?') === false) ? '?' : '&'; + $url .= (str_contains($url, '?')) ? '&' : '?'; $url .= $extra_query; } @@ -432,7 +431,7 @@ private function install($update) $url = trim($name->url); if ($extra_query) { - $url .= (strpos($url, '?') === false) ? '?' : '&'; + $url .= (str_contains($url, '?')) ? '&' : '?'; $url .= $extra_query; } @@ -481,7 +480,7 @@ private function install($update) $app->enqueueMessage( Text::sprintf( 'COM_INSTALLER_MSG_UPDATE_ERROR', - Text::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])) + Text::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper((string) $package['type'])) ), 'error' ); @@ -491,7 +490,7 @@ private function install($update) $app->enqueueMessage( Text::sprintf( 'COM_INSTALLER_MSG_UPDATE_SUCCESS', - Text::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])) + Text::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper((string) $package['type'])) ), 'success' ); diff --git a/administrator/components/com_installer/src/Model/UpdatesiteModel.php b/administrator/components/com_installer/src/Model/UpdatesiteModel.php index cdb5f0528eaaa..5b2efd737254c 100644 --- a/administrator/components/com_installer/src/Model/UpdatesiteModel.php +++ b/administrator/components/com_installer/src/Model/UpdatesiteModel.php @@ -161,7 +161,7 @@ public function save($data): bool try { $db->setQuery($query)->execute(); - } catch (\Exception $e) { + } catch (\Exception) { // No problem if this fails for any reason. } diff --git a/administrator/components/com_installer/src/Model/UpdatesitesModel.php b/administrator/components/com_installer/src/Model/UpdatesitesModel.php index b8b48d027f701..91c44fc4c13fb 100644 --- a/administrator/components/com_installer/src/Model/UpdatesitesModel.php +++ b/administrator/components/com_installer/src/Model/UpdatesitesModel.php @@ -95,7 +95,7 @@ public function publish(&$eid = [], $value = 1) $table = new UpdateSiteTable($this->getDatabase()); // Enable the update site in the table and store it in the database - foreach ($eid as $i => $id) { + foreach ($eid as $id) { $table->load($id); $table->enabled = $value; @@ -147,7 +147,7 @@ public function delete($ids = []) $joomlaUpdateSitesIds = $this->getJoomlaUpdateSitesIds(0); // Enable the update site in the table and store it in the database - foreach ($ids as $i => $id) { + foreach ($ids as $id) { // Don't allow to delete Joomla Core update sites. if (\in_array((int) $id, $joomlaUpdateSitesIds)) { $app->enqueueMessage(Text::sprintf('COM_INSTALLER_MSG_UPDATESITES_DELETE_CANNOT_DELETE', $updateSitesNames[$id]->name), 'error'); @@ -351,70 +351,68 @@ public function rebuild(): void // Create a unique array of files ordered by priority $xmlfiles = array_unique(array_merge($parentXmlfiles, $allXmlFiles)); - if (!empty($xmlfiles)) { - foreach ($xmlfiles as $file) { - // Is it a valid Joomla installation manifest file? - $manifest = $tmpInstaller->isManifest($file); - - if ($manifest !== null) { - /** - * Search if the extension exists in the extensions table. Excluding Joomla - * core extensions and discovered but not yet installed extensions. - */ - - $name = (string) $manifest->name; - $pkgName = (string) $manifest->packagename; - $type = (string) $manifest['type']; - - $query = $db->getQuery(true) - ->select($db->quoteName('extension_id')) - ->from($db->quoteName('#__extensions')) - ->where( - [ - $db->quoteName('type') . ' = :type', - $db->quoteName('state') . ' != -1', - ] - ) - ->extendWhere( - 'AND', - [ - $db->quoteName('name') . ' = :name', - $db->quoteName('name') . ' = :pkgname', - ], - 'OR' - ) - ->whereNotIn($db->quoteName('extension_id'), $joomlaCoreExtensionIds) - ->bind(':name', $name) - ->bind(':pkgname', $pkgName) - ->bind(':type', $type); - $db->setQuery($query); - - $eid = (int) $db->loadResult(); - - if ($eid && $manifest->updateservers) { - // Set the manifest object and path - $tmpInstaller->manifest = $manifest; - $tmpInstaller->setPath('manifest', $file); - - // Remove last extra_query as we are in a foreach - $tmpInstaller->extraQuery = ''; - - if ( - $tmpInstaller->manifest->updateservers - && $tmpInstaller->manifest->updateservers->server - && isset($backupExtraQuerys[trim((string) $tmpInstaller->manifest->updateservers->server)]) - ) { - $tmpInstaller->extraQuery = $backupExtraQuerys[trim((string) $tmpInstaller->manifest->updateservers->server)]['extra_query']; - } - - // Load the extension plugin (if not loaded yet). - PluginHelper::importPlugin('extension', 'joomla'); - - // Fire the onExtensionAfterUpdate - $app->triggerEvent('onExtensionAfterUpdate', ['installer' => $tmpInstaller, 'eid' => $eid]); - - $count++; + foreach ($xmlfiles as $file) { + // Is it a valid Joomla installation manifest file? + $manifest = $tmpInstaller->isManifest($file); + + if ($manifest !== null) { + /** + * Search if the extension exists in the extensions table. Excluding Joomla + * core extensions and discovered but not yet installed extensions. + */ + + $name = (string) $manifest->name; + $pkgName = (string) $manifest->packagename; + $type = (string) $manifest['type']; + + $query = $db->getQuery(true) + ->select($db->quoteName('extension_id')) + ->from($db->quoteName('#__extensions')) + ->where( + [ + $db->quoteName('type') . ' = :type', + $db->quoteName('state') . ' != -1', + ] + ) + ->extendWhere( + 'AND', + [ + $db->quoteName('name') . ' = :name', + $db->quoteName('name') . ' = :pkgname', + ], + 'OR' + ) + ->whereNotIn($db->quoteName('extension_id'), $joomlaCoreExtensionIds) + ->bind(':name', $name) + ->bind(':pkgname', $pkgName) + ->bind(':type', $type); + $db->setQuery($query); + + $eid = (int) $db->loadResult(); + + if ($eid && $manifest->updateservers) { + // Set the manifest object and path + $tmpInstaller->manifest = $manifest; + $tmpInstaller->setPath('manifest', $file); + + // Remove last extra_query as we are in a foreach + $tmpInstaller->extraQuery = ''; + + if ( + $tmpInstaller->manifest->updateservers + && $tmpInstaller->manifest->updateservers->server + && isset($backupExtraQuerys[trim((string) $tmpInstaller->manifest->updateservers->server)]) + ) { + $tmpInstaller->extraQuery = $backupExtraQuerys[trim((string) $tmpInstaller->manifest->updateservers->server)]['extra_query']; } + + // Load the extension plugin (if not loaded yet). + PluginHelper::importPlugin('extension', 'joomla'); + + // Fire the onExtensionAfterUpdate + $app->triggerEvent('onExtensionAfterUpdate', ['installer' => $tmpInstaller, 'eid' => $eid]); + + $count++; } } } @@ -585,8 +583,8 @@ protected function getListQuery() // Process search filter (update site id). $search = $this->getState('filter.search'); - if (!empty($search) && stripos($search, 'id:') === 0) { - $uid = (int) substr($search, 3); + if (!empty($search) && stripos((string) $search, 'id:') === 0) { + $uid = (int) substr((string) $search, 3); $query->where($db->quoteName('s.update_site_id') . ' = :siteId') ->bind(':siteId', $uid, ParameterType::INTEGER); } @@ -609,7 +607,7 @@ protected function getListQuery() break; } - if (!empty($supportedIDs)) { + if ($supportedIDs !== []) { // Don't remove array_values(). whereIn expect a zero-based array. $query->whereIn($db->quoteName('s.update_site_id'), array_values($supportedIDs)); } else { diff --git a/administrator/components/com_installer/src/Model/WarningsModel.php b/administrator/components/com_installer/src/Model/WarningsModel.php index 1c596941b65b1..c9209ead989a9 100644 --- a/administrator/components/com_installer/src/Model/WarningsModel.php +++ b/administrator/components/com_installer/src/Model/WarningsModel.php @@ -60,20 +60,12 @@ public function return_bytes($val) $val = (int) $matches[1]; } - switch (strtolower($last)) { - case 'g': - case 'gb': - $val *= (1024 * 1024 * 1024); - break; - case 'm': - case 'mb': - $val *= (1024 * 1024); - break; - case 'k': - case 'kb': - $val *= 1024; - break; - } + match (strtolower($last)) { + 'g', 'gb' => $val *= (1024 * 1024 * 1024), + 'm', 'mb' => $val *= (1024 * 1024), + 'k', 'kb' => $val *= 1024, + default => (int) $val, + }; return (int) $val; } @@ -100,7 +92,7 @@ public function getItems() $file_uploads = \ini_get('file_uploads'); - if (!$file_uploads) { + if ($file_uploads === '' || $file_uploads === '0' || $file_uploads === false) { $messages[] = [ 'message' => Text::_('COM_INSTALLER_MSG_WARNINGS_FILEUPLOADSDISABLED'), 'description' => Text::_('COM_INSTALLER_MSG_WARNINGS_FILEUPLOADISDISABLEDDESC'), @@ -109,7 +101,7 @@ public function getItems() $upload_dir = \ini_get('upload_tmp_dir'); - if (!$upload_dir) { + if ($upload_dir === '' || $upload_dir === '0' || $upload_dir === false) { $messages[] = [ 'message' => Text::_('COM_INSTALLER_MSG_WARNINGS_PHPUPLOADNOTSET'), 'description' => Text::_('COM_INSTALLER_MSG_WARNINGS_PHPUPLOADNOTSETDESC'), diff --git a/administrator/components/com_installer/src/View/Discover/HtmlView.php b/administrator/components/com_installer/src/View/Discover/HtmlView.php index 15b49338c5a2b..7cf9fc7a16572 100644 --- a/administrator/components/com_installer/src/View/Discover/HtmlView.php +++ b/administrator/components/com_installer/src/View/Discover/HtmlView.php @@ -10,7 +10,9 @@ namespace Joomla\Component\Installer\Administrator\View\Discover; +use Joomla\CMS\Form\Form; use Joomla\CMS\MVC\View\GenericDataException; +use Joomla\CMS\Pagination\Pagination; use Joomla\Component\Installer\Administrator\Model\DiscoverModel; use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as InstallerViewDefault; @@ -37,7 +39,7 @@ class HtmlView extends InstallerViewDefault /** * The pagination object * - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination * * @since 5.2.0 */ @@ -54,7 +56,7 @@ class HtmlView extends InstallerViewDefault /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form */ public $filterForm; @@ -90,12 +92,12 @@ public function display($tpl = null) $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); - if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { + if (\count($this->items) === 0 && $this->isEmptyState = $model->getIsEmptyState()) { $this->setLayout('emptystate'); } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_installer/src/View/Install/HtmlView.php b/administrator/components/com_installer/src/View/Install/HtmlView.php index 7d08d7a8dd57a..4c58dbbcbf867 100644 --- a/administrator/components/com_installer/src/View/Install/HtmlView.php +++ b/administrator/components/com_installer/src/View/Install/HtmlView.php @@ -27,6 +27,7 @@ */ class HtmlView extends InstallerViewDefault { + public $paths; /** * Display the view * diff --git a/administrator/components/com_installer/src/View/Installer/HtmlView.php b/administrator/components/com_installer/src/View/Installer/HtmlView.php index 50ba704383797..5a9160b8a2c51 100644 --- a/administrator/components/com_installer/src/View/Installer/HtmlView.php +++ b/administrator/components/com_installer/src/View/Installer/HtmlView.php @@ -16,6 +16,7 @@ use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Installer\Administrator\Model\InstallerModel; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -31,7 +32,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\Registry\Registry + * @var Registry * * @since 4.0.0 */ diff --git a/administrator/components/com_installer/src/View/Languages/HtmlView.php b/administrator/components/com_installer/src/View/Languages/HtmlView.php index a0e6c4bf50257..5496012a031d9 100644 --- a/administrator/components/com_installer/src/View/Languages/HtmlView.php +++ b/administrator/components/com_installer/src/View/Languages/HtmlView.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Installer\Administrator\View\Languages; use Joomla\CMS\Access\Exception\NotAllowed; +use Joomla\CMS\Form\Form; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\LanguageHelper; use Joomla\CMS\Language\Text; @@ -29,6 +30,10 @@ */ class HtmlView extends InstallerViewDefault { + /** + * @var mixed[] + */ + public $installedLang; /** * @var object item list */ @@ -42,7 +47,7 @@ class HtmlView extends InstallerViewDefault /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form */ public $filterForm; @@ -77,7 +82,7 @@ public function display($tpl = null) $this->installedLang = LanguageHelper::getInstalledLanguages(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_installer/src/View/Manage/HtmlView.php b/administrator/components/com_installer/src/View/Manage/HtmlView.php index e4b596bb53979..6533932ff340f 100644 --- a/administrator/components/com_installer/src/View/Manage/HtmlView.php +++ b/administrator/components/com_installer/src/View/Manage/HtmlView.php @@ -52,7 +52,7 @@ class HtmlView extends InstallerViewDefault /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form */ public $filterForm; @@ -84,7 +84,7 @@ public function display($tpl = null) $this->activeFilters = $model->getActiveFilters(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_installer/src/View/Update/HtmlView.php b/administrator/components/com_installer/src/View/Update/HtmlView.php index 819a80eeb4d57..f7b9490b23368 100644 --- a/administrator/components/com_installer/src/View/Update/HtmlView.php +++ b/administrator/components/com_installer/src/View/Update/HtmlView.php @@ -12,8 +12,10 @@ use Joomla\CMS\Application\CMSApplication; use Joomla\CMS\Factory; +use Joomla\CMS\Form\Form; use Joomla\CMS\Language\Text; use Joomla\CMS\Object\CMSObject; +use Joomla\CMS\Pagination\Pagination; use Joomla\Component\Installer\Administrator\Helper\InstallerHelper as CmsInstallerHelper; use Joomla\Component\Installer\Administrator\Model\UpdateModel; use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as InstallerViewDefault; @@ -29,6 +31,10 @@ */ class HtmlView extends InstallerViewDefault { + /** + * @var \stdClass + */ + public $paths; /** * List of update items. * @@ -39,7 +45,7 @@ class HtmlView extends InstallerViewDefault /** * List pagination. * - * @var \Joomla\CMS\Pagination\Pagination + * @var Pagination */ protected $pagination; @@ -60,7 +66,7 @@ class HtmlView extends InstallerViewDefault /** * Form object for search filters * - * @var \Joomla\CMS\Form\Form + * @var Form */ public $filterForm; @@ -100,7 +106,7 @@ public function display($tpl = null) } // Find if there are any updates which require but are missing a Download Key - if (!class_exists('Joomla\Component\Installer\Administrator\Helper\InstallerHelper')) { + if (!class_exists(CmsInstallerHelper::class)) { require_once JPATH_COMPONENT_ADMINISTRATOR . '/Helper/InstallerHelper.php'; } diff --git a/administrator/components/com_installer/src/View/Updatesite/HtmlView.php b/administrator/components/com_installer/src/View/Updatesite/HtmlView.php index f0d61c526ce92..bfa72f29b0b92 100644 --- a/administrator/components/com_installer/src/View/Updatesite/HtmlView.php +++ b/administrator/components/com_installer/src/View/Updatesite/HtmlView.php @@ -77,7 +77,7 @@ public function display($tpl = null): void } // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } @@ -101,7 +101,7 @@ protected function addToolbar(): void $user = $app->getIdentity(); $userId = $user->id; - $checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out === $userId); + $checkedOut = !\is_null($this->item->checked_out) && $this->item->checked_out !== $userId; // Since we don't track these assets at the item level, use the category id. $canDo = ContentHelper::getActions('com_installer', 'updatesite'); diff --git a/administrator/components/com_installer/src/View/Updatesites/HtmlView.php b/administrator/components/com_installer/src/View/Updatesites/HtmlView.php index 2bfa9b0e3420d..26422f5321609 100644 --- a/administrator/components/com_installer/src/View/Updatesites/HtmlView.php +++ b/administrator/components/com_installer/src/View/Updatesites/HtmlView.php @@ -82,7 +82,7 @@ public function display($tpl = null): void $this->activeFilters = $model->getActiveFilters(); // Check for errors. - if (\count($errors = $model->getErrors())) { + if (\count($errors = $model->getErrors()) !== 0) { throw new GenericDataException(implode("\n", $errors), 500); } diff --git a/administrator/components/com_installer/src/View/Warnings/HtmlView.php b/administrator/components/com_installer/src/View/Warnings/HtmlView.php index f480472187ab0..38e006e2e1e6d 100644 --- a/administrator/components/com_installer/src/View/Warnings/HtmlView.php +++ b/administrator/components/com_installer/src/View/Warnings/HtmlView.php @@ -24,6 +24,7 @@ */ class HtmlView extends InstallerViewDefault { + public $messages; /** * Display the view * @@ -40,7 +41,7 @@ public function display($tpl = null) $this->messages = $model->getItems(); - if (!\count($this->messages)) { + if (\count($this->messages) === 0) { $this->setLayout('emptystate'); } diff --git a/administrator/components/com_installer/tmpl/database/default.php b/administrator/components/com_installer/tmpl/database/default.php index dcbd008ce8c64..6ecf74284e399 100644 --- a/administrator/components/com_installer/tmpl/database/default.php +++ b/administrator/components/com_installer/tmpl/database/default.php @@ -97,7 +97,7 @@ type_translated; ?> - +