From 2cb0637e9bc0371f92947a6dd98067063e748fe6 Mon Sep 17 00:00:00 2001 From: Peter Schulze Date: Wed, 24 Apr 2024 12:32:17 +0200 Subject: [PATCH] cleanup (after rexstan use) --- .../fragments/yform/manager/history.diff.php | 22 ++++----- plugins/manager/lib/yform_history_helper.php | 46 +++++++++---------- plugins/manager/pages/data_history.php | 4 +- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/plugins/manager/fragments/yform/manager/history.diff.php b/plugins/manager/fragments/yform/manager/history.diff.php index a63879cd..000dcc92 100644 --- a/plugins/manager/fragments/yform/manager/history.diff.php +++ b/plugins/manager/fragments/yform/manager/history.diff.php @@ -13,9 +13,9 @@ $table = $this->getVar('table', null); $sql = rex_sql::factory(); -$timestamp = (string) $sql->setQuery(sprintf('SELECT `timestamp` FROM %s WHERE id = %d', rex::getTable('yform_history'), $historyId))->getValue('timestamp'); +$timestamp = $sql->setQuery(sprintf('SELECT `timestamp` FROM %s WHERE id = :id', rex::getTable('yform_history')), [':id' => $historyId])->getValue('timestamp'); -$data = $sql->getArray(sprintf('SELECT * FROM %s WHERE history_id = %d', rex::getTable('yform_history_field'), $historyId)); +$data = $sql->getArray(sprintf('SELECT * FROM %s WHERE history_id = :history_id', rex::getTable('yform_history_field')), [':history_id' => $historyId]); $data = array_column($data, 'value', 'field'); @@ -60,17 +60,15 @@ // count diffs if(!$currentDataset->hasValue($field->getName())) { $change = 'deleted'; - } elseif("" . $historyValue != "" . $currentValue) { + } elseif("" . $historyValue !== "" . $currentValue) { $change = 'changed'; } $diffs[$change]['count']++; - if (is_callable($class, 'getListValue') && !in_array($field->getTypeName(), ['text', 'textarea'])) { - /** @var $class rex_yform_value_abstract */ - + if (is_callable([$class, 'getListValue']) && !in_array($field->getTypeName(), ['text', 'textarea'], true)) { // to ensure correct replacement with list value, ensure datatype by current dataset - if(gettype($currentValue) != gettype($historyValue)) { + if(gettype($currentValue) !== gettype($historyValue)) { settype($historyValue, gettype($currentValue)); } @@ -105,7 +103,7 @@ } // diff values for specific fields - if($change == 'changed') { + if($change === 'changed') { switch($field->getTypeName()) { case 'text': case 'textarea': @@ -114,7 +112,7 @@ break; default: - if($historyValue != $currentValue) { + if($historyValue !== $currentValue) { $historyValue = '' . $historyValue . ''; } break; @@ -165,14 +163,14 @@ foreach ($diffs as $change => $diff) { $content .= ' -
+
' . rex_i18n::msg('yform_history_diff_headline_' . $change) . ' [' . ($diff['count'] > 0 ? '' : '') . $diff['count'] . ($diff['count'] > 0 ? '' : '') . ']' . '
-
'; +
'; - if($diff['rows'] != '') { + if($diff['rows'] !== '') { $content .= ' diff --git a/plugins/manager/lib/yform_history_helper.php b/plugins/manager/lib/yform_history_helper.php index 52f78a4d..8d20d565 100644 --- a/plugins/manager/lib/yform_history_helper.php +++ b/plugins/manager/lib/yform_history_helper.php @@ -9,7 +9,7 @@ */ class rex_yform_history_helper { - const FIELD_TYPE_ICONS = [ + const array FIELD_TYPE_ICONS = [ 'question' => 'question', 'checkbox' => 'square-check', @@ -40,7 +40,7 @@ class rex_yform_history_helper 'email' => 'at' ]; - const FIELD_TYPE_ICON_WEIGHT_CLASS = 'far'; + const string FIELD_TYPE_ICON_WEIGHT_CLASS = 'far'; /** * detect diffs in 2 strings @@ -51,13 +51,13 @@ class rex_yform_history_helper * @created 17.04.2024 * @copyright https://github.com/paulgb/simplediff | Paul Butler (paulgb) */ - public static function diffStrings($old, $new):array + public static function diffStrings($old, $new): array { $matrix = array(); - $maxlen = 0; + $maxlen = $omax = $nmax = 0; foreach ($old as $oindex => $ovalue) { - $nkeys = array_keys($new, $ovalue); + $nkeys = array_keys($new, $ovalue, true); foreach ($nkeys as $nindex) { $matrix[$oindex][$nindex] = @@ -74,14 +74,14 @@ public static function diffStrings($old, $new):array } } - if ($maxlen == 0) { + if ($maxlen === 0) { return array(array('d' => $old, 'i' => $new)); } return array_merge( - self::diffStrings(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)), + rex_yform_history_helper::diffStrings(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)), array_slice($new, $nmax, $maxlen), - self::diffStrings(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)) + rex_yform_history_helper::diffStrings(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)) ); } @@ -94,20 +94,16 @@ public static function diffStrings($old, $new):array * @created 17.04.2024 * @copyright https://github.com/paulgb/simplediff | Paul Butler (paulgb) */ - public static function diffStringsToHtml($old, $new) + public static function diffStringsToHtml($old, $new): string { $ret = ''; - $diff = self::diffStrings(preg_split("/[\s]+/", $old), preg_split("/[\s]+/", $new)); + $diff = rex_yform_history_helper::diffStrings(preg_split("/[\s]+/", $old), preg_split("/[\s]+/", $new)); foreach ($diff as $k) { - if (is_array($k)) { - $ret .= - (!empty($k['d']) ? "" . implode(' ', $k['d']) . " " : ''). - (!empty($k['i']) ? "" . implode(' ', $k['i']) . " " : '') - ; - } else { - $ret .= $k . ' '; - } + $ret .= + (isset($k['d']) ? "" . implode(' ', $k['d']) . " " : ''). + (isset($k['i']) ? "" . implode(' ', $k['i']) . " " : '') + ; } return $ret; @@ -126,8 +122,8 @@ public static function diffStringsToHtml($old, $new) */ public static function getFieldTypeIcon(rex_yform_manager_field $field, bool $addPrefix = true, bool $outputHtml = true, bool $addTooltip = true, string $tooltipPlacement = 'top'):string { - $icon = self::FIELD_TYPE_ICONS[$field->getTypeName()] ?? 'default'; - $tag = isset(self::FIELD_TYPE_ICONS[$field->getTypeName()]) ? 'i' : 'span'; + $icon = rex_yform_history_helper::FIELD_TYPE_ICONS[$field->getTypeName()] ?? 'default'; + $tag = isset(rex_yform_history_helper::FIELD_TYPE_ICONS[$field->getTypeName()]) ? 'i' : 'span'; switch($field->getTypeName()) { case 'choice': @@ -135,9 +131,9 @@ public static function getFieldTypeIcon(rex_yform_manager_field $field, bool $ad $multiple = (bool)(int)$field->getElement('multiple'); if($expanded && $multiple) { - $icon = self::FIELD_TYPE_ICONS['choice_checkbox']; + $icon = rex_yform_history_helper::FIELD_TYPE_ICONS['choice_checkbox']; } elseif($expanded) { - $icon = self::FIELD_TYPE_ICONS['choice_radio']; + $icon = rex_yform_history_helper::FIELD_TYPE_ICONS['choice_radio']; } break; } @@ -147,7 +143,7 @@ public static function getFieldTypeIcon(rex_yform_manager_field $field, bool $ad ($addTooltip ? ' data-toggle="tooltip" data-placement="' . $tooltipPlacement . '" title="' . rex_i18n::msg('yform_manager_type_name') . ': ' . $field->getTypeName() . '"' : '') . ' class="' : '' ). - ($icon !== 'default' ? self::FIELD_TYPE_ICON_WEIGHT_CLASS . ' ' : '').($addPrefix ? 'rex-icon ' : '') . 'fa-' . $icon . + ($icon !== 'default' ? rex_yform_history_helper::FIELD_TYPE_ICON_WEIGHT_CLASS . ' ' : '').($addPrefix ? 'rex-icon ' : '') . 'fa-' . $icon . ($outputHtml ? '">' : ''); } @@ -164,8 +160,8 @@ public static function getFieldValue(rex_yform_manager_field $field, rex_yform_m $class = 'rex_yform_value_' . $field->getTypeName(); $currentValue = ($dataset->hasValue($field->getName()) ? $dataset->getValue($field->getName()) : '-'); - if (is_callable($class, 'getListValue') && !in_array($field->getTypeName(), ['text','textarea'])) { - /** @var $class rex_yform_value_abstract */ + if (is_callable([$class, 'getListValue']) && !in_array($field->getTypeName(), ['text','textarea'], true)) { + /** @var rex_yform_value_abstract $class */ // get (formatted) value for current entry if($dataset->hasValue($field->getName())) { diff --git a/plugins/manager/pages/data_history.php b/plugins/manager/pages/data_history.php index 0b15e435..75d940c8 100644 --- a/plugins/manager/pages/data_history.php +++ b/plugins/manager/pages/data_history.php @@ -214,7 +214,7 @@ $list->setColumnFormat( $revision, 'custom', - static function($a) use (&$rev, &$historyDatasets, &$table, &$sql, &$dataset) { + static function($a) use (&$rev, &$historyDatasets, &$table, &$sql) { // early column ... store all values for current revision $rev = rex::getProperty('YFORM_HISTORY_REVISION', 0); @@ -287,7 +287,7 @@ static function($a) use (&$rev, &$historyDatasets, &$table, &$sql, &$dataset) { $list->setColumnFormat( $changesCurrent, 'custom', - static function($a) use (&$dataset, $table, $sql, &$historyDatasets, $actionsCell, $normalCell, $changesCurrent) { + static function($a) use (&$dataset, $table, &$historyDatasets, $actionsCell, $normalCell, $changesCurrent) { $rev = rex::getProperty('YFORM_HISTORY_REVISION', 0) - 1; $changes = 0;