diff --git a/.php_cs.dist b/.php_cs.dist index eb466e60..018cbf5c 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -1,7 +1,7 @@ exclude('smarty') + ->exclude('lib') ->exclude('vendor') ->exclude('templates') ->exclude('templates_c') diff --git a/functions.inc.php b/functions.inc.php index a6ef0a6c..63403e38 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -847,11 +847,9 @@ function generate_password() { // add random characters to $password until $length is reached $password = ""; while (strlen($password) < $length) { - - if(function_exists('random_int')) { + if (function_exists('random_int')) { $random = random_int(0, strlen($possible) -1); - } - else { + } else { $random = mt_rand(0, strlen($possible) - 1); } $char = substr($possible, $random, 1); @@ -1064,7 +1062,7 @@ function _pacrypt_php_crypt($pw, $pw_db) { } else { $salt_method = 'MD5'; // default. // no pw provided. create new password hash - if(strpos($CONF['encrypt'], ':') !== false) { + if (strpos($CONF['encrypt'], ':') !== false) { // use specified hash method $split_method = explode(':', $CONF['encrypt']); $salt_method = $split_method[1]; @@ -1127,17 +1125,15 @@ function _php_crypt_generate_crypt_salt($hash_type='MD5') { // used for php_crypt method function _php_crypt_random_string($characters, $length) { - $random_int_exists = true; - if(!function_exists('random_int')) { + if (!function_exists('random_int')) { $random_int_exists = false; } $string = ''; for ($p = 0; $p < $length; $p++) { - if($random_int_exists) { + if ($random_int_exists) { $string .= $characters[random_int(0, strlen($characters) -1)]; - } - else { + } else { // should really use a stronger randomness source $string .= $characters[mt_rand(0, strlen($characters) - 1)]; } diff --git a/model/Config.php b/model/Config.php index caec0e77..3c0597c1 100644 --- a/model/Config.php +++ b/model/Config.php @@ -4,7 +4,6 @@ # This class is too static - if you inherit a class from it, it will share the static $instance and all its contents # Therefore the class is marked as final to prevent someone accidently does this ;-) final class Config { - private static $instance = null; /** @@ -67,7 +66,6 @@ final class Config { } } $_this->setAll($newConfig); - } /** @@ -97,7 +95,7 @@ final class Config { $zero = $name[0]; $one = $name[1]; $two = $name[2]; - if(isset($config[$zero], $config[$zero][$one], $config[$zero][$one][$two])) { + if (isset($config[$zero], $config[$zero][$one], $config[$zero][$one][$two])) { return $config[$zero][$one][$two]; } break; diff --git a/scripts/postfixadmin-cli.php b/scripts/postfixadmin-cli.php index e73c9490..1680ce5a 100644 --- a/scripts/postfixadmin-cli.php +++ b/scripts/postfixadmin-cli.php @@ -149,7 +149,6 @@ class PostfixAdmin { * Dispatches a CLI request */ public function dispatch() { - check_db_version(); # ensure the database layout is up to date if (!isset($this->args[0])) { diff --git a/tests/GeneratePasswordTest.php b/tests/GeneratePasswordTest.php index adbf5062..d16e2725 100644 --- a/tests/GeneratePasswordTest.php +++ b/tests/GeneratePasswordTest.php @@ -2,12 +2,8 @@ require_once('common.php'); -class GeneratePasswordTest extends PHPUnit_Framework_TestCase -{ - public function testBasic() - { - - +class GeneratePasswordTest extends PHPUnit_Framework_TestCase { + public function testBasic() { $one = generate_password(); $two = generate_password(); @@ -15,7 +11,5 @@ class GeneratePasswordTest extends PHPUnit_Framework_TestCase $this->assertNotEquals($one, $two); $this->assertNotEmpty($one); $this->assertNotEmpty($two); - - } } diff --git a/tests/PacryptTest.php b/tests/PacryptTest.php index c8d02263..c4008d9d 100644 --- a/tests/PacryptTest.php +++ b/tests/PacryptTest.php @@ -2,10 +2,8 @@ require_once('common.php'); -class PaCryptTest extends PHPUnit_Framework_TestCase -{ - public function testMd5Crypt() - { +class PaCryptTest extends PHPUnit_Framework_TestCase { + public function testMd5Crypt() { $hash = _pacrypt_md5crypt('test', ''); $this->assertNotEmpty($hash); @@ -14,8 +12,7 @@ class PaCryptTest extends PHPUnit_Framework_TestCase $this->assertEquals($hash, _pacrypt_md5crypt('test', $hash)); } - public function testCrypt() - { + public function testCrypt() { // E_NOTICE if we pass in '' for the salt $hash = _pacrypt_crypt('test', 'sa'); @@ -24,11 +21,9 @@ class PaCryptTest extends PHPUnit_Framework_TestCase $this->assertNotEquals('test', $hash); $this->assertEquals($hash, _pacrypt_crypt('test', $hash)); - } - public function testMySQLEncrypt() - { + public function testMySQLEncrypt() { if (!db_mysql()) { $this->markTestSkipped('Not using MySQL'); } @@ -48,8 +43,7 @@ class PaCryptTest extends PHPUnit_Framework_TestCase $this->assertEquals($hash2, _pacrypt_mysql_encrypt('test', 'salt')); } - public function testAuthlib() - { + public function testAuthlib() { // too many options! foreach ( @@ -67,8 +61,7 @@ class PaCryptTest extends PHPUnit_Framework_TestCase } } - public function testPacryptDovecot() - { + public function testPacryptDovecot() { global $CONF; if (!file_exists('/usr/bin/doveadm')) { $this->markTestSkipped("No /usr/bin/doveadm"); @@ -84,8 +77,7 @@ class PaCryptTest extends PHPUnit_Framework_TestCase $this->assertEquals($expected_hash, _pacrypt_dovecot('test', $expected_hash)); } - public function testPhpCrypt() - { + public function testPhpCrypt() { global $CONF; $config = Config::getInstance(); @@ -104,18 +96,15 @@ class PaCryptTest extends PHPUnit_Framework_TestCase $this->assertNotEquals($fail, $expected); - } - public function testPhpCryptRandomString(){ + public function testPhpCryptRandomString() { $str1 = _php_crypt_random_string('abcdefg123456789', 2); $str2 = _php_crypt_random_string('abcdefg123456789', 2); $this->assertNotEmpty($str1); $this->assertNotEmpty($str2); $this->assertNotEquals($str1, $str2); - - } } diff --git a/tests/RemoteTest.php b/tests/RemoteTest.php index e9831530..6d9a9671 100644 --- a/tests/RemoteTest.php +++ b/tests/RemoteTest.php @@ -15,11 +15,11 @@ abstract class RemoteTest extends PHPUnit_Framework_TestCase { public function setUp() { parent::setUp(); - if($this->server_url == 'http://change.me/to/work') { + if ($this->server_url == 'http://change.me/to/work') { $this->markTestSkipped("Test skipped; Configuration change to \$this->server_url required"); } - if(!class_exists('Zend_XmlRpc_Client', true)) { + if (!class_exists('Zend_XmlRpc_Client', true)) { $this->markTestSkipped("Test skipped; Zend_XmlRpc_Client not found"); } diff --git a/tests/ValidatePasswordTest.php b/tests/ValidatePasswordTest.php index 94d06f49..a4360d77 100644 --- a/tests/ValidatePasswordTest.php +++ b/tests/ValidatePasswordTest.php @@ -2,14 +2,11 @@ require_once('common.php'); -class ValidatePasswordTest extends PHPUnit_Framework_TestCase -{ - public function testBasic() - { - +class ValidatePasswordTest extends PHPUnit_Framework_TestCase { + public function testBasic() { $config = Config::getInstance(); - // Set to the defaults, just to make sure. + // Set to the defaults, just to make sure. Config::write('password_validation', array( # '/regular expression/' => '$PALANG key (optional: + parameter)', '/.{5}/' => 'password_too_short 5', # minimum length 5 characters