From 7e3298753a9f93405ef44b46ba4db4ca98553b51 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sat, 14 Nov 2015 04:08:07 -0500
Subject: [PATCH] Use ternary operator where aplicable

---
 program/lib/Roundcube/rcube.php                |   10 ++--
 program/lib/Roundcube/rcube_tnef_decoder.php   |    2 
 program/lib/Roundcube/rcube_addressbook.php    |    2 
 program/lib/Roundcube/rcube_spellcheck_atd.php |    2 
 program/lib/Roundcube/rcube_vcard.php          |    8 ++--
 program/lib/Roundcube/rcube_contacts.php       |    2 
 program/lib/Roundcube/rcube_mime.php           |    2 
 program/lib/Roundcube/rcube_storage.php        |    2 
 program/lib/Roundcube/rcube_spellchecker.php   |    4 +-
 program/lib/Roundcube/rcube_utils.php          |    4 +-
 program/lib/Roundcube/rcube_smtp.php           |   10 ++--
 program/lib/Roundcube/rcube_ldap.php           |   23 +++++------
 program/lib/Roundcube/rcube_db.php             |    2 
 program/lib/Roundcube/rcube_imap_generic.php   |    4 +-
 program/lib/Roundcube/rcube_plugin_api.php     |    4 +-
 program/lib/Roundcube/rcube_charset.php        |    6 +-
 16 files changed, 43 insertions(+), 44 deletions(-)

diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php
index a1773a8..3b17d99 100644
--- a/program/lib/Roundcube/rcube.php
+++ b/program/lib/Roundcube/rcube.php
@@ -505,7 +505,7 @@
         }
 
         ini_set('session.cookie_secure', $is_secure);
-        ini_set('session.name', $sess_name ? $sess_name : 'roundcube_sessid');
+        ini_set('session.name', $sess_name ?: 'roundcube_sessid');
         ini_set('session.use_cookies', 1);
         ini_set('session.use_only_cookies', 1);
         ini_set('session.cookie_httponly', 1);
@@ -601,7 +601,7 @@
             $attrib = array('name' => $attrib);
         }
 
-        $name = $attrib['name'] ? $attrib['name'] : '';
+        $name = (string) $attrib['name'];
 
         // attrib contain text values: use them from now
         if (($setval = $attrib[strtolower($_SESSION['language'])]) || ($setval = $attrib['en_us'])) {
@@ -619,7 +619,7 @@
         // replace vars in text
         if (is_array($attrib['vars'])) {
             foreach ($attrib['vars'] as $var_key => $var_value) {
-                $text = str_replace($var_key[0]!='$' ? '$'.$var_key : $var_key, $var_value, $text);
+                $text = str_replace($var_key[0] != '$' ? '$'.$var_key : $var_key, $var_value, $text);
             }
         }
 
@@ -685,7 +685,7 @@
      */
     public function load_language($lang = null, $add = array(), $merge = array())
     {
-        $lang = $this->language_prop(($lang ? $lang : $_SESSION['language']));
+        $lang = $this->language_prop($lang ?: $_SESSION['language']);
 
         // load localized texts
         if (empty($this->texts) || $lang != $_SESSION['language']) {
@@ -1267,7 +1267,7 @@
      */
     public static function log_bug($arg_arr)
     {
-        $program = strtoupper(!empty($arg_arr['type']) ? $arg_arr['type'] : 'php');
+        $program = strtoupper($arg_arr['type'] ?: 'php');
         $level   = self::get_instance()->config->get('debug_level');
 
         // disable errors for ajax requests, write to log instead (#1487831)
diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php
index eb8bd3d..325b48a 100644
--- a/program/lib/Roundcube/rcube_addressbook.php
+++ b/program/lib/Roundcube/rcube_addressbook.php
@@ -539,7 +539,7 @@
         else if ($compose_mode == 1)
             $fn = join(' ', array($contact['firstname'], $contact['middlename'], $contact['surname']));
         else if ($compose_mode == 0)
-            $fn = !empty($contact['name']) ? $contact['name'] : join(' ', array($contact['prefix'], $contact['firstname'], $contact['middlename'], $contact['surname'], $contact['suffix']));
+            $fn = $contact['name'] ?: join(' ', array($contact['prefix'], $contact['firstname'], $contact['middlename'], $contact['surname'], $contact['suffix']));
         else {
             $plugin = rcube::get_instance()->plugins->exec_hook('contact_listname', array('contact' => $contact));
             $fn     = $plugin['fn'];
diff --git a/program/lib/Roundcube/rcube_charset.php b/program/lib/Roundcube/rcube_charset.php
index 9d5d55e..2d6d9d3 100644
--- a/program/lib/Roundcube/rcube_charset.php
+++ b/program/lib/Roundcube/rcube_charset.php
@@ -119,7 +119,7 @@
         }
         // ISO-8859
         else if (preg_match('/ISO8859([0-9]{0,2})/', $str, $m)) {
-            $iso = 'ISO-8859-' . ($m[1] ? $m[1] : 1);
+            $iso = 'ISO-8859-' . ($m[1] ?: 1);
             // some clients sends windows-1252 text as latin1,
             // it is safe to use windows-1252 for all latin1
             $result = $iso == 'ISO-8859-1' ? 'WINDOWS-1252' : $iso;
@@ -238,8 +238,8 @@
                 $aliases['US-ASCII'] = 'ASCII';
             }
 
-            $mb_from = $aliases[$from] ? $aliases[$from] : $from;
-            $mb_to   = $aliases[$to] ? $aliases[$to] : $to;
+            $mb_from = $aliases[$from] ?: $from;
+            $mb_to   = $aliases[$to] ?: $to;
 
             // return if encoding found, string matches encoding and convert succeeded
             if (in_array($mb_from, $mbstring_list) && in_array($mb_to, $mbstring_list)) {
diff --git a/program/lib/Roundcube/rcube_contacts.php b/program/lib/Roundcube/rcube_contacts.php
index 4bdec18..5ac5759 100644
--- a/program/lib/Roundcube/rcube_contacts.php
+++ b/program/lib/Roundcube/rcube_contacts.php
@@ -741,7 +741,7 @@
         $words = '';
 
         // copy values into vcard object
-        $vcard = new rcube_vcard($record['vcard'] ? $record['vcard'] : $save_data['vcard'], RCUBE_CHARSET, false, $this->vcard_fieldmap);
+        $vcard = new rcube_vcard($record['vcard'] ?: $save_data['vcard'], RCUBE_CHARSET, false, $this->vcard_fieldmap);
         $vcard->reset();
 
         // don't store groups in vCard (#1490277)
diff --git a/program/lib/Roundcube/rcube_db.php b/program/lib/Roundcube/rcube_db.php
index 8c5bc19..ba3acf6 100644
--- a/program/lib/Roundcube/rcube_db.php
+++ b/program/lib/Roundcube/rcube_db.php
@@ -1183,7 +1183,7 @@
         }
 
         // process the different protocol options
-        $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
+        $parsed['protocol'] = $proto ?: 'tcp';
         $proto_opts = rawurldecode($proto_opts);
         if (strpos($proto_opts, ':') !== false) {
             list($proto_opts, $parsed['port']) = explode(':', $proto_opts);
diff --git a/program/lib/Roundcube/rcube_imap_generic.php b/program/lib/Roundcube/rcube_imap_generic.php
index f45f608..caf2ebe 100644
--- a/program/lib/Roundcube/rcube_imap_generic.php
+++ b/program/lib/Roundcube/rcube_imap_generic.php
@@ -194,7 +194,7 @@
 
         do {
             if ($this->eof()) {
-                return $line ? $line : null;
+                return $line ?: null;
             }
 
             $buffer = fgets($this->fp, $size);
@@ -462,7 +462,7 @@
             }
         }
 
-        return !empty($result) ? $result : false;
+        return $result ?: false;
     }
 
     /**
diff --git a/program/lib/Roundcube/rcube_ldap.php b/program/lib/Roundcube/rcube_ldap.php
index 208588c..b08ee7b 100644
--- a/program/lib/Roundcube/rcube_ldap.php
+++ b/program/lib/Roundcube/rcube_ldap.php
@@ -285,8 +285,7 @@
             $bind_dn   = $this->prop['bind_dn'];
 
             $this->base_dn        = $this->prop['base_dn'];
-            $this->groups_base_dn = ($this->prop['groups']['base_dn']) ?
-                $this->prop['groups']['base_dn'] : $this->base_dn;
+            $this->groups_base_dn = $this->prop['groups']['base_dn'] ?: $this->base_dn;
 
             // User specific access, generate the proper values to use.
             if ($this->prop['user_specific']) {
@@ -677,7 +676,7 @@
         $attrib = array_merge($attrib, array_values($this->group_types));
         $attrib[] = 'memberURL';
 
-        $filter = $this->prop['groups']['member_filter'] ? $this->prop['groups']['member_filter'] : '(objectclass=*)';
+        $filter = $this->prop['groups']['member_filter'] ?: '(objectclass=*)';
 
         for ($i=0; $i < $entry[$attr]['count']; $i++) {
             if (empty($entry[$attr][$i]))
@@ -1312,7 +1311,7 @@
             }
         }
 
-        return $newdn ? $newdn : true;
+        return $newdn ?: true;
     }
 
     /**
@@ -1372,7 +1371,7 @@
     function delete_all($with_groups = false)
     {
         // searching for contact entries
-        $dn_list = $this->ldap->list_entries($this->base_dn, $this->prop['filter'] ? $this->prop['filter'] : '(objectclass=*)');
+        $dn_list = $this->ldap->list_entries($this->base_dn, $this->prop['filter'] ?: '(objectclass=*)');
 
         if (!empty($dn_list)) {
             foreach ($dn_list as $idx => $entry) {
@@ -1447,7 +1446,7 @@
         if ($this->is_group_entry($rec)) {
             $out['_type'] = 'group';
             $out['readonly'] = true;
-            $fieldmap['name'] = $this->group_data['name_attr'] ? $this->group_data['name_attr'] : $this->prop['groups']['name_attr'];
+            $fieldmap['name'] = $this->group_data['name_attr'] ?: $this->prop['groups']['name_attr'];
         }
 
         // assign object type from object class mapping
@@ -1472,7 +1471,7 @@
                 if ($col == 'email' && $this->mail_domain && !strpos($value, '@'))
                     $out[$rf][] = sprintf('%s@%s', $value, $this->mail_domain);
                 else if (in_array($col, array('street','zipcode','locality','country','region')))
-                    $out['address'.($subtype?':':'').$subtype][$i][$col] = $value;
+                    $out['address' . ($subtype ? ':' : '') . $subtype][$i][$col] = $value;
                 else if ($col == 'address' && strpos($value, '$') !== false)  // address data is represented as string separated with $
                     list($out[$rf][$i]['street'], $out[$rf][$i]['locality'], $out[$rf][$i]['zipcode'], $out[$rf][$i]['country']) = explode('$', $value);
                 else if ($rec[$lf]['count'] > 1)
@@ -1701,7 +1700,7 @@
         $filter     = $this->prop['groups']['filter'];
         $scope      = $this->prop['groups']['scope'];
         $name_attr  = $this->prop['groups']['name_attr'];
-        $email_attr = $this->prop['groups']['email_attr'] ? $this->prop['groups']['email_attr'] : 'mail';
+        $email_attr = $this->prop['groups']['email_attr'] ?: 'mail';
         $sort_attrs = $this->prop['groups']['sort'] ? (array)$this->prop['groups']['sort'] : array($name_attr);
         $sort_attr  = $sort_attrs[0];
 
@@ -1849,11 +1848,11 @@
         $new_dn      = 'cn=' . rcube_ldap_generic::quote_string($group_name, true) . ',' . $this->groups_base_dn;
         $new_gid     = self::dn_encode($new_dn);
         $member_attr = $this->get_group_member_attr();
-        $name_attr   = $this->prop['groups']['name_attr'] ? $this->prop['groups']['name_attr'] : 'cn';
+        $name_attr   = $this->prop['groups']['name_attr'] ?: 'cn';
         $new_entry   = array(
             'objectClass' => $this->prop['groups']['object_classes'],
-            $name_attr => $group_name,
-            $member_attr => '',
+            $name_attr    => $group_name,
+            $member_attr  => '',
         );
 
         if (!$this->ldap->add_entry($new_dn, $new_entry)) {
@@ -2005,7 +2004,7 @@
 
         $base_dn     = $this->groups_base_dn;
         $contact_dn  = self::dn_decode($contact_id);
-        $name_attr   = $this->prop['groups']['name_attr'] ? $this->prop['groups']['name_attr'] : 'cn';
+        $name_attr   = $this->prop['groups']['name_attr'] ?: 'cn';
         $member_attr = $this->get_group_member_attr();
         $add_filter  = '';
 
diff --git a/program/lib/Roundcube/rcube_mime.php b/program/lib/Roundcube/rcube_mime.php
index 1954856..56406b1 100644
--- a/program/lib/Roundcube/rcube_mime.php
+++ b/program/lib/Roundcube/rcube_mime.php
@@ -155,7 +155,7 @@
      */
     public static function decode_mime_string($input, $fallback = null)
     {
-        $default_charset = !empty($fallback) ? $fallback : self::get_charset();
+        $default_charset = $fallback ?: self::get_charset();
 
         // rfc: all line breaks or other characters not found
         // in the Base64 Alphabet must be ignored by decoding software
diff --git a/program/lib/Roundcube/rcube_plugin_api.php b/program/lib/Roundcube/rcube_plugin_api.php
index 383f0de..704f416 100644
--- a/program/lib/Roundcube/rcube_plugin_api.php
+++ b/program/lib/Roundcube/rcube_plugin_api.php
@@ -325,8 +325,8 @@
             // load additional information from local composer.lock file
             if ($lock = $composer_lock['installed'][$json['name']]) {
                 $info['version'] = $lock['version'];
-                $info['uri']     = $lock['homepage'] ? $lock['homepage'] : $lock['source']['uri'];
-                $info['src_uri'] = $lock['dist']['uri'] ? $lock['dist']['uri'] : $lock['source']['uri'];
+                $info['uri']     = $lock['homepage'] ?: $lock['source']['uri'];
+                $info['src_uri'] = $lock['dist']['uri'] ?: $lock['source']['uri'];
             }
         }
 
diff --git a/program/lib/Roundcube/rcube_smtp.php b/program/lib/Roundcube/rcube_smtp.php
index 7400b99..b260fb7 100644
--- a/program/lib/Roundcube/rcube_smtp.php
+++ b/program/lib/Roundcube/rcube_smtp.php
@@ -59,10 +59,10 @@
 
         // let plugins alter smtp connection config
         $CONFIG = $rcube->plugins->exec_hook('smtp_connect', array(
-            'smtp_server'    => $host ? $host : $rcube->config->get('smtp_server'),
-            'smtp_port'      => $port ? $port : $rcube->config->get('smtp_port', 25),
-            'smtp_user'      => $user ? $user : $rcube->config->get('smtp_user'),
-            'smtp_pass'      => $pass ? $pass : $rcube->config->get('smtp_pass'),
+            'smtp_server'    => $host ?: $rcube->config->get('smtp_server'),
+            'smtp_port'      => $port ?: $rcube->config->get('smtp_port', 25),
+            'smtp_user'      => $user ?: $rcube->config->get('smtp_user'),
+            'smtp_pass'      => $pass ?: $rcube->config->get('smtp_pass'),
             'smtp_auth_cid'  => $rcube->config->get('smtp_auth_cid'),
             'smtp_auth_pw'   => $rcube->config->get('smtp_auth_pw'),
             'smtp_auth_type' => $rcube->config->get('smtp_auth_type'),
@@ -145,7 +145,7 @@
 
         $smtp_user = str_replace('%u', $rcube->get_user_name(), $CONFIG['smtp_user']);
         $smtp_pass = str_replace('%p', $rcube->get_user_password(), $CONFIG['smtp_pass']);
-        $smtp_auth_type = empty($CONFIG['smtp_auth_type']) ? NULL : $CONFIG['smtp_auth_type'];
+        $smtp_auth_type = $CONFIG['smtp_auth_type'] ?: null;
 
         if (!empty($CONFIG['smtp_auth_cid'])) {
             $smtp_authz = $smtp_user;
diff --git a/program/lib/Roundcube/rcube_spellcheck_atd.php b/program/lib/Roundcube/rcube_spellcheck_atd.php
index 4a03ed5..fc5319e 100644
--- a/program/lib/Roundcube/rcube_spellcheck_atd.php
+++ b/program/lib/Roundcube/rcube_spellcheck_atd.php
@@ -67,7 +67,7 @@
         if ($url) {
             $a_uri = parse_url($url);
             $ssl   = ($a_uri['scheme'] == 'https' || $a_uri['scheme'] == 'ssl');
-            $port  = $a_uri['port'] ? $a_uri['port'] : ($ssl ? 443 : 80);
+            $port  = $a_uri['port'] ?: ($ssl ? 443 : 80);
             $host  = ($ssl ? 'ssl://' : '') . $a_uri['host'];
             $path  = $a_uri['path'] . ($a_uri['query'] ? '?'.$a_uri['query'] : '') . $this->lang;
         }
diff --git a/program/lib/Roundcube/rcube_spellchecker.php b/program/lib/Roundcube/rcube_spellchecker.php
index 58b3727..a579cac 100644
--- a/program/lib/Roundcube/rcube_spellchecker.php
+++ b/program/lib/Roundcube/rcube_spellchecker.php
@@ -46,7 +46,7 @@
     {
         $this->rc     = rcube::get_instance();
         $this->engine = $this->rc->config->get('spellcheck_engine', 'googie');
-        $this->lang   = $lang ? $lang : 'en';
+        $this->lang   = $lang ?: 'en';
 
         $this->options = array(
             'ignore_syms' => $this->rc->config->get('spellcheck_ignore_syms'),
@@ -245,7 +245,7 @@
      */
     function error()
     {
-        return $this->error ? $this->error : ($this->backend ? $this->backend->error() : false);
+        return $this->error ?: ($this->backend ? $this->backend->error() : false);
     }
 
     private function html2text($text)
diff --git a/program/lib/Roundcube/rcube_storage.php b/program/lib/Roundcube/rcube_storage.php
index 48ab91f..387b3d0 100644
--- a/program/lib/Roundcube/rcube_storage.php
+++ b/program/lib/Roundcube/rcube_storage.php
@@ -454,7 +454,7 @@
     {
         $headers = $this->get_message_headers($uid);
         return rcube_charset::convert($this->get_message_part($uid, $part, null),
-            $headers->charset ? $headers->charset : $this->default_charset);
+            $headers->charset ?: $this->default_charset);
     }
 
     /**
diff --git a/program/lib/Roundcube/rcube_tnef_decoder.php b/program/lib/Roundcube/rcube_tnef_decoder.php
index b59ebdd..4930820 100644
--- a/program/lib/Roundcube/rcube_tnef_decoder.php
+++ b/program/lib/Roundcube/rcube_tnef_decoder.php
@@ -234,7 +234,7 @@
             case self::MAPI_UNICODE_STRING:
             case self::MAPI_BINARY:
             case self::MAPI_OBJECT:
-                $num_vals = ($have_mval) ? $num_mval : $this->_geti($data, 32);
+                $num_vals = $have_mval ? $num_mval : $this->_geti($data, 32);
                 for ($i = 0; $i < $num_vals; $i++) {
                     $length = $this->_geti($data, 32);
 
diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php
index 07dc870..60a1ccc 100644
--- a/program/lib/Roundcube/rcube_utils.php
+++ b/program/lib/Roundcube/rcube_utils.php
@@ -469,7 +469,7 @@
 
         list($primary, $secondary) = explode('/', $mimetype);
 
-        $classes = array($primary ? $primary : 'unknown');
+        $classes = array($primary ?: 'unknown');
 
         if ($secondary) {
             $classes[] = $secondary;
@@ -579,7 +579,7 @@
         // %d - domain name without first part
         $d = preg_replace('/^[^\.]+\./', '', $_SERVER['HTTP_HOST']);
         // %h - IMAP host
-        $h = $_SESSION['storage_host'] ? $_SESSION['storage_host'] : $host;
+        $h = $_SESSION['storage_host'] ?: $host;
         // %z - IMAP domain without first part, e.g. %h=imap.domain.tld, %z=domain.tld
         $z = preg_replace('/^[^\.]+\./', '', $h);
         // %s - domain name after the '@' from e-mail address provided at login screen.
diff --git a/program/lib/Roundcube/rcube_vcard.php b/program/lib/Roundcube/rcube_vcard.php
index 91815a6..cea61bd 100644
--- a/program/lib/Roundcube/rcube_vcard.php
+++ b/program/lib/Roundcube/rcube_vcard.php
@@ -196,7 +196,7 @@
                         }
 
                         while ($k < count($raw['type']) && ($subtype == 'internet' || $subtype == 'pref')) {
-                            $subtype = $typemap[$raw['type'][++$k]] ? $typemap[$raw['type'][$k]] : strtolower($raw['type'][$k]);
+                            $subtype = $typemap[$raw['type'][++$k]] ?: strtolower($raw['type'][$k]);
                         }
                     }
 
@@ -207,7 +207,7 @@
                                 && !in_array($k, array('pref','internet','voice','base64'))
                             ) {
                                 $k_uc    = strtoupper($k);
-                                $subtype = $typemap[$k_uc] ? $typemap[$k_uc] : $k;
+                                $subtype = $typemap[$k_uc] ?: $k;
                                 break;
                             }
                         }
@@ -385,7 +385,7 @@
                 $this->raw[$tag][$index] = (array)$value;
                 if ($type) {
                     $typemap = array_flip($this->typemap);
-                    $this->raw[$tag][$index]['type'] = explode(',', ($typemap[$type_uc] ? $typemap[$type_uc] : $type));
+                    $this->raw[$tag][$index]['type'] = explode(',', $typemap[$type_uc] ?: $type);
                 }
             }
             else {
@@ -658,7 +658,7 @@
                         // $entry['base64'] = true;
                     }
 
-                    $data = self::decode_value($data, $enc ? $enc : 'base64');
+                    $data = self::decode_value($data, $enc ?: 'base64');
                 }
                 else if ($field == 'PHOTO') {
                     // vCard 4.0 data URI, "PHOTO:data:image/jpeg;base64,..."

--
Gitblit v1.9.1