From 4fcdba9cf45ed93d53d8962c44b604422f4d3b05 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Fri, 28 Dec 2018 19:31:43 +0000 Subject: [PATCH] run php-cs-fixer (code reforamt) --- ADDITIONS/squirrelmail-plugin/common.php | 9 ++-- ADDITIONS/squirrelmail-plugin/setup.php | 2 +- common.php | 4 +- functions.inc.php | 59 +++++++++--------------- model/CliDelete.php | 1 - model/CliEdit.php | 18 +++----- model/CliView.php | 1 - model/Config.php | 14 +++--- model/MailboxHandler.php | 2 - model/PFAHandler.php | 6 +-- model/VacationHandler.php | 2 +- public/backup.php | 4 +- public/broadcast-message.php | 2 +- public/list-virtual.php | 4 +- public/list.php | 3 +- public/login.php | 3 +- public/setup.php | 2 +- public/upgrade.php | 8 ++-- public/viewlog.php | 4 +- scripts/snippets/dovecot_crypt.php | 4 +- tests/PacryptTest.php | 1 - tests/ValidatePasswordTest.php | 1 - 22 files changed, 63 insertions(+), 91 deletions(-) diff --git a/ADDITIONS/squirrelmail-plugin/common.php b/ADDITIONS/squirrelmail-plugin/common.php index 05ac1112..9774a3d6 100644 --- a/ADDITIONS/squirrelmail-plugin/common.php +++ b/ADDITIONS/squirrelmail-plugin/common.php @@ -16,19 +16,18 @@ if (!defined('SM_PATH')) { $config_file = dirname(__FILE__ ) . '/config.php'; $validate_file = dirname(__FILE__) . '/../include/validate.php'; -if(!file_exists($config_file)) { +if (!file_exists($config_file)) { die("$config_file is missing"); } include_once($config_file); include_once(dirname(__FILE__) . '/functions.inc.php'); -if(file_exists($validate_file)) { +if (file_exists($validate_file)) { include_once($validate_file); -} -else { +} else { $validate_file = SM_PATH . '/src/validate.php'; - if(file_exists($validate_file)) { + if (file_exists($validate_file)) { include_once($validate_file); } } diff --git a/ADDITIONS/squirrelmail-plugin/setup.php b/ADDITIONS/squirrelmail-plugin/setup.php index 764efa7f..95abdb62 100644 --- a/ADDITIONS/squirrelmail-plugin/setup.php +++ b/ADDITIONS/squirrelmail-plugin/setup.php @@ -1,6 +1,6 @@ 0) { $i = 0; while ($row = db_assoc($result['result'])) { - if(is_array($row)) { + if (is_array($row)) { $list[$i] = $row['domain']; $i++; } @@ -893,7 +887,6 @@ function generate_password($length = 12) { * @return array of error messages, or empty array if the password is ok */ function validate_password($password) { - $result = array(); $val_conf = Config::read_array('password_validation'); @@ -1490,8 +1483,7 @@ function db_connect_with_errors() { static $link; if (isset($link) && $link) { - return array($link, $error_text); - + return array($link, $error_text); } $link = 0; @@ -1535,7 +1527,7 @@ function db_connect_with_errors() { $error_text .= ("

DEBUG INFORMATION
Connect: given database path does not exist, is not writable, or \$CONF['database_name'] is empty."); } else { $link = new SQLite3($CONF['database_name']) or $error_text .= ("

DEBUG INFORMATION
Connect: failed to connect to database. $DEBUG_TEXT"); - if($link instanceof SQLite3) { + if ($link instanceof SQLite3) { $link->createFunction('base64_decode', 'base64_decode'); } } @@ -1775,7 +1767,7 @@ function db_row($result) { $row = pg_fetch_row($result); } - if(!is_array($row)) { + if (!is_array($row)) { return array(); } return $row; @@ -1803,7 +1795,7 @@ function db_array($result) { $row = pg_fetch_array($result); } - if(!is_array($row)) { + if (!is_array($row)) { return []; } @@ -1825,7 +1817,6 @@ function db_assoc($result) { } if ($CONF['database_type'] == "mysqli" && $result instanceof mysqli_result) { $row = mysqli_fetch_assoc($result); - } if (db_sqlite() && $result instanceof SQLite3Result) { $row = $result->fetchArray(SQLITE3_ASSOC); @@ -1834,7 +1825,7 @@ function db_assoc($result) { $row = pg_fetch_assoc($result); } - if(!is_array($row)) { + if (!is_array($row)) { $row = []; } return $row; @@ -1876,7 +1867,7 @@ function db_delete($table, $where, $delete, $additionalwhere='') { * @param array $timestamp (optional) - array of fields to set to now() - default: array('created', 'modified') * @return int - number of inserted rows */ -function db_insert ($table, array $values, $timestamp = array('created', 'modified') ) { +function db_insert($table, array $values, $timestamp = array('created', 'modified')) { $table = table_by_key($table); foreach (array_keys($values) as $key) { @@ -1899,9 +1890,8 @@ function db_insert ($table, array $values, $timestamp = array('created', 'modifi $password_expiration_value = (int) get_password_expiration_value($domain); $values['password_expiry'] = "now() + interval " . $password_expiration_value . " day"; } - } - else { - if($_table == 'mailbox') { + } else { + if ($_table == 'mailbox') { unset($values['password_expiry']); } } @@ -1958,7 +1948,6 @@ function db_update_q($table, $where, $values, $timestamp = array('modified')) { if (Config::bool('password_expiration')) { if ($table == 'mailbox') { - error_log("db_update_q : " . json_Encode($where)); $where_type = explode('=', $where); $email = ($where_type[1]); @@ -1972,7 +1961,7 @@ function db_update_q($table, $where, $values, $timestamp = array('modified')) { $sql="UPDATE $table_key SET " . implode(",", $sql_values) . " WHERE $where"; $result = db_query($sql); - if(array_key_exists('rows', $result)) { + if (array_key_exists('rows', $result)) { return $result['rows']; } return 0; @@ -2022,7 +2011,6 @@ function db_log($domain, $action, $data) { * @return string */ function db_in_clause($field, array $values) { - $v = array_map('escape_string', array_values($values)); return " $field IN ('" . implode("','", $v) . "') "; } @@ -2079,12 +2067,11 @@ function db_where_clause($condition, $struct, $additional_raw_where = '', $searc } elseif ($operator == "NOTNULL") { $querypart = $field . ' IS NOT NULL'; } else { - $querypart = $field . $operator . "'" . escape_string($value) . "'"; // might need other types adding here. if (db_pgsql() && in_array($struct[$field]['type'], array('ts', 'num')) && $value === '') { - $querypart = $field . $operator . " NULL"; + $querypart = $field . $operator . " NULL"; } } @@ -2154,7 +2141,7 @@ function check_db_version($error_out = true) { if ($r['rows'] == 1) { $row = db_assoc($r['result']); - if(isset($row['value'])) { + if (isset($row['value'])) { $dbversion = (int) $row['value']; } } else { @@ -2241,7 +2228,7 @@ function gen_show_status($show_alias) { // Vacation CHECK if ( $CONF['show_vacation'] == 'YES' ) { - $stat_result = db_query ("SELECT * FROM ". $CONF['database_tables']['vacation'] ." WHERE email = '" . $show_alias . "' AND active = 1"); + $stat_result = db_query("SELECT * FROM ". $CONF['database_tables']['vacation'] ." WHERE email = '" . $show_alias . "' AND active = 1"); if ($stat_result['rows'] == 1) { $stat_string .= "" . $CONF['show_status_text'] . " "; } else { @@ -2251,7 +2238,7 @@ function gen_show_status($show_alias) { // Disabled CHECK if ( $CONF['show_disabled'] == 'YES' ) { - $stat_result = db_query ("SELECT * FROM ". $CONF['database_tables']['mailbox'] ." WHERE username = '" . $show_alias . "' AND active = 0"); + $stat_result = db_query("SELECT * FROM ". $CONF['database_tables']['mailbox'] ." WHERE username = '" . $show_alias . "' AND active = 0"); if ($stat_result['rows'] == 1) { $stat_string .= "" . $CONF['show_status_text'] . " "; } else { @@ -2261,7 +2248,7 @@ function gen_show_status($show_alias) { // Expired CHECK if ( $CONF['show_expired'] == 'YES' ) { - $stat_result = db_query ("SELECT * FROM ". $CONF['database_tables']['mailbox'] ." WHERE username = '" . $show_alias . "' AND password_expiry <= now()"); + $stat_result = db_query("SELECT * FROM ". $CONF['database_tables']['mailbox'] ." WHERE username = '" . $show_alias . "' AND password_expiry <= now()"); if ($stat_result['rows'] == 1) { $stat_string .= "" . $CONF['show_status_text'] . " "; } else { diff --git a/model/CliDelete.php b/model/CliDelete.php index c6a0a6ea..5e532bef 100644 --- a/model/CliDelete.php +++ b/model/CliDelete.php @@ -5,7 +5,6 @@ */ class CliDelete extends Shell { - protected $handler_to_use = ''; /** diff --git a/model/CliEdit.php b/model/CliEdit.php index 83389dd0..d70fac42 100644 --- a/model/CliEdit.php +++ b/model/CliEdit.php @@ -6,8 +6,7 @@ * * extends the "Shell" class */ -class CliEdit extends Shell -{ +class CliEdit extends Shell { public $handler_to_use = ""; public $new = 0; @@ -15,8 +14,7 @@ class CliEdit extends Shell /** * Execution method always used for tasks */ - public function execute() - { + public function execute() { if (empty($this->args)) { $this->__interactive(); } else { @@ -29,8 +27,7 @@ class CliEdit extends Shell * read, check and handle all --* parameters * The list of allowed params is based on $handler->struct */ - private function __handle_params() - { + private function __handle_params() { $handler = new $this->handler_to_use($this->new); $form_fields = $handler->getStruct(); $id_field = $handler->getId_field(); @@ -74,8 +71,7 @@ class CliEdit extends Shell /** * Interactive mode */ - private function __interactive() - { + private function __interactive() { $handler = new $this->handler_to_use($this->new); $form_fields = $handler->getStruct(); @@ -179,8 +175,7 @@ class CliEdit extends Shell /** * (try to) store values */ - private function __handle($id, $values) - { + private function __handle($id, $values) { $handler = new $this->handler_to_use($this->new); if (!$handler->init($id)) { $this->err($handler->errormsg); @@ -205,8 +200,7 @@ class CliEdit extends Shell /** * Displays help contents */ - public function help() - { + public function help() { if ($this->new) { $cmd = 'add'; $cmdtext = 'Adds'; diff --git a/model/CliView.php b/model/CliView.php index 8f100112..86ca4e98 100644 --- a/model/CliView.php +++ b/model/CliView.php @@ -5,7 +5,6 @@ */ class CliView extends Shell { - protected $handler_to_use = 'invalid'; /** diff --git a/model/Config.php b/model/Config.php index d972ec91..140db0db 100644 --- a/model/Config.php +++ b/model/Config.php @@ -75,7 +75,7 @@ final class Config { public static function read_array($var) { $stuff = self::read($var); - if(!is_array($stuff)) { + if (!is_array($stuff)) { trigger_error('In '.__FUNCTION__.": expected config $var to be a boolean, but received a " . gettype($stuff), E_USER_ERROR); } @@ -89,11 +89,11 @@ final class Config { public static function read_string($var) { $stuff = self::read($var); - if($stuff === null) { + if ($stuff === null) { return ''; } - if(!is_string($stuff)) { + if (!is_string($stuff)) { trigger_error('In '.__FUNCTION__.": expected config $var to be a string, but received a " . gettype($stuff), E_USER_ERROR); return ''; } @@ -189,11 +189,11 @@ final class Config { public static function bool($var) { $value = self::read($var); - if(is_bool($value)) { + if (is_bool($value)) { return $value; } - if(!is_string($value)) { + if (!is_string($value)) { trigger_error('In '.__FUNCTION__.": expected config $var to be a string, but received a " . gettype($value), E_USER_ERROR); error_log("config $var should be a string, found: " . json_encode($value)); return false; @@ -233,11 +233,11 @@ final class Config { public static function lang($var) { $value = self::read("__LANG.{$var}"); - if(is_null($value)) { + if (is_null($value)) { return ''; } - if(!is_string($value)) { + if (!is_string($value)) { trigger_error('In '.__FUNCTION__.": expected config $var to be a string , but received a " . gettype($value), E_USER_ERROR); } return $value; diff --git a/model/MailboxHandler.php b/model/MailboxHandler.php index 6cccd6e5..4ad2fda8 100644 --- a/model/MailboxHandler.php +++ b/model/MailboxHandler.php @@ -217,7 +217,6 @@ class MailboxHandler extends PFAHandler { protected function beforestore() { - if (isset($this->values['quota']) && $this->values['quota'] != -1) { $this->values['quota'] = $this->values['quota'] * Config::read_string('quota_multiplier'); # convert quota from MB to bytes } @@ -452,7 +451,6 @@ class MailboxHandler extends PFAHandler { * @todo merge with allowed_quota? */ protected function check_quota($quota) { - if (!Config::bool('quota')) { return true; # enforcing quotas is disabled - just allow it } diff --git a/model/PFAHandler.php b/model/PFAHandler.php index b735d1e3..91103fdb 100644 --- a/model/PFAHandler.php +++ b/model/PFAHandler.php @@ -730,7 +730,7 @@ abstract class PFAHandler { $db_result = array(); if ($result['rows'] != 0) { while ($row = db_assoc($result['result'])) { - if(is_array($row)) { + if (is_array($row)) { $db_result[$row[$this->id_field]] = $row; } } @@ -827,7 +827,7 @@ abstract class PFAHandler { $result = db_query($query); if ($result['rows'] == 1) { $row = db_assoc($result['result']); - if(!is_array($row)) { + if (!is_array($row)) { return false; } $crypt_password = pacrypt($password, $row['password']); @@ -876,7 +876,7 @@ abstract class PFAHandler { if ($result['rows'] == 1) { $row = db_assoc($result['result']); - if(!is_array($row)) { + if (!is_array($row)) { return false; } $crypt_token = pacrypt($token, $row['token']); diff --git a/model/VacationHandler.php b/model/VacationHandler.php index 30e5ac3d..ca3912f5 100644 --- a/model/VacationHandler.php +++ b/model/VacationHandler.php @@ -197,7 +197,7 @@ class VacationHandler extends PFAHandler { $row = db_assoc($result['result']); - if(!is_array($row)) { + if (!is_array($row)) { return false; } $boolean = ($row['active'] == db_get_boolean(true)); diff --git a/public/backup.php b/public/backup.php index 2e0fe57e..3e4e47c2 100644 --- a/public/backup.php +++ b/public/backup.php @@ -108,7 +108,9 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") { while ($row = db_assoc($result['result'])) { $fields = array_keys($row); $values = array_values($row); - $values = array_map(function($str) { return escape_string($str); }, $values); + $values = array_map(function ($str) { + return escape_string($str); + }, $values); fwrite($fh, "INSERT INTO ". $tables[$i] . " (". implode(',', $fields) . ") VALUES ('" . implode('\',\'', $values) . "');\n"); $fields = ""; diff --git a/public/broadcast-message.php b/public/broadcast-message.php index 9c875cbc..deef5fb4 100644 --- a/public/broadcast-message.php +++ b/public/broadcast-message.php @@ -66,7 +66,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { $result = db_query($q); if ($result['rows'] > 0) { while ($row = db_assoc($result['result'])) { - if(is_array($row)) { + if (is_array($row)) { $recipients[] = $row['username']; } } diff --git a/public/list-virtual.php b/public/list-virtual.php index d1f168c9..70b1d53a 100644 --- a/public/list-virtual.php +++ b/public/list-virtual.php @@ -230,7 +230,7 @@ if ($result['rows'] > 0) { $goto_single_rec_del = ""; while ($row = db_assoc($result['result'])) { - if(!is_array($row)) { + if (!is_array($row)) { continue; } if ($display_mailbox_aliases) { @@ -405,7 +405,7 @@ class cNav_bar { $highlight_at = 0; - if ($this->limit >= $this->page_size) { + if ($this->limit >= $this->page_size) { $highlight_at = $this->limit / $this->page_size ; } diff --git a/public/list.php b/public/list.php index 9f4b01d8..10a0715b 100644 --- a/public/list.php +++ b/public/list.php @@ -87,7 +87,6 @@ if (count($handler->infomsg)) { if (safeget('output') == 'csv') { - $out = fopen('php://output', 'w'); header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment;filename='.$table.'.csv'); @@ -115,7 +114,7 @@ if (safeget('output') == 'csv') { $fields = array(); foreach ($columns as $column) { $values = $item[$column]; - if(is_array($values)) { + if (is_array($values)) { $values = implode(',', $values); } $fields[] = $values; diff --git a/public/login.php b/public/login.php index ba884bb2..7c98fa32 100644 --- a/public/login.php +++ b/public/login.php @@ -76,8 +76,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { error_log("PostfixAdmin admin login failed (username: $fUsername, ip_address: {$_SERVER['REMOTE_ADDR']})"); flash_error($PALANG['pLogin_failed']); } -} -else { +} else { session_unset(); session_destroy(); session_start(); diff --git a/public/setup.php b/public/setup.php index b912fc1f..c3cdd9bd 100644 --- a/public/setup.php +++ b/public/setup.php @@ -50,7 +50,7 @@ $file_config = file_exists(realpath("./../config.inc.php")); $file_local_config = file_exists(realpath("./../config.local.php")); // Fall back to looking in /etc/postfixadmin for config.local.php (Debian etc) -if(!$file_local_config && is_dir('/etc/postfixadmin')) { +if (!$file_local_config && is_dir('/etc/postfixadmin')) { $file_local_config = file_exists('/etc/postfixadmin/config.local.php'); } diff --git a/public/upgrade.php b/public/upgrade.php index acc542cd..df4f7a26 100644 --- a/public/upgrade.php +++ b/public/upgrade.php @@ -3,7 +3,7 @@ if (!defined('POSTFIXADMIN')) { require_once('common.php'); } -if(!isset($CONF) || !is_array($CONF)) { +if (!isset($CONF) || !is_array($CONF)) { die("config.inc.php seems invalid"); } /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ @@ -1416,7 +1416,7 @@ function upgrade_1284_mysql_pgsql() { if ($result['rows'] > 0) { while ($row = db_assoc($result['result'])) { - if(!is_array($row)) { + if (!is_array($row)) { break; } @@ -1737,7 +1737,7 @@ function upgrade_1837_sqlite() { /* https://github.com/postfixadmin/postfixadmin/issues/89 */ # upgrade_1838_mysql() renamed to upgrade_1839() to keep all databases in sync function upgrade_1839() { - if(!db_sqlite()) { + if (!db_sqlite()) { return _db_add_field('log', 'id', '{AUTOINCREMENT} {PRIMARY}', 'data'); } @@ -1776,4 +1776,4 @@ function upgrade_1841_sqlite() { function upgrade_1842() { _db_add_field('mailbox', 'password_expiry', "{DATETIME}"); // when a specific mailbox password expires _db_add_field('domain', 'password_expiry', 'int DEFAULT 0'); // expiry applied to mailboxes within that domain -} \ No newline at end of file +} diff --git a/public/viewlog.php b/public/viewlog.php index 05238e74..f8132d8e 100644 --- a/public/viewlog.php +++ b/public/viewlog.php @@ -76,8 +76,8 @@ if ($error != 1) { } } -foreach($tLog as $k => $v) { - if(isset($v['action'])) { +foreach ($tLog as $k => $v) { + if (isset($v['action'])) { $v['action'] = $PALANG['pViewlog_action_' . $v['action']]; $tLog[$k] = $v; } diff --git a/scripts/snippets/dovecot_crypt.php b/scripts/snippets/dovecot_crypt.php index 645a0952..99717a0b 100644 --- a/scripts/snippets/dovecot_crypt.php +++ b/scripts/snippets/dovecot_crypt.php @@ -10,8 +10,6 @@ define('NTLMSSP_HASH_SIZE', 16); class DovecotCrypt extends Crypt { - - private $errormsg = []; private $salt_chars = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; @@ -109,7 +107,7 @@ class DovecotCrypt extends Crypt { /** * @return string - */ + */ public function custom_hmac($algo, $data, $key, $raw_output = false) { $algo = strtolower($algo); $pack = 'H'.strlen($algo('test')); diff --git a/tests/PacryptTest.php b/tests/PacryptTest.php index 77a9cb64..b06adaee 100644 --- a/tests/PacryptTest.php +++ b/tests/PacryptTest.php @@ -52,7 +52,6 @@ class PaCryptTest extends \PHPUnit\Framework\TestCase { 'md5' => 'CY9rzUYh03PK3k6DJie09g==', // crypt requires salt ... 'SHA' => 'qUqP5cyxm6YcTAhz05Hph5gvu9M='] as $flavour => $hash) { - $CONF['authlib_default_flavour'] = $flavour; $stored = "{" . $flavour . "}$hash"; diff --git a/tests/ValidatePasswordTest.php b/tests/ValidatePasswordTest.php index 93f8b3eb..4ae21edb 100644 --- a/tests/ValidatePasswordTest.php +++ b/tests/ValidatePasswordTest.php @@ -3,7 +3,6 @@ require_once('common.php'); class ValidatePasswordTest extends \PHPUnit\Framework\TestCase { - public function testBasic() { $config = Config::getInstance();