diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2c602972..4aa913c8 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -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() )); diff --git a/ADDITIONS/squirrelmail-plugin/common.php b/ADDITIONS/squirrelmail-plugin/common.php index 9774a3d6..0834d98d 100644 --- a/ADDITIONS/squirrelmail-plugin/common.php +++ b/ADDITIONS/squirrelmail-plugin/common.php @@ -1,4 +1,5 @@ remove(); diff --git a/ADDITIONS/squirrelmail-plugin/setup.php b/ADDITIONS/squirrelmail-plugin/setup.php index ab36af79..2e7fcd0b 100644 --- a/ADDITIONS/squirrelmail-plugin/setup.php +++ b/ADDITIONS/squirrelmail-plugin/setup.php @@ -1,4 +1,5 @@ diff --git a/model/AdminHandler.php b/model/AdminHandler.php index 13ac403e..24e89bc1 100644 --- a/model/AdminHandler.php +++ b/model/AdminHandler.php @@ -1,4 +1,5 @@ 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'])) { diff --git a/model/AdminpasswordHandler.php b/model/AdminpasswordHandler.php index 7aa50381..b75a2c14 100644 --- a/model/AdminpasswordHandler.php +++ b/model/AdminpasswordHandler.php @@ -1,4 +1,5 @@ admin_username == '') { diff --git a/model/AliasHandler.php b/model/AliasHandler.php index 267c6986..fc251d92 100644 --- a/model/AliasHandler.php +++ b/model/AliasHandler.php @@ -1,4 +1,5 @@ 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 */ diff --git a/model/AliasdomainHandler.php b/model/AliasdomainHandler.php index e288d1be..12ccaccd 100644 --- a/model/AliasdomainHandler.php +++ b/model/AliasdomainHandler.php @@ -1,4 +1,5 @@ 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
in non-interactive mode. "); */ - + $head = "Usage: postfixadmin-cli $module [
] [--option value] [--option value]\n"; diff --git a/model/CliScheme.php b/model/CliScheme.php index ddd9135c..cf4b5736 100644 --- a/model/CliScheme.php +++ b/model/CliScheme.php @@ -1,4 +1,5 @@ out(" PRIMARY KEY (" . $handler->getId_field() . ")"); $this->out(' ) {MYISAM} '); $this->out('");'); - + $this->out(''); $this->hr(); $this->out('For adding fields with upgrade.php:'); diff --git a/model/CliView.php b/model/CliView.php index 8c0df2a2..c56abd71 100644 --- a/model/CliView.php +++ b/model/CliView.php @@ -1,4 +1,5 @@ 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; } diff --git a/model/DomainHandler.php b/model/DomainHandler.php index c509577b..d246e653 100644 --- a/model/DomainHandler.php +++ b/model/DomainHandler.php @@ -1,4 +1,5 @@ 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) { diff --git a/model/FetchmailHandler.php b/model/FetchmailHandler.php index 77e7f353..a1505c4d 100644 --- a/model/FetchmailHandler.php +++ b/model/FetchmailHandler.php @@ -1,4 +1,5 @@ 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()) { diff --git a/model/PFAHandler.php b/model/PFAHandler.php index 1322b8fd..3f70a7b7 100644 --- a/model/PFAHandler.php +++ b/model/PFAHandler.php @@ -1,7 +1,7 @@ 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(); diff --git a/model/VacationHandler.php b/model/VacationHandler.php index 9ac2c740..8592fa14 100644 --- a/model/VacationHandler.php +++ b/model/VacationHandler.php @@ -1,9 +1,9 @@ display('index.tpl'); } else { fwrite($fh, $header); - + $tables = array( 'admin', 'alias', diff --git a/public/common.php b/public/common.php index bfe1a15c..913e4d3e 100644 --- a/public/common.php +++ b/public/common.php @@ -1,2 +1,3 @@ checkPasswordRecoveryCode($tUsername, $tCode)) { flash_error(Config::lang('pPassword_code_text_error')); } else { diff --git a/public/vacation.php b/public/vacation.php index 59b662b0..3122edfd 100644 --- a/public/vacation.php +++ b/public/vacation.php @@ -207,7 +207,7 @@ if (!$details['active']) { if ($tActiveFrom < $now) { $tActiveFrom = $now; } - + if ($tActiveUntil < $now) { $tActiveUntil = $now; } diff --git a/public/viewlog.php b/public/viewlog.php index fa26ef41..96800e89 100644 --- a/public/viewlog.php +++ b/public/viewlog.php @@ -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 { diff --git a/public/xmlrpc.php b/public/xmlrpc.php index 03c8ba51..16fda385 100644 --- a/public/xmlrpc.php +++ b/public/xmlrpc.php @@ -69,7 +69,6 @@ echo $server->handle(); class UserProxy { - /** * @param string $old_password * @param string $new_password diff --git a/scripts/postfixadmin-cli.php b/scripts/postfixadmin-cli.php index 4c784763..798cb9f9 100644 --- a/scripts/postfixadmin-cli.php +++ b/scripts/postfixadmin-cli.php @@ -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(); diff --git a/scripts/snippets/crypt.php b/scripts/snippets/crypt.php index 068ee42e..dae80dbe 100644 --- a/scripts/snippets/crypt.php +++ b/scripts/snippets/crypt.php @@ -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 */ diff --git a/tests/AdminHandlerTest.php b/tests/AdminHandlerTest.php index 600e1b66..35103438 100644 --- a/tests/AdminHandlerTest.php +++ b/tests/AdminHandlerTest.php @@ -2,7 +2,7 @@ class AdminHandlerTest extends \PHPUnit\Framework\TestCase { - public function setUp() : void + public function setUp(): void { parent::setUp(); diff --git a/tests/CheckLanguageTest.php b/tests/CheckLanguageTest.php index ee0ec611..b571d416 100644 --- a/tests/CheckLanguageTest.php +++ b/tests/CheckLanguageTest.php @@ -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); } diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 96758ca2..087cd067 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -2,7 +2,7 @@ class ConfigTest extends \PHPUnit\Framework\TestCase { - public function setUp() : void + public function setUp(): void { $c = Config::getInstance(); diff --git a/tests/CreatePageBrowserTest.php b/tests/CreatePageBrowserTest.php index c6233f51..70cd4feb 100644 --- a/tests/CreatePageBrowserTest.php +++ b/tests/CreatePageBrowserTest.php @@ -2,7 +2,7 @@ class CreatePageBrowserTest extends \PHPUnit\Framework\TestCase { - public function tearDown() : void + public function tearDown(): void { $this->cleanup(); } diff --git a/tests/DbBasicTest.php b/tests/DbBasicTest.php index a2f10138..28593d99 100644 --- a/tests/DbBasicTest.php +++ b/tests/DbBasicTest.php @@ -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'; diff --git a/tests/MailboxHandlerTest.php b/tests/MailboxHandlerTest.php index 38b9028d..e152f730 100644 --- a/tests/MailboxHandlerTest.php +++ b/tests/MailboxHandlerTest.php @@ -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)); diff --git a/tests/RemoteTest.php b/tests/RemoteTest.php index 60b53086..0a5b4bbb 100644 --- a/tests/RemoteTest.php +++ b/tests/RemoteTest.php @@ -13,7 +13,7 @@ abstract class RemoteTest extends \PHPUnit\Framework\TestCase protected $xmlrpc_client; - public function setUp() : void + public function setUp(): void { parent::setUp(); diff --git a/tests/RemoteVacationTest.php b/tests/RemoteVacationTest.php index 510d407a..22f80065 100644 --- a/tests/RemoteVacationTest.php +++ b/tests/RemoteVacationTest.php @@ -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; diff --git a/tests/ValidatePasswordTest.php b/tests/ValidatePasswordTest.php index 61f151b7..8dcbef3d 100644 --- a/tests/ValidatePasswordTest.php +++ b/tests/ValidatePasswordTest.php @@ -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();