mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
Fix phpcs errors
This commit is contained in:
parent
d574a26db3
commit
df6ccce6f2
@ -28,7 +28,7 @@
|
||||
|
||||
namespace Icinga\Config;
|
||||
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use \Zend_Config_Exception;
|
||||
|
||||
/**
|
||||
* Edit the sections and keys of an ini in-place
|
||||
@ -52,7 +52,7 @@ class 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)
|
||||
{
|
||||
@ -63,8 +63,8 @@ class IniEditor
|
||||
* Set the value of the given key.
|
||||
*
|
||||
* @param array $key The key to set
|
||||
* @param $value The value to set
|
||||
* @param $section The section to insert to.
|
||||
* @param mixed $value The value to set
|
||||
* @param string $section The section to insert to.
|
||||
*/
|
||||
public function set(array $key, $value, $section = null)
|
||||
{
|
||||
@ -80,8 +80,8 @@ class IniEditor
|
||||
/**
|
||||
* Reset the value of the given array element
|
||||
*
|
||||
* @param $key The key of the array value
|
||||
* @param $section The section of the array.
|
||||
* @param array $key The key of the array value
|
||||
* @param string $section The section of the array.
|
||||
*/
|
||||
public function resetArrayElement(array $key, $section = null)
|
||||
{
|
||||
@ -95,8 +95,8 @@ class IniEditor
|
||||
* Set the value for an array element
|
||||
*
|
||||
* @param array $key The key of the property
|
||||
* @param $value The value of the property
|
||||
* @param $section The section to use
|
||||
* @param mixed $value The value of the property
|
||||
* @param string $section The section to use
|
||||
*/
|
||||
public function setArrayElement(array $key, $value, $section = null)
|
||||
{
|
||||
@ -120,10 +120,9 @@ class IniEditor
|
||||
* Get the line of an array element
|
||||
*
|
||||
* @param array $key The key of the property.
|
||||
* @param $value The value
|
||||
* @param $section The section to use
|
||||
* @param string $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)
|
||||
{
|
||||
@ -149,7 +148,7 @@ class IniEditor
|
||||
* When it exists, set the key back to null
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
@ -163,8 +162,8 @@ class IniEditor
|
||||
/**
|
||||
* Create the section if it does not exist and set the properties
|
||||
*
|
||||
* @param $section The section name
|
||||
* @param $extend The section that should be extended by this section
|
||||
* @param string $section The section name
|
||||
* @param string $extend The section that should be extended by this section
|
||||
*/
|
||||
public function setSection($section, $extend = null)
|
||||
{
|
||||
@ -186,7 +185,7 @@ class IniEditor
|
||||
/**
|
||||
* Remove a section declaration
|
||||
*
|
||||
* @param $section The section name
|
||||
* @param string $section The section name
|
||||
*/
|
||||
public function removeSection($section)
|
||||
{
|
||||
@ -200,8 +199,8 @@ class IniEditor
|
||||
* Insert the key at the end of the corresponding section
|
||||
*
|
||||
* @param array $key The key to insert
|
||||
* @param $value The value to insert
|
||||
* @param array $key The key to insert
|
||||
* @param mixed $value The value to insert
|
||||
* @param string $section
|
||||
*/
|
||||
private function insert(array $key, $value, $section = null)
|
||||
{
|
||||
@ -260,8 +259,8 @@ class IniEditor
|
||||
/**
|
||||
* Insert the text at line $lineNr
|
||||
*
|
||||
* @param $lineNr The line nr the inserted line should have
|
||||
* @param $toInsert The text that will be inserted
|
||||
* @param int $lineNr The line nr the inserted line should have
|
||||
* @param string $toInsert The text that will be inserted
|
||||
*/
|
||||
private function insertAtLine($lineNr, $toInsert)
|
||||
{
|
||||
@ -271,14 +270,14 @@ class IniEditor
|
||||
/**
|
||||
* Update the line $lineNr
|
||||
*
|
||||
* @param $lineNr The line number of the target line
|
||||
* @param $toInsert The new line content
|
||||
* @param int $lineNr The line number of the target line
|
||||
* @param string $content The content to replace
|
||||
*/
|
||||
private function updateLine($lineNr, $content)
|
||||
{
|
||||
$comment = $this->getComment($this->text[$lineNr]);
|
||||
if (strlen($comment) > 0) {
|
||||
$comment = " ; " . trim($comment);
|
||||
$comment = ' ; ' . trim($comment);
|
||||
}
|
||||
$this->text[$lineNr] = str_pad($content, 43) . $comment;
|
||||
}
|
||||
@ -286,7 +285,7 @@ class IniEditor
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@ -299,13 +298,13 @@ class IniEditor
|
||||
$cleaned = preg_replace('/^[^;"]*"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"/s', '', $lineContent);
|
||||
|
||||
$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
|
||||
*
|
||||
* @param $lineNr The lineNr starting at 0
|
||||
* @param int $lineNr The lineNr starting at 0
|
||||
*/
|
||||
private function deleteLine($lineNr)
|
||||
{
|
||||
@ -316,17 +315,20 @@ class IniEditor
|
||||
* Format a key-value pair to an INI file-entry
|
||||
*
|
||||
* @param array $key The key
|
||||
* @param $value The value
|
||||
* @param mixed $value The value
|
||||
*
|
||||
* @return string The formatted key-value pair
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @param array $key
|
||||
* @return string
|
||||
*/
|
||||
private function formatKey(array $key)
|
||||
{
|
||||
@ -336,7 +338,7 @@ class IniEditor
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@ -371,23 +373,23 @@ class IniEditor
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
return preg_match(
|
||||
'/^\s*' . $this->formatKey($key) .'\s*=\s*/'
|
||||
,$lineContent
|
||||
'/^\s*' . $this->formatKey($key) .'\s*=\s*/',
|
||||
$lineContent
|
||||
) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @return bool True, when the lineContent is a section declaration
|
||||
@ -404,7 +406,7 @@ class IniEditor
|
||||
/**
|
||||
* Get the line where the section begins
|
||||
*
|
||||
* @param $section The section
|
||||
* @param string $section The section
|
||||
*
|
||||
* @return int The line number
|
||||
*/
|
||||
@ -424,13 +426,12 @@ class IniEditor
|
||||
* Get the line number where the given key occurs
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
private function getKeyLine(array $keys, $section = null)
|
||||
{
|
||||
$key = implode($this->nestSeparator,$keys);
|
||||
$inSection = isset($section) ? false : true;
|
||||
$i = 0;
|
||||
foreach ($this->text as $line) {
|
||||
@ -451,7 +452,7 @@ class IniEditor
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
@ -461,9 +462,9 @@ class IniEditor
|
||||
/**
|
||||
* Insert a new element into a specific position of an array
|
||||
*
|
||||
* @param $array The array to use
|
||||
* @param $pos The target position
|
||||
* @param $element The element to insert
|
||||
* @param array $array The array to use
|
||||
* @param int $pos The target position
|
||||
* @param mixed $element The element to insert
|
||||
*
|
||||
* @return array The changed array
|
||||
*/
|
||||
@ -476,10 +477,12 @@ class IniEditor
|
||||
/**
|
||||
* Remove an element from an array
|
||||
*
|
||||
* @param $array The array to use
|
||||
* @param $pos The position to remove
|
||||
* @param array $array The array to use
|
||||
* @param mixed $pos The position to remove
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function removeFromArray($array, $pos)
|
||||
private function removeFromArray(array $array, $pos)
|
||||
{
|
||||
unset($array[$pos]);
|
||||
return array_values($array);
|
||||
@ -488,10 +491,9 @@ class IniEditor
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @throws Zend_Config_Exception
|
||||
*/
|
||||
private function formatValue($value)
|
||||
@ -507,4 +509,3 @@ class IniEditor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,14 +28,16 @@
|
||||
|
||||
namespace Icinga\Config;
|
||||
|
||||
use Zend_Config;
|
||||
use Zend_Config_Ini;
|
||||
use \Zend_Config;
|
||||
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
|
||||
* 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
|
||||
@ -181,4 +183,3 @@ class PreservingIniWriter extends \Zend_Config_Writer_FileAbstract
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user