0
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2024-09-19 19:22:14 +02:00

bumping php-cs-fixer; formatting rules change slightly

This commit is contained in:
David Goodwin 2022-06-28 13:31:37 +01:00
parent 3472897527
commit b18ed591a2
38 changed files with 76 additions and 61 deletions

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

@ -1955,7 +1955,7 @@ function db_insert($table, array $values, $timestamp = array('created', 'modifie
* @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);
$pvalues = array();

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 {
@ -123,7 +124,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'])) {
if (is_array($this->values['domains'])) {

View File

@ -1,4 +1,5 @@
<?php
# $Id$
class AdminpasswordHandler extends PFAHandler {
@ -35,7 +36,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 == '') {
die("No admin logged in");

View File

@ -1,4 +1,5 @@
<?php
# $Id$
/**
@ -136,7 +137,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) {
$local_part = $bits[0];
@ -151,7 +152,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)
@ -191,7 +192,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');
@ -303,7 +304,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;
}
@ -357,7 +358,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);
$result = parent::getList($condition, $searchmode, $limit, $offset);
@ -452,7 +453,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$
/**
@ -51,7 +52,7 @@ class AliasdomainHandler extends PFAHandler {
}
}
public function init(string $id) : bool {
public function init(string $id): bool {
$success = parent::init($id);
if ($success) {
if (count($this->struct['alias_domain']['options']) == 0 && $this->new) {

View File

@ -1,11 +1,11 @@
<?php
# $Id$
/**
* class to handle 'delete' in Cli
*/
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 {
@ -14,7 +15,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);
@ -35,7 +36,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
@ -57,7 +58,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,11 +1,11 @@
<?php
# $Id$
/**
* class to handle 'view' in Cli
*/
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
@ -45,7 +46,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);
if (!is_array($stuff)) {
@ -55,7 +56,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);
}
@ -63,7 +64,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);
if ($stuff === null) {
@ -110,7 +111,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);
$newtext = sprintf($text, $value);
@ -133,7 +134,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);
if (is_bool($value)) {
@ -164,7 +165,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;
}
@ -177,7 +178,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');
$value = $languages[$var] ?? '';
@ -197,7 +198,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');
$text = $all[$var] ?? '';
@ -215,7 +216,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$
/**
@ -148,7 +149,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) {
return true;
@ -161,7 +162,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) {
$address = $address . "@" . $this->id;

View File

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

View File

@ -1,4 +1,5 @@
<?php
# $Id$
/**
@ -60,7 +61,7 @@ class MailboxHandler extends PFAHandler {
}
}
public function init(string $id) : bool {
public function init(string $id): bool {
if (!parent::init($id)) {
return false;
}
@ -217,7 +218,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');
if ($multiplier == 0 || !is_numeric($multiplier)) { // or empty string, or null, or false...
@ -292,7 +293,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()) {
# return false; # TODO: should this be fatal?

View File

@ -1,6 +1,6 @@
<?php
abstract class PFAHandler {
abstract class PFAHandler {
/**
* public variables
*/
@ -337,7 +337,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.
// MySQL is normally case insenstive, PostgreSQL is case sensitive.
@ -534,7 +534,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')) {
error_log('store() is deprecated, please rename it to save()');
@ -608,7 +608,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.
if (method_exists($this, 'beforestore')) {
@ -623,7 +623,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.
if (method_exists($this, 'storemore')) {
@ -755,7 +755,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);
$query = $queryparts['select_cols'] . $queryparts['from_where_order'];
@ -820,7 +820,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();
foreach ($condition as $key => $value) {

View File

@ -1,8 +1,8 @@
<?php
# $Id$
class VacationHandler extends PFAHandler {
/**
* @var string
*/
@ -18,7 +18,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 /**
<?php
/**
* Postfix Admin
*
* LICENSE

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

@ -66,7 +66,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

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

View File

@ -203,7 +203,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

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

View File

@ -16,7 +16,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

@ -1,7 +1,7 @@
<?php
class ConfigTest extends \PHPUnit\Framework\TestCase {
public function setUp() : void {
public function setUp(): void {
$c = Config::getInstance();
$all = $c->getAll();

View File

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

View File

@ -3,7 +3,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';
$this->test_domain = $test_domain;

View File

@ -1,7 +1,7 @@
<?php
class MailboxHandlerTest extends \PHPUnit\Framework\TestCase {
public function tearDown() : void {
public function tearDown(): void {
db_query('DELETE FROM mailbox');
db_query('DELETE FROM alias');
db_query('DELETE FROM domain_admins');
@ -10,7 +10,7 @@ class MailboxHandlerTest extends \PHPUnit\Framework\TestCase {
parent::tearDown();
}
public function setUp() : void {
public function setUp(): void {
global $CONF;
parent::setUp();
@ -160,7 +160,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

@ -12,7 +12,7 @@ abstract class RemoteTest extends \PHPUnit\Framework\TestCase {
protected $xmlrpc_client;
public function setUp() : void {
public function setUp(): void {
parent::setUp();
if ($this->server_url == 'http://change.me/to/work') {

View File

@ -8,12 +8,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;
if ($CONF['vacation'] != 'YES' || $CONF['vacation_control'] != "YES") {