Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rector test #44617

Open
wants to merge 13 commits into
base: 5.3-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -310,7 +310,7 @@ public static function loadActionLogPluginsLanguage()

try {
$rows = $db->loadObjectList();
} catch (\RuntimeException $e) {
} catch (\RuntimeException) {
$rows = [];
}

Expand All @@ -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
Expand Down Expand Up @@ -362,7 +363,7 @@ protected static function escapeCsvFormula($value)
}

if (\in_array($value[0], self::$characters, true)) {
$value = ' ' . $value;
return ' ' . $value;
}

return $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -85,15 +85,15 @@ public function addLog($messages, $messageLanguageKey, $context, $userId = 0)
try {
$db->insertObject('#__action_logs', $logMessage);
$loggedMessages[] = $logMessage;
} catch (\RuntimeException $e) {
} catch (\RuntimeException) {
// Ignore it
}
}

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
}
}
Expand Down Expand Up @@ -143,7 +143,7 @@ protected function sendNotificationEmails($messages, $username, $context)
}
}

if (empty($recipients)) {
if ($recipients === []) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -363,7 +363,7 @@ public function purge()
{
try {
$this->getDatabase()->truncateTable('#__action_logs');
} catch (\Exception $e) {
} catch (\Exception) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading