0
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2024-09-19 03:02:14 +02: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
->setFinder($finder)
->setRules(array(
'@PSR2' => true,
'@PSR12' => true,
'method_argument_space' => 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
// vim:ts=4:sw=4:et
ini_set('include_path', get_include_path() . ':' . dirname(__FILE__));

View File

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

View File

@ -99,7 +99,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
$$key = $_POST[$key];
}
}
if (!empty($fBack)) {
$success = $vacation->remove();

View File

@ -1,4 +1,5 @@
<?php
// vim:ts=4:sw=4:et
if (!defined('SM_PATH')) {
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
* @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);
@ -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')
* @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);

View File

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

View File

@ -1,4 +1,5 @@
<?php
# $Id$
class AdminHandler extends PFAHandler
@ -129,7 +130,7 @@ class AdminHandler extends PFAHandler
* called by $this->store() after storing $this->values in the database
* 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
if (isset($this->values['domains'])) {

View File

@ -1,4 +1,5 @@
<?php
# $Id$
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
if ($this->admin_username == '') {

View File

@ -1,4 +1,5 @@
<?php
# $Id$
/**
@ -141,7 +142,7 @@ class AliasHandler extends PFAHandler
* AliasHandler needs some special handling in init() and therefore overloads the function.
* It also calls parent::init()
*/
public function init(string $id) : bool
public function init(string $id): bool
{
$bits = explode('@', $id);
if (sizeof($bits) == 2) {
@ -157,7 +158,7 @@ class AliasHandler extends PFAHandler
if (!$retval) {
return false;
} # parent::init() failed, no need to continue
# hide 'goto_mailbox' for non-mailbox aliases
# parent::init called view() before, so we can rely on having $this->result filled
# (only validate_new_id() is called from parent::init and could in theory change $this->result)
@ -199,7 +200,7 @@ class AliasHandler extends PFAHandler
$this->errormsg[$this->id_field] = Config::lang('pCreate_alias_address_text_error3');
return false;
}
# TODO: already checked in set() - does it make sense to check it here also? Only advantage: it's an early check
# if (!in_array($domain, $this->allowed_domains)) {
# $this->errormsg[] = Config::lang('pCreate_alias_address_text_error1');
@ -314,7 +315,7 @@ class AliasHandler extends PFAHandler
$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
return true;
@ -371,7 +372,7 @@ class AliasHandler extends PFAHandler
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);
$this->set_is_mailbox_extrafrom($condition, $searchmode);
@ -472,7 +473,7 @@ class AliasHandler extends PFAHandler
$vacation_goto = str_replace('@', '#', $this->id);
return $vacation_goto . '@' . Config::read_string('vacation_domain');
}
/**
* @return boolean
*/

View File

@ -1,4 +1,5 @@
<?php
# $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);
if ($success) {

View File

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

View File

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

View File

@ -1,4 +1,5 @@
<?php
# $Id$
class CliHelp extends Shell
@ -17,7 +18,7 @@ class CliHelp extends Shell
public function help()
{
$handler = new $this->handler_to_use;
$handler = new $this->handler_to_use();
# TODO: adjust help text according to $handler->taskNames
$module = preg_replace('/Handler$/', '', $this->handler_to_use);
@ -38,7 +39,7 @@ class CliHelp extends Shell
View $module <address> in non-interactive mode.
"); */
$head = "Usage: postfixadmin-cli $module <task> [<address>] [--option value] [--option value]\n";

View File

@ -1,4 +1,5 @@
<?php
# $Id$
/**
* class to display the database scheme (for usage in upgrade.php) in Cli
@ -59,7 +60,7 @@ class CliScheme extends Shell
$this->out(" PRIMARY KEY (" . $handler->getId_field() . ")");
$this->out(' ) {MYISAM} ');
$this->out('");');
$this->out('');
$this->hr();
$this->out('For adding fields with upgrade.php:');

View File

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

View File

@ -1,4 +1,5 @@
<?php
# $Id$
# 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
* @return array
*/
public static function read_array(string $var) : array
public static function read_array(string $var): array
{
$stuff = self::read($var);
@ -59,7 +60,7 @@ final class Config
return $stuff;
}
public static function has(string $var) : bool
public static function has(string $var): bool
{
$x = self::getInstance()->getAll();
return array_key_exists($var, $x);
@ -68,7 +69,7 @@ final class Config
* @param string $var
* @return string
*/
public static function read_string(string $var) : string
public static function read_string(string $var): string
{
$stuff = self::read($var);
@ -117,7 +118,7 @@ final class Config
* @param string $value Value to use as sprintf parameter
* @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);
@ -141,7 +142,7 @@ final class Config
* @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)
*/
public static function bool(string $var) : bool
public static function bool(string $var): bool
{
$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)
* @see bool()
*/
public static function intbool($var) : int
public static function intbool($var): int
{
return Config::bool($var) ? 1 : 0;
}
@ -187,7 +188,7 @@ final class Config
* @return string value of $PALANG[$var]
* @access public
*/
public static function lang(string $var) : string
public static function lang(string $var): string
{
$languages = self::read_array('__LANG');
@ -208,7 +209,7 @@ final class Config
* @param string $value Value to use as sprintf parameter
* @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');
@ -227,7 +228,7 @@ final class Config
/**
* @return array
*/
public function getAll() : array
public function getAll(): array
{
return $this->config;
}

View File

@ -1,4 +1,5 @@
<?php
# $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
if ($this->is_superadmin) {
@ -167,7 +168,7 @@ class DomainHandler extends PFAHandler
* called by $this->store() after storing $this->values in the database
* 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']) {
foreach (Config::read_array('default_aliases') as $address=>$goto) {

View File

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

View File

@ -195,7 +195,7 @@ class Login
error_log("Running $command yielded return value=$retval, output was: " . json_encode($output));
throw new \Exception($warnmsg_pw);
}
return true;
}
}

View File

@ -1,4 +1,5 @@
<?php
# $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)) {
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'])) {
$multiplier = Config::read_string('quota_multiplier');
@ -310,7 +311,7 @@ class MailboxHandler extends PFAHandler
return $ok && parent::set($values);
}
protected function postSave() : bool
protected function postSave(): bool
{
if ($this->new) {
if (!$this->mailbox_post_script()) {

View File

@ -1,7 +1,7 @@
<?php
abstract class PFAHandler
{
/**
* public variables
*/
@ -342,7 +342,7 @@ abstract class PFAHandler
* initialize with $id and check if it is valid
* @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.
@ -544,7 +544,7 @@ abstract class PFAHandler
* @return bool - true if all values were stored in the database, otherwise false
* 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().
if (method_exists($this, 'store')) {
@ -619,7 +619,7 @@ abstract class PFAHandler
* called by $this->save() before storing the values in the database
* @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().
# 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
* 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().
# 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
* @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);
@ -838,7 +838,7 @@ abstract class PFAHandler
* @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)
*/
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)) {
$real_condition = array();

View File

@ -1,9 +1,9 @@
<?php
# $Id$
class VacationHandler extends PFAHandler
{
/**
* @var string
*/
@ -19,7 +19,7 @@ class VacationHandler extends PFAHandler
*/
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');
}

View File

@ -84,7 +84,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") {
$smarty->display('index.tpl');
} else {
fwrite($fh, $header);
$tables = array(
'admin',
'alias',

View File

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

View File

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

View File

@ -1,4 +1,5 @@
<?php
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
# 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;
flash_error(Config::lang('pPassword_password_text_error'));
} else {
$handler = $context === 'admin' ? new AdminHandler : new MailboxHandler;
$handler = $context === 'admin' ? new AdminHandler() : new MailboxHandler();
if (!$handler->checkPasswordRecoveryCode($tUsername, $tCode)) {
flash_error(Config::lang('pPassword_code_text_error'));
} else {

View File

@ -207,7 +207,7 @@ if (!$details['active']) {
if ($tActiveFrom < $now) {
$tActiveFrom = $now;
}
if ($tActiveUntil < $now) {
$tActiveUntil = $now;
}

View File

@ -58,7 +58,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") {
}
}
}
if ($flag_fDomain == 0 ) {
die('Unknown domain');
}
@ -106,24 +106,24 @@ if ($error != 1) {
$where_sql = 'WHERE ' . implode(' AND ', $where);
}
$number_of_logs=0;
$number_of_pages=0;
//get number of total logs
$query = "SELECT count(*) as number_of_logs FROM $table_log $where_sql";
$result = db_query_all($query, $params);
foreach ($result as $r ) {
$number_of_logs=$r['number_of_logs'];
}
$number_of_pages = ceil($number_of_logs/$page_size);
if ($page_number > $number_of_pages) {
die('Unknown page number');
}
if ($page_number == 1 ) {
$offset=0;
} else {

View File

@ -69,7 +69,6 @@ echo $server->handle();
class UserProxy
{
/**
* @param string $old_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)
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)) {
$this->shiftArgs();
$shell->startup();

View File

@ -2,25 +2,24 @@
class Crypt
{
/**
* @access private
*/
protected $plain = '';
/**
* @access private
*/
protected $password;
protected $size;
public function __construct($plaintext)
{
$this->plain = $plaintext;
}
/**
* @return bool
*/

View File

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

View File

@ -18,7 +18,7 @@ class CheckLanguageTest extends \PHPUnit\Framework\TestCase
$this->assertEquals('test', $lang);
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en';
$lang = check_language(false);
$this->assertEquals('en', $lang);
}

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
class MailboxHandlerTest extends \PHPUnit\Framework\TestCase
{
public function tearDown() : void
public function tearDown(): void
{
db_query('DELETE FROM mailbox');
db_query('DELETE FROM alias');
@ -12,7 +12,7 @@ class MailboxHandlerTest extends \PHPUnit\Framework\TestCase
parent::tearDown();
}
public function setUp() : void
public function setUp(): void
{
global $CONF;
parent::setUp();
@ -165,7 +165,7 @@ class MailboxHandlerTest extends \PHPUnit\Framework\TestCase
$this->assertEmpty($h->infomsg);
$this->assertTrue($r);
$this->assertTrue($h->save());
$h->getList('');
$list = $h->result();
$this->assertEquals(1, count($list));

View File

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

View File

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

View File

@ -20,7 +20,7 @@ class ValidatePasswordTest extends \PHPUnit\Framework\TestCase
$this->assertNotEmpty(validate_password('pas')); // notEmpty == fail
$this->assertNotEmpty(validate_password('pa1'));
}
public function testSpecial()
{
$config = Config::getInstance();