Skip to content

Commit d4bc468

Browse files
committed
Update modOutputFilter.php
Code style/quality fixes
1 parent 6c43562 commit d4bc468

File tree

1 file changed

+42
-30
lines changed

1 file changed

+42
-30
lines changed

core/src/Revolution/Filters/modOutputFilter.php

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/*
34
* This file is part of the MODX Revolution package.
45
*
@@ -10,7 +11,6 @@
1011

1112
namespace MODX\Revolution\Filters;
1213

13-
1414
use Exception;
1515
use MODX\Revolution\Formatter\modManagerDateFormatter;
1616
use MODX\Revolution\modElement;
@@ -36,7 +36,7 @@ class modOutputFilter
3636
/**
3737
* @param modX $modx A reference to the modX instance
3838
*/
39-
function __construct(modX &$modx)
39+
public function __construct(modX &$modx)
4040
{
4141
$this->modx = &$modx;
4242
$this->formatter = $this->modx->services->get(modManagerDateFormatter::class);
@@ -49,7 +49,7 @@ function __construct(modX &$modx)
4949
*/
5050
public function filter(&$element)
5151
{
52-
$usemb = function_exists('mb_strlen') && (boolean)$this->modx->getOption('use_multibyte', null, false);
52+
$usemb = function_exists('mb_strlen') && (bool)$this->modx->getOption('use_multibyte', null, false);
5353
$encoding = $this->modx->getOption('modx_charset', null, 'UTF-8');
5454

5555
$output = &$element->_output;
@@ -61,7 +61,6 @@ public function filter(&$element)
6161
$condition = [];
6262

6363
for ($i = 0; $i < $count; $i++) {
64-
6564
$m_cmd = trim($modifier_cmd[$i]);
6665
$m_val = $modifier_value[$i];
6766

@@ -127,7 +126,7 @@ public function filter(&$element)
127126
$condition[] = intval(stripos($output, $m_val) !== false);
128127
break;
129128
case 'containsnot':
130-
$condition[] = intval(stripos($output, $m_val) === false);;
129+
$condition[] = intval(stripos($output, $m_val) === false);
131130
break;
132131
case 'ismember':
133132
case 'memberof':
@@ -328,12 +327,16 @@ public function filter(&$element)
328327
if ($limit < 0) {
329328
$limit = 0;
330329
}
331-
$breakpoint = $usemb ? mb_strpos($output, " ", $limit, $encoding) : strpos($output, " ",
332-
$limit);
330+
$breakpoint = $usemb
331+
? mb_strpos($output, ' ', $limit, $encoding)
332+
: strpos($output, ' ', $limit)
333+
;
333334
if (false !== $breakpoint) {
334335
if ($breakpoint < $len - 1) {
335-
$partial = $usemb ? mb_substr($output, 0, $breakpoint, $encoding) : substr($output,
336-
0, $breakpoint);
336+
$partial = $usemb
337+
? mb_substr($output, 0, $breakpoint, $encoding)
338+
: substr($output, 0, $breakpoint)
339+
;
337340
$output = $partial . $pad;
338341
}
339342
}
@@ -564,32 +567,46 @@ public function filter(&$element)
564567

565568
$ago = [];
566569
if (!empty($agoTS['years'])) {
567-
$ago[] = $this->modx->lexicon(($agoTS['years'] > 1 ? 'ago_years' : 'ago_year'),
568-
['time' => $agoTS['years']]);
570+
$ago[] = $this->modx->lexicon(
571+
($agoTS['years'] > 1 ? 'ago_years' : 'ago_year'),
572+
['time' => $agoTS['years']]
573+
);
569574
}
570575
if (!empty($agoTS['months'])) {
571-
$ago[] = $this->modx->lexicon(($agoTS['months'] > 1 ? 'ago_months' : 'ago_month'),
572-
['time' => $agoTS['months']]);
576+
$ago[] = $this->modx->lexicon(
577+
($agoTS['months'] > 1 ? 'ago_months' : 'ago_month'),
578+
['time' => $agoTS['months']]
579+
);
573580
}
574581
if (!empty($agoTS['weeks']) && empty($agoTS['years'])) {
575-
$ago[] = $this->modx->lexicon(($agoTS['weeks'] > 1 ? 'ago_weeks' : 'ago_week'),
576-
['time' => $agoTS['weeks']]);
582+
$ago[] = $this->modx->lexicon(
583+
($agoTS['weeks'] > 1 ? 'ago_weeks' : 'ago_week'),
584+
['time' => $agoTS['weeks']]
585+
);
577586
}
578587
if (!empty($agoTS['days']) && empty($agoTS['months']) && empty($agoTS['years'])) {
579-
$ago[] = $this->modx->lexicon(($agoTS['days'] > 1 ? 'ago_days' : 'ago_day'),
580-
['time' => $agoTS['days']]);
588+
$ago[] = $this->modx->lexicon(
589+
($agoTS['days'] > 1 ? 'ago_days' : 'ago_day'),
590+
['time' => $agoTS['days']]
591+
);
581592
}
582593
if (!empty($agoTS['hours']) && empty($agoTS['weeks']) && empty($agoTS['months']) && empty($agoTS['years'])) {
583-
$ago[] = $this->modx->lexicon(($agoTS['hours'] > 1 ? 'ago_hours' : 'ago_hour'),
584-
['time' => $agoTS['hours']]);
594+
$ago[] = $this->modx->lexicon(
595+
($agoTS['hours'] > 1 ? 'ago_hours' : 'ago_hour'),
596+
['time' => $agoTS['hours']]
597+
);
585598
}
586599
if (!empty($agoTS['minutes']) && empty($agoTS['days']) && empty($agoTS['weeks']) && empty($agoTS['months']) && empty($agoTS['years'])) {
587-
$ago[] = $this->modx->lexicon($agoTS['minutes'] == 1 ? 'ago_minute' : 'ago_minutes',
588-
['time' => $agoTS['minutes']]);
600+
$ago[] = $this->modx->lexicon(
601+
($agoTS['minutes'] == 1 ? 'ago_minute' : 'ago_minutes'),
602+
['time' => $agoTS['minutes']]
603+
);
589604
}
590605
if (empty($ago)) { /* handle <1 min */
591-
$ago[] = $this->modx->lexicon('ago_seconds',
592-
['time' => !empty($agoTS['seconds']) ? $agoTS['seconds'] : 0]);
606+
$ago[] = $this->modx->lexicon(
607+
'ago_seconds',
608+
['time' => !empty($agoTS['seconds']) ? $agoTS['seconds'] : 0]
609+
);
593610
}
594611
$output = implode(', ', $ago);
595612
$output = $this->modx->lexicon('ago', ['time' => $output]);
@@ -628,12 +645,9 @@ public function filter(&$element)
628645
if ($user = $this->modx->getObjectGraph(modUser::class, '{"Profile":{}}', $output)) {
629646
$userData = array_merge($user->toArray(), $user->Profile->toArray());
630647
unset($userData['cachepwd'], $userData['salt'], $userData['sessionid'], $userData['password'], $userData['session_stale']);
631-
if (strpos($key, 'extended.') === 0 && isset($userData['extended'][substr($key,
632-
9)])) {
648+
if (strpos($key, 'extended.') === 0 && isset($userData['extended'][substr($key, 9)])) {
633649
$userInfo = $userData['extended'][substr($key, 9)];
634-
} elseif (strpos($key,
635-
'remote_data.') === 0 && isset($userData['remote_data'][substr($key,
636-
12)])) {
650+
} elseif (strpos($key, 'remote_data.') === 0 && isset($userData['remote_data'][substr($key, 12)])) {
637651
$userInfo = $userData['remote_data'][substr($key, 12)];
638652
} elseif (isset($userData[$key])) {
639653
$userInfo = $userData[$key];
@@ -804,11 +818,9 @@ private static function parseConditions($conditions, $value = null, $default = n
804818

805819
return $default;
806820
}
807-
808821
if (!$m_con) {
809822
return $value;
810823
}
811-
812824
} catch (Exception $e) {
813825
}
814826

0 commit comments

Comments
 (0)