Fix phpcs errors

This commit is contained in:
Marius Hein 2013-08-20 17:34:47 +02:00
parent d574a26db3
commit df6ccce6f2
2 changed files with 117 additions and 115 deletions

View File

@ -28,7 +28,7 @@
namespace Icinga\Config; namespace Icinga\Config;
use Icinga\Exception\ConfigurationError; use \Zend_Config_Exception;
/** /**
* Edit the sections and keys of an ini in-place * Edit the sections and keys of an ini in-place
@ -52,7 +52,7 @@ class IniEditor
/** /**
* Create a new IniEditor * Create a new IniEditor
* *
* @param $content The content of the ini as string * @param string $content The content of the ini as string
*/ */
public function __construct($content) public function __construct($content)
{ {
@ -63,8 +63,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 $value The value to set * @param mixed $value The value to set
* @param $section The section to insert to. * @param string $section The section to insert to.
*/ */
public function set(array $key, $value, $section = null) public function set(array $key, $value, $section = null)
{ {
@ -80,8 +80,8 @@ class IniEditor
/** /**
* Reset the value of the given array element * Reset the value of the given array element
* *
* @param $key The key of the array value * @param array $key The key of the array value
* @param $section The section of the array. * @param string $section The section of the array.
*/ */
public function resetArrayElement(array $key, $section = null) public function resetArrayElement(array $key, $section = null)
{ {
@ -95,8 +95,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 $value The value of the property * @param mixed $value The value of the property
* @param $section The section to use * @param string $section The section to use
*/ */
public function setArrayElement(array $key, $value, $section = null) public function setArrayElement(array $key, $value, $section = null)
{ {
@ -120,10 +120,9 @@ 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 $value The value * @param string $section The section to use
* @param $section The section to use
* *
* @return The line of the array element. * @return int The line of the array element.
*/ */
private function getArrayElement(array $key, $section = null) private function getArrayElement(array $key, $section = null)
{ {
@ -149,7 +148,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 $section The section of the key * @param string $section The section of the key
*/ */
public function reset(array $key, $section = null) public function reset(array $key, $section = null)
{ {
@ -163,8 +162,8 @@ 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 $section The section name * @param string $section The section name
* @param $extend The section that should be extended by this section * @param string $extend The section that should be extended by this section
*/ */
public function setSection($section, $extend = null) public function setSection($section, $extend = null)
{ {
@ -186,7 +185,7 @@ class IniEditor
/** /**
* Remove a section declaration * Remove a section declaration
* *
* @param $section The section name * @param string $section The section name
*/ */
public function removeSection($section) public function removeSection($section)
{ {
@ -200,8 +199,8 @@ class IniEditor
* Insert the key at the end of the corresponding section * Insert the key at the end of the corresponding section
* *
* @param array $key The key to insert * @param array $key The key to insert
* @param $value The value to insert * @param mixed $value The value to insert
* @param array $key The key to insert * @param string $section
*/ */
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 $lineNr The line nr the inserted line should have * @param int $lineNr The line nr the inserted line should have
* @param $toInsert The text that will be inserted * @param string $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 $lineNr The line number of the target line * @param int $lineNr The line number of the target line
* @param $toInsert The new line content * @param string $content The content to replace
*/ */
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 $lineContent The content of the line * @param string $lineContent The content of the line
* *
* @return string The extracted comment * @return string The extracted comment
*/ */
@ -299,13 +298,13 @@ class IniEditor
$cleaned = preg_replace('/^[^;"]*"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"/s', '', $lineContent); $cleaned = preg_replace('/^[^;"]*"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"/s', '', $lineContent);
$matches = mb_split(';', $cleaned, 2); $matches = mb_split(';', $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 $lineNr The lineNr starting at 0 * @param int $lineNr The lineNr starting at 0
*/ */
private function deleteLine($lineNr) private function deleteLine($lineNr)
{ {
@ -316,17 +315,20 @@ 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
* @param $value The value * @param mixed $value The value
* *
* @return string The formatted key-value pair * @return string The formatted key-value pair
*/ */
private function formatKeyValuePair(array $key, $value) private function formatKeyValuePair(array $key, $value)
{ {
return str_pad($this->formatKey($key),19) . " = ".$this->formatValue($value); return str_pad($this->formatKey($key), 19) . ' = ' . $this->formatValue($value);
} }
/** /**
* Format a key to an INI key * Format a key to an INI key
*
* @param array $key
* @return string
*/ */
private function formatKey(array $key) private function formatKey(array $key)
{ {
@ -336,7 +338,7 @@ class IniEditor
/** /**
* Get the first line after the given $section * Get the first line after the given $section
* *
* @param $section The name of the section * @param string $section The name of the section
* *
* @return int The line number of the section * @return int The line number of the section
*/ */
@ -371,23 +373,23 @@ class IniEditor
/** /**
* Check if the line contains the property declaration for a key * Check if the line contains the property declaration for a key
* *
* @param $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 boolean True, when the lineContent is a property declaration * @return bool True, when the lineContent is a property declaration
*/ */
private function isPropertyDeclaration($lineContent, array $key) private function isPropertyDeclaration($lineContent, array $key)
{ {
return preg_match( return preg_match(
'/^\s*' . $this->formatKey($key) .'\s*=\s*/' '/^\s*' . $this->formatKey($key) .'\s*=\s*/',
,$lineContent $lineContent
) === 1; ) === 1;
} }
/** /**
* Check if the given line contains a section declaration * Check if the given line contains a section declaration
* *
* @param $lineContent The content of the line * @param string $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
@ -404,7 +406,7 @@ class IniEditor
/** /**
* Get the line where the section begins * Get the line where the section begins
* *
* @param $section The section * @param string $section The section
* *
* @return int The line number * @return int The line number
*/ */
@ -424,13 +426,12 @@ 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 $section The section of the key * @param string $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) {
@ -451,7 +452,7 @@ class IniEditor
/** /**
* Get the last line number occurring in the text * Get the last line number occurring in the text
* *
* @return The line number of the last line * @return int The line number of the last line
*/ */
private function getLastLine() private function getLastLine()
{ {
@ -461,9 +462,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 The array to use * @param array $array The array to use
* @param $pos The target position * @param int $pos The target position
* @param $element The element to insert * @param mixed $element The element to insert
* *
* @return array The changed array * @return array The changed array
*/ */
@ -476,10 +477,12 @@ class IniEditor
/** /**
* Remove an element from an array * Remove an element from an array
* *
* @param $array The array to use * @param array $array The array to use
* @param $pos The position to remove * @param mixed $pos The position to remove
*
* @return array
*/ */
private function removeFromArray($array, $pos) private function removeFromArray(array $array, $pos)
{ {
unset($array[$pos]); unset($array[$pos]);
return array_values($array); return array_values($array);
@ -488,10 +491,9 @@ class IniEditor
/** /**
* Prepare a value for INe * Prepare a value for INe
* *
* @param $value The value of the string * @param mixed $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)
@ -507,4 +509,3 @@ class IniEditor
} }
} }
} }

View File

@ -28,14 +28,16 @@
namespace Icinga\Config; namespace Icinga\Config;
use Zend_Config; use \Zend_Config;
use Zend_Config_Ini; use \Zend_Config_Ini;
use \Zend_Config_Writer_FileAbstract;
use \Icinga\Config\IniEditor;
/** /**
* A ini file adapter that respects the file structure and the comments of already * A ini file adapter that respects the file structure and the comments of already
* existing ini files * existing ini files
*/ */
class PreservingIniWriter extends \Zend_Config_Writer_FileAbstract class PreservingIniWriter extends Zend_Config_Writer_FileAbstract
{ {
/** /**
* Render the Zend_Config into a config file string * Render the Zend_Config into a config file string
@ -181,4 +183,3 @@ class PreservingIniWriter extends \Zend_Config_Writer_FileAbstract
} }
} }
} }