1
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2025-07-31 10:04:20 +03:00

PSR2 -> PSR12 formatting

This commit is contained in:
David Goodwin
2022-06-28 13:46:11 +01:00
parent bed0300fae
commit 2d6ded2786
42 changed files with 84 additions and 70 deletions

View File

@ -14,7 +14,7 @@ $config = new PhpCsFixer\Config();
return $config return $config
->setFinder($finder) ->setFinder($finder)
->setRules(array( ->setRules(array(
'@PSR2' => true, '@PSR12' => true,
'method_argument_space' => false, # don't break formatting in initStruct() 'method_argument_space' => false, # don't break formatting in initStruct()
'no_spaces_inside_parenthesis' => false, # don't break formatting in initStruct() 'no_spaces_inside_parenthesis' => false, # don't break formatting in initStruct()
)); ));

View File

@ -1,4 +1,5 @@
<?php <?php
// vim:ts=4:sw=4:et // vim:ts=4:sw=4:et
ini_set('include_path', get_include_path() . ':' . dirname(__FILE__)); ini_set('include_path', get_include_path() . ':' . dirname(__FILE__));

View File

@ -1,4 +1,5 @@
<?php <?php
require_once(dirname(__FILE__) . '/common.php'); require_once(dirname(__FILE__) . '/common.php');
$xmlrpc = get_xmlrpc(); $xmlrpc = get_xmlrpc();

View File

@ -1,4 +1,5 @@
<?php <?php
// vim:ts=4:sw=4:et // vim:ts=4:sw=4:et
if (!defined('SM_PATH')) { if (!defined('SM_PATH')) {
die("Invalid internal state (don't access file directly)"); die("Invalid internal state (don't access file directly)");

View File

@ -1983,7 +1983,7 @@ function db_delete($table, $where, $delete, $additionalwhere='')
* @param boolean $throw_exceptions * @param boolean $throw_exceptions
* @return int - number of inserted rows * @return int - number of inserted rows
*/ */
function db_insert(string $table, array $values, array $timestamp = array('created', 'modified'), bool $throw_exceptions = false) : int function db_insert(string $table, array $values, array $timestamp = array('created', 'modified'), bool $throw_exceptions = false): int
{ {
$table = table_by_key($table); $table = table_by_key($table);
@ -2027,7 +2027,7 @@ function db_insert(string $table, array $values, array $timestamp = array('creat
* @param array $timestamp (optional) - array of fields to set to now() - default: array('modified') * @param array $timestamp (optional) - array of fields to set to now() - default: array('modified')
* @return int - number of updated rows * @return int - number of updated rows
*/ */
function db_update(string $table, string $where_col, string $where_value, array $values, array $timestamp = array('modified'), bool $throw_exceptions = false):int function db_update(string $table, string $where_col, string $where_value, array $values, array $timestamp = array('modified'), bool $throw_exceptions = false): int
{ {
$table_key = table_by_key($table); $table_key = table_by_key($table);

View File

@ -1,4 +1,5 @@
<?php <?php
// //
// Postfix Admin // Postfix Admin
// by Mischa Peters <mischa at high5 dot net> // by Mischa Peters <mischa at high5 dot net>

View File

@ -1,4 +1,5 @@
<?php <?php
# $Id$ # $Id$
class AdminHandler extends PFAHandler class AdminHandler extends PFAHandler
@ -129,7 +130,7 @@ class AdminHandler extends PFAHandler
* called by $this->store() after storing $this->values in the database * called by $this->store() after storing $this->values in the database
* can be used to update additional tables, call scripts etc. * can be used to update additional tables, call scripts etc.
*/ */
protected function postSave() : bool protected function postSave(): bool
{ {
# store list of allowed domains in the domain_admins table # store list of allowed domains in the domain_admins table
if (isset($this->values['domains'])) { if (isset($this->values['domains'])) {

View File

@ -1,4 +1,5 @@
<?php <?php
# $Id$ # $Id$
class AdminpasswordHandler extends PFAHandler class AdminpasswordHandler extends PFAHandler
@ -39,7 +40,7 @@ class AdminpasswordHandler extends PFAHandler
); );
} }
public function init(string $id) :bool public function init(string $id): bool
{ {
# hardcode to logged in admin # hardcode to logged in admin
if ($this->admin_username == '') { if ($this->admin_username == '') {

View File

@ -1,4 +1,5 @@
<?php <?php
# $Id$ # $Id$
/** /**
@ -141,7 +142,7 @@ class AliasHandler extends PFAHandler
* AliasHandler needs some special handling in init() and therefore overloads the function. * AliasHandler needs some special handling in init() and therefore overloads the function.
* It also calls parent::init() * It also calls parent::init()
*/ */
public function init(string $id) : bool public function init(string $id): bool
{ {
$bits = explode('@', $id); $bits = explode('@', $id);
if (sizeof($bits) == 2) { if (sizeof($bits) == 2) {
@ -314,7 +315,7 @@ class AliasHandler extends PFAHandler
$this->values['goto'] = join(',', $values['goto']); $this->values['goto'] = join(',', $values['goto']);
} }
protected function postSave() : bool protected function postSave(): bool
{ {
# TODO: if alias belongs to a mailbox, update mailbox active status # TODO: if alias belongs to a mailbox, update mailbox active status
return true; return true;
@ -371,7 +372,7 @@ class AliasHandler extends PFAHandler
return array($condition, $searchmode); return array($condition, $searchmode);
} }
public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1) : bool public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1): bool
{ {
list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode); list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode);
$this->set_is_mailbox_extrafrom($condition, $searchmode); $this->set_is_mailbox_extrafrom($condition, $searchmode);

View File

@ -1,4 +1,5 @@
<?php <?php
# $Id$ # $Id$
/** /**
@ -53,7 +54,7 @@ class AliasdomainHandler extends PFAHandler
} }
} }
public function init(string $id) : bool public function init(string $id): bool
{ {
$success = parent::init($id); $success = parent::init($id);
if ($success) { if ($success) {

View File

@ -1,4 +1,5 @@
<?php <?php
# $Id$ # $Id$
/** /**
* class to handle 'delete' in Cli * class to handle 'delete' in Cli
@ -6,7 +7,6 @@
class CliDelete extends Shell class CliDelete extends Shell
{ {
/** /**
* Execution method always used for tasks * Execution method always used for tasks
*/ */

View File

@ -1,4 +1,5 @@
<?php <?php
# $Id$ # $Id$
/** /**

View File

@ -1,4 +1,5 @@
<?php <?php
# $Id$ # $Id$
class CliHelp extends Shell class CliHelp extends Shell
@ -17,7 +18,7 @@ class CliHelp extends Shell
public function help() public function help()
{ {
$handler = new $this->handler_to_use; $handler = new $this->handler_to_use();
# TODO: adjust help text according to $handler->taskNames # TODO: adjust help text according to $handler->taskNames
$module = preg_replace('/Handler$/', '', $this->handler_to_use); $module = preg_replace('/Handler$/', '', $this->handler_to_use);

View File

@ -1,4 +1,5 @@
<?php <?php
# $Id$ # $Id$
/** /**
* class to display the database scheme (for usage in upgrade.php) in Cli * class to display the database scheme (for usage in upgrade.php) in Cli

View File

@ -1,4 +1,5 @@
<?php <?php
# $Id$ # $Id$
/** /**
* class to handle 'view' in Cli * class to handle 'view' in Cli
@ -6,7 +7,6 @@
class CliView extends Shell class CliView extends Shell
{ {
/** /**
* Execution method always used for tasks * Execution method always used for tasks
*/ */

View File

@ -1,4 +1,5 @@
<?php <?php
# $Id$ # $Id$
# This class is too static - if you inherit a class from it, it will share the static $instance and all its contents # This class is too static - if you inherit a class from it, it will share the static $instance and all its contents
@ -48,7 +49,7 @@ final class Config
* @param string $var * @param string $var
* @return array * @return array
*/ */
public static function read_array(string $var) : array public static function read_array(string $var): array
{ {
$stuff = self::read($var); $stuff = self::read($var);
@ -59,7 +60,7 @@ final class Config
return $stuff; return $stuff;
} }
public static function has(string $var) : bool public static function has(string $var): bool
{ {
$x = self::getInstance()->getAll(); $x = self::getInstance()->getAll();
return array_key_exists($var, $x); return array_key_exists($var, $x);
@ -68,7 +69,7 @@ final class Config
* @param string $var * @param string $var
* @return string * @return string
*/ */
public static function read_string(string $var) : string public static function read_string(string $var): string
{ {
$stuff = self::read($var); $stuff = self::read($var);
@ -117,7 +118,7 @@ final class Config
* @param string $value Value to use as sprintf parameter * @param string $value Value to use as sprintf parameter
* @return string value of Config::$var, parsed by sprintf * @return string value of Config::$var, parsed by sprintf
*/ */
public static function read_f(string $var, string $value) : string public static function read_f(string $var, string $value): string
{ {
$text = self::read_string($var); $text = self::read_string($var);
@ -141,7 +142,7 @@ final class Config
* @param string $var Variable to obtain * @param string $var Variable to obtain
* @return bool value of Configure::$var (TRUE (on YES/yes) or FALSE (on NO/no/not set/unknown value) * @return bool value of Configure::$var (TRUE (on YES/yes) or FALSE (on NO/no/not set/unknown value)
*/ */
public static function bool(string $var) : bool public static function bool(string $var): bool
{ {
$value = self::read($var); $value = self::read($var);
@ -173,7 +174,7 @@ final class Config
* Used to read Config::$var, converted to bool, returned as integer (0 or 1) * Used to read Config::$var, converted to bool, returned as integer (0 or 1)
* @see bool() * @see bool()
*/ */
public static function intbool($var) : int public static function intbool($var): int
{ {
return Config::bool($var) ? 1 : 0; return Config::bool($var) ? 1 : 0;
} }
@ -187,7 +188,7 @@ final class Config
* @return string value of $PALANG[$var] * @return string value of $PALANG[$var]
* @access public * @access public
*/ */
public static function lang(string $var) : string public static function lang(string $var): string
{ {
$languages = self::read_array('__LANG'); $languages = self::read_array('__LANG');
@ -208,7 +209,7 @@ final class Config
* @param string $value Value to use as sprintf parameter * @param string $value Value to use as sprintf parameter
* @return string value of $PALANG[$var], parsed by sprintf * @return string value of $PALANG[$var], parsed by sprintf
*/ */
public static function lang_f(string $var, $value) : string public static function lang_f(string $var, $value): string
{ {
$all = self::read_array('__LANG'); $all = self::read_array('__LANG');
@ -227,7 +228,7 @@ final class Config
/** /**
* @return array * @return array
*/ */
public function getAll() : array public function getAll(): array
{ {
return $this->config; return $this->config;
} }

View File

@ -1,4 +1,5 @@
<?php <?php
# $Id$ # $Id$
/** /**
@ -153,7 +154,7 @@ class DomainHandler extends PFAHandler
} }
protected function preSave() : bool protected function preSave(): bool
{ {
# TODO: is this function superfluous? _can_edit should already cover this # TODO: is this function superfluous? _can_edit should already cover this
if ($this->is_superadmin) { if ($this->is_superadmin) {
@ -167,7 +168,7 @@ class DomainHandler extends PFAHandler
* called by $this->store() after storing $this->values in the database * called by $this->store() after storing $this->values in the database
* can be used to update additional tables, call scripts etc. * can be used to update additional tables, call scripts etc.
*/ */
protected function postSave() : bool protected function postSave(): bool
{ {
if ($this->new && $this->values['default_aliases']) { if ($this->new && $this->values['default_aliases']) {
foreach (Config::read_array('default_aliases') as $address=>$goto) { foreach (Config::read_array('default_aliases') as $address=>$goto) {

View File

@ -1,4 +1,5 @@
<?php <?php
# $Id$ # $Id$
/** /**

View File

@ -1,4 +1,5 @@
<?php <?php
# $Id$ # $Id$
/** /**
@ -66,7 +67,7 @@ class MailboxHandler extends PFAHandler
} }
} }
public function init(string $id) : bool public function init(string $id): bool
{ {
if (!parent::init($id)) { if (!parent::init($id)) {
return false; return false;
@ -232,7 +233,7 @@ class MailboxHandler extends PFAHandler
} }
protected function preSave() : bool protected function preSave(): bool
{ {
if (isset($this->values['quota']) && $this->values['quota'] != -1 && is_numeric($this->values['quota'])) { if (isset($this->values['quota']) && $this->values['quota'] != -1 && is_numeric($this->values['quota'])) {
$multiplier = Config::read_string('quota_multiplier'); $multiplier = Config::read_string('quota_multiplier');
@ -310,7 +311,7 @@ class MailboxHandler extends PFAHandler
return $ok && parent::set($values); return $ok && parent::set($values);
} }
protected function postSave() : bool protected function postSave(): bool
{ {
if ($this->new) { if ($this->new) {
if (!$this->mailbox_post_script()) { if (!$this->mailbox_post_script()) {

View File

@ -1,7 +1,7 @@
<?php <?php
abstract class PFAHandler abstract class PFAHandler
{ {
/** /**
* public variables * public variables
*/ */
@ -342,7 +342,7 @@ abstract class PFAHandler
* initialize with $id and check if it is valid * initialize with $id and check if it is valid
* @param string $id * @param string $id
*/ */
public function init(string $id) : bool public function init(string $id): bool
{ {
// postfix treats address lookups (aliases, mailboxes) as if they were lowercase. // postfix treats address lookups (aliases, mailboxes) as if they were lowercase.
@ -544,7 +544,7 @@ abstract class PFAHandler
* @return bool - true if all values were stored in the database, otherwise false * @return bool - true if all values were stored in the database, otherwise false
* error messages (if any) are stored in $this->errormsg * error messages (if any) are stored in $this->errormsg
*/ */
public function save() : bool public function save(): bool
{ {
# backwards compability: save() was once (up to 3.2.x) named store(). If a child class still uses the old name, let it override save(). # backwards compability: save() was once (up to 3.2.x) named store(). If a child class still uses the old name, let it override save().
if (method_exists($this, 'store')) { if (method_exists($this, 'store')) {
@ -619,7 +619,7 @@ abstract class PFAHandler
* called by $this->save() before storing the values in the database * called by $this->save() before storing the values in the database
* @return bool - if false, save() will abort * @return bool - if false, save() will abort
*/ */
protected function preSave() : bool protected function preSave(): bool
{ {
# backwards compability: preSave() was once (up to 3.2.x) named beforestore(). If a child class still uses the old name, let it override preSave(). # backwards compability: preSave() was once (up to 3.2.x) named beforestore(). If a child class still uses the old name, let it override preSave().
# Note: if a child class also has preSave(), it will override this function and obviously also the compability code. # Note: if a child class also has preSave(), it will override this function and obviously also the compability code.
@ -635,7 +635,7 @@ abstract class PFAHandler
* called by $this->save() after storing $this->values in the database * called by $this->save() after storing $this->values in the database
* can be used to update additional tables, call scripts etc. * can be used to update additional tables, call scripts etc.
*/ */
protected function postSave() : bool protected function postSave(): bool
{ {
# backwards compability: postSave() was once (up to 3.2.x) named storemore(). If a child class still uses the old name, let it override postSave(). # backwards compability: postSave() was once (up to 3.2.x) named storemore(). If a child class still uses the old name, let it override postSave().
# Note: if a child class also has postSave(), it will override this function and obviously also the compability code. # Note: if a child class also has postSave(), it will override this function and obviously also the compability code.
@ -770,7 +770,7 @@ abstract class PFAHandler
* @param int $offset - number of first row to return * @param int $offset - number of first row to return
* @return array - rows (as associative array, with the ID as key) * @return array - rows (as associative array, with the ID as key)
*/ */
protected function read_from_db($condition, $searchmode = array(), $limit=-1, $offset=-1) : array protected function read_from_db($condition, $searchmode = array(), $limit=-1, $offset=-1): array
{ {
$queryparts = $this->build_select_query($condition, $searchmode); $queryparts = $this->build_select_query($condition, $searchmode);
@ -838,7 +838,7 @@ abstract class PFAHandler
* @return bool - always true, no need to check ;-) (if $result is not an array, getList die()s) * @return bool - always true, no need to check ;-) (if $result is not an array, getList die()s)
* The data is stored in $this->result (as array of rows, each row is an associative array of column => value) * The data is stored in $this->result (as array of rows, each row is an associative array of column => value)
*/ */
public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1) : bool public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1): bool
{ {
if (is_array($condition)) { if (is_array($condition)) {
$real_condition = array(); $real_condition = array();

View File

@ -1,9 +1,9 @@
<?php <?php
# $Id$ # $Id$
class VacationHandler extends PFAHandler class VacationHandler extends PFAHandler
{ {
/** /**
* @var string * @var string
*/ */
@ -19,7 +19,7 @@ class VacationHandler extends PFAHandler
*/ */
protected $domain_field = 'domain'; protected $domain_field = 'domain';
public function init(string $id) : bool public function init(string $id): bool
{ {
throw new \Exception('VacationHandler is not yet ready to be used with *Handler methods'); throw new \Exception('VacationHandler is not yet ready to be used with *Handler methods');
} }

View File

@ -1,2 +1,3 @@
<?php <?php
require_once(dirname(__FILE__) . '/../common.php'); require_once(dirname(__FILE__) . '/../common.php');

View File

@ -1,4 +1,5 @@
<?php <?php
// //
// File: index.php // File: index.php
// //

View File

@ -1,4 +1,5 @@
<?php <?php
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
# Note: run with upgrade.php?debug=1 to see all SQL error messages # Note: run with upgrade.php?debug=1 to see all SQL error messages

View File

@ -69,7 +69,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$error = true; $error = true;
flash_error(Config::lang('pPassword_password_text_error')); flash_error(Config::lang('pPassword_password_text_error'));
} else { } else {
$handler = $context === 'admin' ? new AdminHandler : new MailboxHandler; $handler = $context === 'admin' ? new AdminHandler() : new MailboxHandler();
if (!$handler->checkPasswordRecoveryCode($tUsername, $tCode)) { if (!$handler->checkPasswordRecoveryCode($tUsername, $tCode)) {
flash_error(Config::lang('pPassword_code_text_error')); flash_error(Config::lang('pPassword_code_text_error'));
} else { } else {

View File

@ -69,7 +69,6 @@ echo $server->handle();
class UserProxy class UserProxy
{ {
/** /**
* @param string $old_password * @param string $old_password
* @param string $new_password * @param string $new_password

View File

@ -208,7 +208,7 @@ class PostfixAdmin
# TODO: add a way to Cli* to signal if the selected handler is supported (for example, not all *Handler support changing the password) # TODO: add a way to Cli* to signal if the selected handler is supported (for example, not all *Handler support changing the password)
if (strtolower(get_parent_class($shell)) == 'shell') { if (strtolower(get_parent_class($shell)) == 'shell') {
$handler = new $shell->handler_to_use; $handler = new $shell->handler_to_use();
if (in_array($task, $handler->taskNames)) { if (in_array($task, $handler->taskNames)) {
$this->shiftArgs(); $this->shiftArgs();
$shell->startup(); $shell->startup();

View File

@ -2,7 +2,6 @@
class Crypt class Crypt
{ {
/** /**
* @access private * @access private
*/ */

View File

@ -2,7 +2,7 @@
class AdminHandlerTest extends \PHPUnit\Framework\TestCase class AdminHandlerTest extends \PHPUnit\Framework\TestCase
{ {
public function setUp() : void public function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -2,7 +2,7 @@
class ConfigTest extends \PHPUnit\Framework\TestCase class ConfigTest extends \PHPUnit\Framework\TestCase
{ {
public function setUp() : void public function setUp(): void
{ {
$c = Config::getInstance(); $c = Config::getInstance();

View File

@ -2,7 +2,7 @@
class CreatePageBrowserTest extends \PHPUnit\Framework\TestCase class CreatePageBrowserTest extends \PHPUnit\Framework\TestCase
{ {
public function tearDown() : void public function tearDown(): void
{ {
$this->cleanup(); $this->cleanup();
} }

View File

@ -4,7 +4,7 @@ class DbBasicTest extends \PHPUnit\Framework\TestCase
{ {
private $test_domain; private $test_domain;
public function setUp() : void public function setUp(): void
{ {
$db = db_connect(); $db = db_connect();
$test_domain = 'test' . uniqid() . '.com'; $test_domain = 'test' . uniqid() . '.com';

View File

@ -2,7 +2,7 @@
class MailboxHandlerTest extends \PHPUnit\Framework\TestCase class MailboxHandlerTest extends \PHPUnit\Framework\TestCase
{ {
public function tearDown() : void public function tearDown(): void
{ {
db_query('DELETE FROM mailbox'); db_query('DELETE FROM mailbox');
db_query('DELETE FROM alias'); db_query('DELETE FROM alias');
@ -12,7 +12,7 @@ class MailboxHandlerTest extends \PHPUnit\Framework\TestCase
parent::tearDown(); parent::tearDown();
} }
public function setUp() : void public function setUp(): void
{ {
global $CONF; global $CONF;
parent::setUp(); parent::setUp();

View File

@ -13,7 +13,7 @@ abstract class RemoteTest extends \PHPUnit\Framework\TestCase
protected $xmlrpc_client; protected $xmlrpc_client;
public function setUp() : void public function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@ -9,12 +9,10 @@ require_once('RemoteTest.php');
class RemoteVacationTest extends RemoteTest class RemoteVacationTest extends RemoteTest
{ {
/** /**
* Adds the test recipient data to the database. * Adds the test recipient data to the database.
*/ */
public function setUp() : void public function setUp(): void
{ {
// Ensure config.inc.php is vaguely correct. // Ensure config.inc.php is vaguely correct.
global $CONF; global $CONF;