Skip to content

Commit

Permalink
Coding style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
madhuracj committed Nov 3, 2013
1 parent d64ea21 commit 184316d
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 84 deletions.
12 changes: 8 additions & 4 deletions libraries/config/ConfigFile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class ConfigFile
/**
* Constructor
*
* @param array $base_config base configuration read from {@link PMA_Config::$base_config},
* @param array $base_config base configuration read from
* {@link PMA_Config::$base_config},
* use only when not in PMA Setup
*/
public function __construct(array $base_config = null)
Expand Down Expand Up @@ -209,7 +210,8 @@ public function set($path, $value, $canonical_path = null)
$remove_path = $value === $default_value;
if ($this->_isInSetup) {
// remove if it has a default value or is empty
$remove_path = $remove_path || (empty($value) && empty($default_value));
$remove_path = $remove_path
|| (empty($value) && empty($default_value));
} else {
// get original config values not overwritten by user
// preferences to allow for overwriting options set in
Expand All @@ -218,8 +220,10 @@ public function set($path, $value, $canonical_path = null)
$canonical_path,
$this->_baseCfg
);
// remove if it has a default value and base config (config.inc.php) uses default value
$remove_path = $remove_path && ($instance_default_value === $default_value);
// remove if it has a default value and base config (config.inc.php)
// uses default value
$remove_path = $remove_path
&& ($instance_default_value === $default_value);
}
if ($remove_path) {
PMA_arrayRemove($path, $_SESSION[$this->_id]);
Expand Down
13 changes: 7 additions & 6 deletions libraries/config/Form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ class Form
/**
* Constructor, reads default config values
*
* @param string $form_name Form name
* @param array $form Form data
* @param ConfigFile $cf Config file instance
* @param int $index arbitrary index, stored in Form::$index
* @param string $form_name Form name
* @param array $form Form data
* @param ConfigFile $cf Config file instance
* @param int $index arbitrary index, stored in Form::$index
*/
public function __construct($form_name, array $form, ConfigFile $cf, $index = null)
{
public function __construct(
$form_name, array $form, ConfigFile $cf, $index = null
) {
$this->index = $index;
$this->_configFile = $cf;
$this->loadForm($form_name, $form);
Expand Down
8 changes: 6 additions & 2 deletions libraries/config/FormDisplay.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ public function getConfigFile()
*/
public function registerForm($form_name, array $form, $server_id = null)
{
$this->_forms[$form_name] = new Form($form_name, $form, $this->_configFile, $server_id);
$this->_forms[$form_name] = new Form(
$form_name, $form, $this->_configFile, $server_id
);
$this->_isValidated = false;
foreach ($this->_forms[$form_name]->fields as $path) {
$work_path = $server_id === null
Expand Down Expand Up @@ -182,7 +184,9 @@ private function _validate()
}

// run validation
$errors = PMA_Validator::validate($this->_configFile, $paths, $values, false);
$errors = PMA_Validator::validate(
$this->_configFile, $paths, $values, false
);

// change error keys from canonical paths to work paths
if (is_array($errors) && count($errors) > 0) {
Expand Down
11 changes: 7 additions & 4 deletions libraries/config/Validator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class PMA_Validator
* Returns validator list
*
* @param ConfigFile $cf Config file instance
*
* @return array
*/
public static function getValidators(ConfigFile $cf)
Expand All @@ -49,7 +50,8 @@ public static function getValidators(ConfigFile $cf)
for ($i = 1; $i < count($uv); $i++) {
if (substr($uv[$i], 0, 6) == 'value:') {
$uv[$i] = PMA_arrayRead(
substr($uv[$i], 6), $GLOBALS['PMA_Config']->base_settings
substr($uv[$i], 6),
$GLOBALS['PMA_Config']->base_settings
);
}
}
Expand All @@ -72,16 +74,17 @@ public static function getValidators(ConfigFile $cf)
* cleanup in HTML documen
* o false - when no validators match name(s) given by $validator_id
*
* @param ConfigFile $cf Config file instance
* @param ConfigFile $cf Config file instance
* @param string|array $validator_id ID of validator(s) to run
* @param array &$values Values to validate
* @param bool $isPostSource tells whether $values are directly from
* POST request
*
* @return bool|array
*/
public static function validate(ConfigFile $cf, $validator_id, &$values, $isPostSource)
{
public static function validate(
ConfigFile $cf, $validator_id, &$values, $isPostSource
) {
// find validators
$validator_id = (array) $validator_id;
$validators = static::getValidators($cf);
Expand Down
4 changes: 2 additions & 2 deletions libraries/core.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,8 @@ function PMA_downloadHeader($filename, $mimetype, $length = 0, $no_cache = true)
* $path is a string describing position of an element in an associative array,
* eg. Servers/1/host refers to $array[Servers][1][host]
*
* @param string $path path in the arry
* @param array $array the array
* @param string $path path in the arry
* @param array $array the array
*
* @return mixed array element or $default
*/
Expand Down
1 change: 1 addition & 0 deletions libraries/user_preferences.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Common initialization for user preferences modification pages
*
* @param ConfigFile $cf Config file instance
*
* @return void
*/
function PMA_userprefsPageInit(ConfigFile $cf)
Expand Down
5 changes: 4 additions & 1 deletion setup/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
//
// Save generated config file on the server
//
file_put_contents($config_file_path, ConfigGenerator::getConfigFile($GLOBALS['ConfigFile']));
file_put_contents(
$config_file_path,
ConfigGenerator::getConfigFile($GLOBALS['ConfigFile'])
);
header('HTTP/1.1 303 See Other');
header('Location: index.php?action_done=config_saved');
exit;
Expand Down
18 changes: 13 additions & 5 deletions setup/lib/ConfigGenerator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ class ConfigGenerator
* Creates config file
*
* @param ConfigFile $cf Config file instance
*
* @return string
*/
public static function getConfigFile(ConfigFile $cf)
{
$crlf = (isset($_SESSION['eol']) && $_SESSION['eol'] == 'win') ? "\r\n" : "\n";
$crlf = (isset($_SESSION['eol']) && $_SESSION['eol'] == 'win')
? "\r\n"
: "\n";
$c = $cf->getConfig();

// header
Expand All @@ -38,7 +41,9 @@ public static function getConfigFile(ConfigFile $cf)
if ($cf->getServerCount() > 0) {
$ret .= "/* Servers configuration */$crlf\$i = 0;" . $crlf . $crlf;
foreach ($c['Servers'] as $id => $server) {
$ret .= '/* Server: ' . strtr($cf->getServerName($id) . " [$id] ", '*/', '-') . "*/" . $crlf
$ret .= '/* Server: '
. strtr($cf->getServerName($id) . " [$id] ", '*/', '-')
. "*/" . $crlf
. '$i++;' . $crlf;
foreach ($server as $k => $v) {
$k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
Expand Down Expand Up @@ -88,17 +93,20 @@ public static function getConfigFile(ConfigFile $cf)
private static function _getVarExport($var_name, $var_value, $crlf)
{
if (!is_array($var_value) || empty($var_value)) {
return "\$cfg['$var_name'] = " . var_export($var_value, true) . ';' . $crlf;
return "\$cfg['$var_name'] = "
. var_export($var_value, true) . ';' . $crlf;
}
$ret = '';
if (self::_isZeroBasedArray($var_value)) {
$ret = "\$cfg['$var_name'] = " . self::_exportZeroBasedArray($var_value, $crlf)
$ret = "\$cfg['$var_name'] = "
. self::_exportZeroBasedArray($var_value, $crlf)
. ';' . $crlf;
} else {
// string keys: $cfg[key][subkey] = value
foreach ($var_value as $k => $v) {
$k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
$ret .= "\$cfg['$var_name']['$k'] = " . var_export($v, true) . ';' . $crlf;
$ret .= "\$cfg['$var_name']['$k'] = "
. var_export($v, true) . ';' . $crlf;
}
}
return $ret;
Expand Down
32 changes: 17 additions & 15 deletions test/classes/config/PMA_Form_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ function setup()
$GLOBALS['PMA_Config'] = new PMA_Config();
$GLOBALS['PMA_Config']->enableBc();
$GLOBALS['server'] = 0;
$this->object = new Form('pma_form_name', array('pma_form1','pma_form2'), new ConfigFile(), 1);
$this->object = new Form(
'pma_form_name', array('pma_form1','pma_form2'), new ConfigFile(), 1
);
}

/**
* tearDown for test cases
*
*
* @return void
*/
protected function tearDown()
Expand All @@ -53,7 +55,7 @@ protected function tearDown()

/**
* Test for Form::__constructor
*
*
* @return void
*/
public function testContructor()
Expand All @@ -74,7 +76,7 @@ public function testContructor()

/**
* Test for Form::getOptionType
*
*
* @return void
*/
public function testGetOptionType()
Expand All @@ -98,29 +100,29 @@ public function testGetOptionType()

/**
* Test for Form::getOptionValueList
*
*
* @return void
*/
public function testGetOptionValueList()
{
{
$this->assertEquals(
array('NHibernate C# DO', 'NHibernate XML'),
$this->object->getOptionValueList("Export/codegen_format")
);

$this->assertEquals(
array(
'auto' => 'auto',
'1' => 1,
'auto' => 'auto',
'1' => 1,
'0' => 0
),
$this->object->getOptionValueList("OBGzip")
);

$this->assertEquals(
array(
'none' => 'Nowhere',
'left' => 'Left',
'none' => 'Nowhere',
'left' => 'Left',
'right' => 'Right',
'both' => "Both"
),
Expand All @@ -130,7 +132,7 @@ public function testGetOptionValueList()

/**
* Test for Form::_readFormPathsCallback
*
*
* @return void
*/
public function testReadFormPathsCallBack()
Expand Down Expand Up @@ -182,7 +184,7 @@ public function testReadFormPathsCallBack()

/**
* Test for Form::readFormPaths
*
*
* @return void
*/
public function testReadFormPaths()
Expand Down Expand Up @@ -228,7 +230,7 @@ public function testReadFormPaths()

preg_match("/^\:group\:end\:(\d+)$/", $key, $matches);
$digit = $matches[1];

$this->assertEquals(
"foo/bar/:group:end:" . $digit,
$result[':group:end:' . $digit]
Expand All @@ -237,7 +239,7 @@ public function testReadFormPaths()

/**
* Test for Form::readTypes
*
*
* @return void
*/
public function testReadTypes()
Expand Down Expand Up @@ -271,7 +273,7 @@ public function testReadTypes()

/**
* Test for Form::loadForm
*
*
* @return void
*/
public function testLoadForm()
Expand Down
3 changes: 2 additions & 1 deletion test/classes/plugin/auth/PMA_AuthenticationCookie_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@ public function testAuthSetUserWithHeaders()
isset($_COOKIE['pmaServer-2'])
);

// target can be "phpunit" or "ide-phpunut.php", depending on testing environment
// target can be "phpunit" or "ide-phpunut.php",
// depending on testing environment
$this->assertStringStartsWith(
'Location: http://phpmyadmin.net/index.php?target=',
$GLOBALS['header'][0]
Expand Down
Loading

0 comments on commit 184316d

Please sign in to comment.