Code style and test fixes

refs #3777
This commit is contained in:
Jannis Moßhammer 2013-08-16 16:46:58 +02:00 committed by Eric Lippmann
parent c705f5d475
commit 4810a0d47e
2 changed files with 81 additions and 66 deletions

View File

@ -28,8 +28,6 @@
namespace Icinga\Config; namespace Icinga\Config;
use \Zend_Config_Exception;
/** /**
* Edit the sections and keys of an ini in-place * Edit the sections and keys of an ini in-place
*/ */
@ -63,8 +61,8 @@ class IniEditor
* Set the value of the given key. * Set the value of the given key.
* *
* @param array $key The key to set * @param array $key The key to set
* @param mixed $value The value to set * @param string $value The value to set
* @param string $section The section to insert to. * @param array $section The section to insert to.
*/ */
public function set(array $key, $value, $section = null) public function set(array $key, $value, $section = null)
{ {
@ -81,7 +79,7 @@ class IniEditor
* Reset the value of the given array element * Reset the value of the given array element
* *
* @param array $key The key of the array value * @param array $key The key of the array value
* @param string $section The section of the array. * @param array $section The section of the array.
*/ */
public function resetArrayElement(array $key, $section = null) public function resetArrayElement(array $key, $section = null)
{ {
@ -95,8 +93,8 @@ class IniEditor
* Set the value for an array element * Set the value for an array element
* *
* @param array $key The key of the property * @param array $key The key of the property
* @param mixed $value The value of the property * @param string $value The value of the property
* @param string $section The section to use * @param array $section The section to use
*/ */
public function setArrayElement(array $key, $value, $section = null) public function setArrayElement(array $key, $value, $section = null)
{ {
@ -120,9 +118,10 @@ class IniEditor
* Get the line of an array element * Get the line of an array element
* *
* @param array $key The key of the property. * @param array $key The key of the property.
* @param string $section The section to use * @param $value The value
* @param $section The section to use
* *
* @return int The line of the array element. * @return The line of the array element.
*/ */
private function getArrayElement(array $key, $section = null) private function getArrayElement(array $key, $section = null)
{ {
@ -148,7 +147,7 @@ class IniEditor
* When it exists, set the key back to null * When it exists, set the key back to null
* *
* @param array $key The key to reset * @param array $key The key to reset
* @param string $section The section of the key * @param array $section The section of the key
*/ */
public function reset(array $key, $section = null) public function reset(array $key, $section = null)
{ {
@ -163,7 +162,7 @@ class IniEditor
* Create the section if it does not exist and set the properties * Create the section if it does not exist and set the properties
* *
* @param string $section The section name * @param string $section The section name
* @param string $extend The section that should be extended by this section * @param array $extend The section that should be extended by this section
*/ */
public function setSection($section, $extend = null) public function setSection($section, $extend = null)
{ {
@ -200,7 +199,7 @@ class IniEditor
* *
* @param array $key The key to insert * @param array $key The key to insert
* @param mixed $value The value to insert * @param mixed $value The value to insert
* @param string $section * @param array $key The key to insert
*/ */
private function insert(array $key, $value, $section = null) private function insert(array $key, $value, $section = null)
{ {
@ -260,8 +259,8 @@ class IniEditor
/** /**
* Insert the text at line $lineNr * Insert the text at line $lineNr
* *
* @param int $lineNr The line nr the inserted line should have * @param $lineNr The line nr the inserted line should have
* @param string $toInsert The text that will be inserted * @param $toInsert The text that will be inserted
*/ */
private function insertAtLine($lineNr, $toInsert) private function insertAtLine($lineNr, $toInsert)
{ {
@ -271,14 +270,14 @@ class IniEditor
/** /**
* Update the line $lineNr * Update the line $lineNr
* *
* @param int $lineNr The line number of the target line * @param $lineNr The line number of the target line
* @param string $content The content to replace * @param $toInsert The new line content
*/ */
private function updateLine($lineNr, $content) private function updateLine($lineNr, $content)
{ {
$comment = $this->getComment($this->text[$lineNr]); $comment = $this->getComment($this->text[$lineNr]);
if (strlen($comment) > 0) { if (strlen($comment) > 0) {
$comment = ' ; ' . trim($comment); $comment = " ; " . trim($comment);
} }
$this->text[$lineNr] = str_pad($content, 43) . $comment; $this->text[$lineNr] = str_pad($content, 43) . $comment;
} }
@ -286,7 +285,7 @@ class IniEditor
/** /**
* Get the comment from the given line * Get the comment from the given line
* *
* @param string $lineContent The content of the line * @param $lineContent The content of the line
* *
* @return string The extracted comment * @return string The extracted comment
*/ */
@ -298,14 +297,14 @@ class IniEditor
*/ */
$cleaned = preg_replace('/^[^;"]*"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"/s', '', $lineContent); $cleaned = preg_replace('/^[^;"]*"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"/s', '', $lineContent);
$matches = mb_split(';', $cleaned, 2); $matches = explode(';', $cleaned, 2);
return array_key_exists(1, $matches) ? $matches[1] : ''; return array_key_exists(1, $matches) ? $matches[1] : '';
} }
/** /**
* Delete the line $lineNr * Delete the line $lineNr
* *
* @param int $lineNr The lineNr starting at 0 * @param $lineNr The lineNr starting at 0
*/ */
private function deleteLine($lineNr) private function deleteLine($lineNr)
{ {
@ -315,8 +314,8 @@ class IniEditor
/** /**
* Format a key-value pair to an INI file-entry * Format a key-value pair to an INI file-entry
* *
* @param array $key The key * @param array $key The key to format
* @param mixed $value The value * @param string $value The value to format
* *
* @return string The formatted key-value pair * @return string The formatted key-value pair
*/ */
@ -328,7 +327,8 @@ class IniEditor
/** /**
* Format a key to an INI key * Format a key to an INI key
* *
* @param array $key * @param array $key the key array to format
*
* @return string * @return string
*/ */
private function formatKey(array $key) private function formatKey(array $key)
@ -339,7 +339,7 @@ class IniEditor
/** /**
* Get the first line after the given $section * Get the first line after the given $section
* *
* @param string $section The name of the section * @param $section The name of the section
* *
* @return int The line number of the section * @return int The line number of the section
*/ */
@ -377,7 +377,7 @@ class IniEditor
* @param string $lineContent The content of the line * @param string $lineContent The content of the line
* @param array $key The key this declaration is supposed to have * @param array $key The key this declaration is supposed to have
* *
* @return bool True, when the lineContent is a property declaration * @return boolean True, when the lineContent is a property declaration
*/ */
private function isPropertyDeclaration($lineContent, array $key) private function isPropertyDeclaration($lineContent, array $key)
{ {
@ -390,7 +390,7 @@ class IniEditor
/** /**
* Check if the given line contains a section declaration * Check if the given line contains a section declaration
* *
* @param string $lineContent The content of the line * @param $lineContent The content of the line
* @param string $section The optional section name that will be assumed * @param string $section The optional section name that will be assumed
* *
* @return bool True, when the lineContent is a section declaration * @return bool True, when the lineContent is a section declaration
@ -407,7 +407,7 @@ class IniEditor
/** /**
* Get the line where the section begins * Get the line where the section begins
* *
* @param string $section The section * @param $section The section
* *
* @return int The line number * @return int The line number
*/ */
@ -427,12 +427,13 @@ class IniEditor
* Get the line number where the given key occurs * Get the line number where the given key occurs
* *
* @param array $keys The key and its parents * @param array $keys The key and its parents
* @param string $section The section of the key * @param $section The section of the key
* *
* @return int The line number * @return int The line number
*/ */
private function getKeyLine(array $keys, $section = null) private function getKeyLine(array $keys, $section = null)
{ {
$key = implode($this->nestSeparator, $keys);
$inSection = isset($section) ? false : true; $inSection = isset($section) ? false : true;
$i = 0; $i = 0;
foreach ($this->text as $line) { foreach ($this->text as $line) {
@ -453,7 +454,7 @@ class IniEditor
/** /**
* Get the last line number occurring in the text * Get the last line number occurring in the text
* *
* @return int The line number of the last line * @return The line number of the last line
*/ */
private function getLastLine() private function getLastLine()
{ {
@ -463,9 +464,9 @@ class IniEditor
/** /**
* Insert a new element into a specific position of an array * Insert a new element into a specific position of an array
* *
* @param array $array The array to use * @param $array The array to use
* @param int $pos The target position * @param $pos The target position
* @param mixed $element The element to insert * @param $element The element to insert
* *
* @return array The changed array * @return array The changed array
*/ */
@ -478,12 +479,10 @@ class IniEditor
/** /**
* Remove an element from an array * Remove an element from an array
* *
* @param array $array The array to use * @param $array The array to use
* @param mixed $pos The position to remove * @param $pos The position to remove
*
* @return array
*/ */
private function removeFromArray(array $array, $pos) private function removeFromArray($array, $pos)
{ {
unset($array[$pos]); unset($array[$pos]);
return array_values($array); return array_values($array);
@ -492,9 +491,10 @@ class IniEditor
/** /**
* Prepare a value for INe * Prepare a value for INe
* *
* @param mixed $value The value of the string * @param $value The value of the string
* *
* @return string The formatted value * @return string The formatted value
*
* @throws Zend_Config_Exception * @throws Zend_Config_Exception
*/ */
private function formatValue($value) private function formatValue($value)

View File

@ -87,7 +87,11 @@ class GeneralFormTest extends \Test\Icinga\Web\Form\BaseFormTest
) )
) )
); );
$form->setResources(
array(
'db' => 'db'
)
);
$form->setConfigDir('/tmp'); $form->setConfigDir('/tmp');
$view = new Zend_View(); $view = new Zend_View();
@ -117,7 +121,13 @@ class GeneralFormTest extends \Test\Icinga\Web\Form\BaseFormTest
) )
); );
$form->setConfigDir('/tmp'); $form->setConfigDir('/tmp');
$form->setResources(
array(
'db' => 'db'
)
);
$form->create(); $form->create();
$view = new Zend_View(); $view = new Zend_View();
$this->assertFalse( $this->assertFalse(
@ -146,6 +156,11 @@ class GeneralFormTest extends \Test\Icinga\Web\Form\BaseFormTest
) )
); );
$form->setConfigDir('/tmp'); $form->setConfigDir('/tmp');
$form->setResources(
array(
'db' => 'db'
)
);
$form->create(); $form->create();
$view = new Zend_View(); $view = new Zend_View();