Skip to content

Commit

Permalink
Fix PHP 7.2 Warning: count(): Parameter must be an array or an object…
Browse files Browse the repository at this point in the history
… that implements Countable
  • Loading branch information
alecpl committed Nov 27, 2017
1 parent 5a63e52 commit 7c6bbd8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
41 changes: 29 additions & 12 deletions plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,15 @@ function actions()
// Initialize the form
$rules = rcube_utils::get_input_value('r', rcube_utils::INPUT_GET);
if (!empty($rules)) {
$i = 0;
$tests = array();
foreach ($rules as $rule) {
list($header, $value) = explode(':', $rule, 2);
$tests[$i] = array(
$tests[] = array(
'type' => 'contains',
'test' => 'header',
'arg1' => $header,
'arg2' => $value,
);
$i++;
}

$this->form = array(
Expand Down Expand Up @@ -757,7 +756,7 @@ function save()
$this->form['tests'][$i]['arg'] = $target;

if ($type != 'exists') {
if (!count($target)) {
if (empty($target)) {
$this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
}
else if (strpos($type, 'count-') === 0) {
Expand All @@ -774,7 +773,7 @@ function save()
}
}

if (!preg_match('/^(regex|matches|count-)/', $type) && count($target)) {
if (!preg_match('/^(regex|matches|count-)/', $type) && !empty($target)) {
foreach ($target as $arg) {
if (!$this->validate_date_part($datepart, $arg)) {
$this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat');
Expand Down Expand Up @@ -817,7 +816,7 @@ function save()
$this->form['tests'][$i]['header'] = $dateheader;

if ($type != 'exists') {
if (!count($target)) {
if (empty($target)) {
$this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
}
else if (strpos($type, 'count-') === 0) {
Expand All @@ -834,7 +833,7 @@ function save()
}
}

if (count($target) && !preg_match('/^(regex|matches|count-)/', $type)) {
if (!empty($target) && !preg_match('/^(regex|matches|count-)/', $type)) {
foreach ($target as $arg) {
if (!$this->validate_date_part($datepart, $arg)) {
$this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat');
Expand Down Expand Up @@ -1452,7 +1451,7 @@ function filter_form($attrib)

// 'any' flag
if ((!isset($this->form) && empty($scr['tests']) && !empty($scr))
|| (count($scr['tests']) == 1 && $scr['tests'][0]['test'] == 'true' && !$scr['tests'][0]['not'])
|| (is_array($scr['tests']) && count($scr['tests']) == 1 && $scr['tests'][0]['test'] == 'true' && !$scr['tests'][0]['not'])
) {
$any = true;
}
Expand Down Expand Up @@ -1587,8 +1586,17 @@ function filter_form($attrib)

function rule_div($fid, $id, $div = true, $compact = false)
{
$rule = isset($this->form) ? $this->form['tests'][$id] : $this->script[$fid]['tests'][$id];
$rows_num = isset($this->form) ? count($this->form['tests']) : count($this->script[$fid]['tests']);
$rule = isset($this->form) ? $this->form['tests'][$id] : $this->script[$fid]['tests'][$id];

if (isset($this->form['tests'])) {
$rows_num = count($this->form['tests']);
}
else if (isset($this->script[$fid]['tests'])) {
$rows_num = count($this->script[$fid]['tests']);
}
else {
$rows_num = 0;
}

// headers select
$select_header = new html_select(array('name' => "_header[]", 'id' => 'header'.$id,
Expand Down Expand Up @@ -2003,8 +2011,17 @@ private static function rule_test(&$rule)

function action_div($fid, $id, $div=true)
{
$action = isset($this->form) ? $this->form['actions'][$id] : $this->script[$fid]['actions'][$id];
$rows_num = isset($this->form) ? count($this->form['actions']) : count($this->script[$fid]['actions']);
$action = isset($this->form) ? $this->form['actions'][$id] : $this->script[$fid]['actions'][$id];

if (isset($this->form['actions'])) {
$rows_num = count($this->form['actions']);
}
else if (isset($this->script[$fid]['actions'])) {
$rows_num = count($this->script[$fid]['actions']);
}
else {
$rows_num = 0;
}

$out = $div ? '<div class="actionrow" id="actionrow' .$id .'">'."\n" : '';

Expand Down
4 changes: 2 additions & 2 deletions plugins/managesieve/lib/Roundcube/rcube_sieve_forward.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private function forward_post()
}

if (empty($forward_tests)) {
$forward_tests = $this->rc->config->get('managesieve_forward_test', array(array('test' => 'true')));
$forward_tests = (array) $this->rc->config->get('managesieve_forward_test', array(array('test' => 'true')));
}

if (!$error) {
Expand Down Expand Up @@ -468,7 +468,7 @@ public function set_forward($data)
}

if (empty($forward_tests)) {
$forward_tests = $this->rc->config->get('managesieve_forward_test', array(array('test' => 'true')));
$forward_tests = (array) $this->rc->config->get('managesieve_forward_test', array(array('test' => 'true')));
}

$rule = $this->forward;
Expand Down
6 changes: 3 additions & 3 deletions plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private function vacation_post()
}

if (empty($vacation_tests)) {
$vacation_tests = $this->rc->config->get('managesieve_vacation_test', array(array('test' => 'true')));
$vacation_tests = (array) $this->rc->config->get('managesieve_vacation_test', array(array('test' => 'true')));
}

if (!$error) {
Expand Down Expand Up @@ -378,7 +378,7 @@ public function vacation_form($attrib)
$action->add($this->plugin->gettext('vacation.copy'), 'copy');
}

if ($this->rc->config->get('managesieve_vacation') != 2 && count($this->vacation['list'])) {
if ($this->rc->config->get('managesieve_vacation') != 2 && !empty($this->vacation['list'])) {
$after = new html_select(array('name' => 'vacation_after', 'id' => 'vacation_after'));

$after->add('', '');
Expand Down Expand Up @@ -886,7 +886,7 @@ public function set_vacation($data)
}

if (empty($vacation_tests)) {
$vacation_tests = $this->rc->config->get('managesieve_vacation_test', array(array('test' => 'true')));
$vacation_tests = (array) $this->rc->config->get('managesieve_vacation_test', array(array('test' => 'true')));
}

$rule = $this->vacation;
Expand Down

0 comments on commit 7c6bbd8

Please sign in to comment.