@@ -62,10 +62,10 @@ discard block |
||
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * The end of line character used in the INI source string. |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 65 | + /** |
|
| 66 | + * The end of line character used in the INI source string. |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | 69 | public function getEOLChar() : string |
| 70 | 70 | { |
| 71 | 71 | return $this->eol; |
@@ -99,35 +99,35 @@ discard block |
||
| 99 | 99 | ); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Factory method: Creates a new ini helper instance from an ini string. |
|
| 104 | - * |
|
| 105 | - * @param string $iniContent |
|
| 106 | - * @return IniHelper |
|
| 107 | - */ |
|
| 102 | + /** |
|
| 103 | + * Factory method: Creates a new ini helper instance from an ini string. |
|
| 104 | + * |
|
| 105 | + * @param string $iniContent |
|
| 106 | + * @return IniHelper |
|
| 107 | + */ |
|
| 108 | 108 | public static function createFromString(string $iniContent) : IniHelper |
| 109 | 109 | { |
| 110 | 110 | return new IniHelper($iniContent); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Factory method: Creates a new empty ini helper. |
|
| 115 | - * |
|
| 116 | - * @return IniHelper |
|
| 117 | - */ |
|
| 113 | + /** |
|
| 114 | + * Factory method: Creates a new empty ini helper. |
|
| 115 | + * |
|
| 116 | + * @return IniHelper |
|
| 117 | + */ |
|
| 118 | 118 | public static function createNew() : IniHelper |
| 119 | 119 | { |
| 120 | 120 | return self::createFromString(''); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Adds a new data section, and returns the section instance. |
|
| 125 | - * If a section with the name already exists, returns that |
|
| 126 | - * section instead of creating a new one. |
|
| 127 | - * |
|
| 128 | - * @param string $name |
|
| 129 | - * @return IniHelper_Section |
|
| 130 | - */ |
|
| 123 | + /** |
|
| 124 | + * Adds a new data section, and returns the section instance. |
|
| 125 | + * If a section with the name already exists, returns that |
|
| 126 | + * section instead of creating a new one. |
|
| 127 | + * |
|
| 128 | + * @param string $name |
|
| 129 | + * @return IniHelper_Section |
|
| 130 | + */ |
|
| 131 | 131 | public function addSection(string $name) : IniHelper_Section |
| 132 | 132 | { |
| 133 | 133 | if(!isset($this->sections[$name])) { |
@@ -137,22 +137,22 @@ discard block |
||
| 137 | 137 | return $this->sections[$name]; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Retrieves a section by its name, if it exists. |
|
| 142 | - * |
|
| 143 | - * @param string $name |
|
| 144 | - * @return IniHelper_Section|NULL |
|
| 145 | - */ |
|
| 140 | + /** |
|
| 141 | + * Retrieves a section by its name, if it exists. |
|
| 142 | + * |
|
| 143 | + * @param string $name |
|
| 144 | + * @return IniHelper_Section|NULL |
|
| 145 | + */ |
|
| 146 | 146 | public function getSection(string $name) : ?IniHelper_Section |
| 147 | 147 | { |
| 148 | 148 | return $this->sections[$name] ?? null; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Gets the data from the INI file as an associative array. |
|
| 153 | - * |
|
| 154 | - * @return array<string,mixed> |
|
| 155 | - */ |
|
| 151 | + /** |
|
| 152 | + * Gets the data from the INI file as an associative array. |
|
| 153 | + * |
|
| 154 | + * @return array<string,mixed> |
|
| 155 | + */ |
|
| 156 | 156 | public function toArray() : array |
| 157 | 157 | { |
| 158 | 158 | $result = array(); |
@@ -172,17 +172,17 @@ discard block |
||
| 172 | 172 | return $result; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * Saves the INI content to the target file. |
|
| 177 | - * |
|
| 178 | - * @param string $filePath |
|
| 179 | - * @return IniHelper |
|
| 180 | - * @throws FileHelper_Exception |
|
| 181 | - * |
|
| 182 | - * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
| 183 | - * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
| 184 | - * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
| 185 | - */ |
|
| 175 | + /** |
|
| 176 | + * Saves the INI content to the target file. |
|
| 177 | + * |
|
| 178 | + * @param string $filePath |
|
| 179 | + * @return IniHelper |
|
| 180 | + * @throws FileHelper_Exception |
|
| 181 | + * |
|
| 182 | + * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
| 183 | + * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
| 184 | + * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
| 185 | + */ |
|
| 186 | 186 | public function saveToFile(string $filePath) : IniHelper |
| 187 | 187 | { |
| 188 | 188 | FileHelper::saveFile($filePath, $this->saveToString()); |
@@ -190,11 +190,11 @@ discard block |
||
| 190 | 190 | return $this; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * Returns the INI content as string. |
|
| 195 | - * |
|
| 196 | - * @return string |
|
| 197 | - */ |
|
| 193 | + /** |
|
| 194 | + * Returns the INI content as string. |
|
| 195 | + * |
|
| 196 | + * @return string |
|
| 197 | + */ |
|
| 198 | 198 | public function saveToString() : string |
| 199 | 199 | { |
| 200 | 200 | $parts = array(); |
@@ -207,15 +207,15 @@ discard block |
||
| 207 | 207 | return implode($this->eol, $parts); |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * Sets or adds the value of a setting in the INI content. |
|
| 212 | - * If the setting does not exist, it is added. Otherwise, |
|
| 213 | - * the existing value is overwritten. |
|
| 214 | - * |
|
| 215 | - * @param string $path A variable path, either <code>varname</code> or <code>section.varname</code>. |
|
| 216 | - * @param mixed $value |
|
| 217 | - * @return IniHelper |
|
| 218 | - */ |
|
| 210 | + /** |
|
| 211 | + * Sets or adds the value of a setting in the INI content. |
|
| 212 | + * If the setting does not exist, it is added. Otherwise, |
|
| 213 | + * the existing value is overwritten. |
|
| 214 | + * |
|
| 215 | + * @param string $path A variable path, either <code>varname</code> or <code>section.varname</code>. |
|
| 216 | + * @param mixed $value |
|
| 217 | + * @return IniHelper |
|
| 218 | + */ |
|
| 219 | 219 | public function setValue(string $path, $value) : IniHelper |
| 220 | 220 | { |
| 221 | 221 | $info = $this->parsePath($path); |
@@ -239,12 +239,12 @@ discard block |
||
| 239 | 239 | return $this; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - /** |
|
| 243 | - * Checks whether a section with the specified name exists. |
|
| 244 | - * |
|
| 245 | - * @param string $name |
|
| 246 | - * @return bool |
|
| 247 | - */ |
|
| 242 | + /** |
|
| 243 | + * Checks whether a section with the specified name exists. |
|
| 244 | + * |
|
| 245 | + * @param string $name |
|
| 246 | + * @return bool |
|
| 247 | + */ |
|
| 248 | 248 | public function sectionExists(string $name) : bool |
| 249 | 249 | { |
| 250 | 250 | foreach($this->sections as $section) { |
@@ -256,23 +256,23 @@ discard block |
||
| 256 | 256 | return false; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Retrieves the default section, which is used to add |
|
| 261 | - * values in the root of the document. |
|
| 262 | - * |
|
| 263 | - * @return IniHelper_Section |
|
| 264 | - */ |
|
| 259 | + /** |
|
| 260 | + * Retrieves the default section, which is used to add |
|
| 261 | + * values in the root of the document. |
|
| 262 | + * |
|
| 263 | + * @return IniHelper_Section |
|
| 264 | + */ |
|
| 265 | 265 | public function getDefaultSection() : IniHelper_Section |
| 266 | 266 | { |
| 267 | 267 | return $this->addSection(self::SECTION_DEFAULT); |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Retrieves all variable lines for the specified path. |
|
| 272 | - * |
|
| 273 | - * @param string $path A variable path. Either <code>varname</code> or <code>section.varname</code>. |
|
| 274 | - * @return INILine[] |
|
| 275 | - */ |
|
| 270 | + /** |
|
| 271 | + * Retrieves all variable lines for the specified path. |
|
| 272 | + * |
|
| 273 | + * @param string $path A variable path. Either <code>varname</code> or <code>section.varname</code>. |
|
| 274 | + * @return INILine[] |
|
| 275 | + */ |
|
| 276 | 276 | public function getLinesByVariable(string $path) : array |
| 277 | 277 | { |
| 278 | 278 | $info = $this->parsePath($path); |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | { |
| 40 | 40 | $section = $this->addSection(self::SECTION_DEFAULT); |
| 41 | 41 | |
| 42 | - if(empty($iniString)) { |
|
| 42 | + if (empty($iniString)) { |
|
| 43 | 43 | return; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $eol = ConvertHelper::detectEOLCharacter($iniString); |
| 47 | - if($eol !== null) { |
|
| 47 | + if ($eol !== null) { |
|
| 48 | 48 | $this->eol = $eol->getCharacter(); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $line = new INILine($value, $index); |
| 56 | 56 | |
| 57 | - if($line->isSection()) { |
|
| 57 | + if ($line->isSection()) { |
|
| 58 | 58 | $section = $this->addSection($line->getSectionName()); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | $iniPath = FileHelper::requireFileExists($iniPath); |
| 86 | 86 | |
| 87 | 87 | $content = file_get_contents($iniPath); |
| 88 | - if($content !== false) { |
|
| 88 | + if ($content !== false) { |
|
| 89 | 89 | return self::createFromString($content); |
| 90 | 90 | } |
| 91 | 91 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | public function addSection(string $name) : IniHelper_Section |
| 132 | 132 | { |
| 133 | - if(!isset($this->sections[$name])) { |
|
| 133 | + if (!isset($this->sections[$name])) { |
|
| 134 | 134 | $this->sections[$name] = new IniHelper_Section($this, $name); |
| 135 | 135 | } |
| 136 | 136 | |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | { |
| 158 | 158 | $result = array(); |
| 159 | 159 | |
| 160 | - foreach($this->sections as $section) |
|
| 160 | + foreach ($this->sections as $section) |
|
| 161 | 161 | { |
| 162 | - if($section->isDefault()) |
|
| 162 | + if ($section->isDefault()) |
|
| 163 | 163 | { |
| 164 | 164 | $result = array_merge($result, $section->toArray()); |
| 165 | 165 | } |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | { |
| 200 | 200 | $parts = array(); |
| 201 | 201 | |
| 202 | - foreach($this->sections as $section) |
|
| 202 | + foreach ($this->sections as $section) |
|
| 203 | 203 | { |
| 204 | 204 | $parts[] = $section->toString(); |
| 205 | 205 | } |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | public function sectionExists(string $name) : bool |
| 249 | 249 | { |
| 250 | - foreach($this->sections as $section) { |
|
| 251 | - if($section->getName() === $name) { |
|
| 250 | + foreach ($this->sections as $section) { |
|
| 251 | + if ($section->getName() === $name) { |
|
| 252 | 252 | return true; |
| 253 | 253 | } |
| 254 | 254 | } |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | { |
| 278 | 278 | $info = $this->parsePath($path); |
| 279 | 279 | |
| 280 | - if(!$this->sectionExists($info['section'])) { |
|
| 280 | + if (!$this->sectionExists($info['section'])) { |
|
| 281 | 281 | return array(); |
| 282 | 282 | } |
| 283 | 283 | |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | { |
| 293 | 293 | $parts = explode($this->pathSeparator, $path); |
| 294 | 294 | |
| 295 | - if(count($parts) === 1) |
|
| 295 | + if (count($parts) === 1) |
|
| 296 | 296 | { |
| 297 | 297 | return array( |
| 298 | 298 | 'section' => self::SECTION_DEFAULT, |
@@ -27,14 +27,14 @@ discard block |
||
| 27 | 27 | $this->subject = $subject; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public function setRemoveDuplicates(bool $remove=true, bool $caseInsensitive=false) : self |
|
| 30 | + public function setRemoveDuplicates(bool $remove = true, bool $caseInsensitive = false) : self |
|
| 31 | 31 | { |
| 32 | 32 | $this->removeDuplicates = $remove; |
| 33 | 33 | $this->duplicatesCaseInsensitive = $caseInsensitive; |
| 34 | 34 | return $this; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - public function setSorting(bool $sorting=true) : self |
|
| 37 | + public function setSorting(bool $sorting = true) : self |
|
| 38 | 38 | { |
| 39 | 39 | $this->sorting = $sorting; |
| 40 | 40 | return $this; |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | $words = $this->filterEmpty($words); |
| 57 | 57 | |
| 58 | - if($this->removeDuplicates) { |
|
| 58 | + if ($this->removeDuplicates) { |
|
| 59 | 59 | $words = $this->filterDuplicates($words); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if($this->sorting) { |
|
| 62 | + if ($this->sorting) { |
|
| 63 | 63 | usort($words, 'strnatcasecmp'); |
| 64 | 64 | } |
| 65 | 65 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | private function filterDuplicates(array $words) : array |
| 74 | 74 | { |
| 75 | - if($this->duplicatesCaseInsensitive) { |
|
| 75 | + if ($this->duplicatesCaseInsensitive) { |
|
| 76 | 76 | return $this->filterDuplicatesCaseInsensitive($words); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | { |
| 88 | 88 | return array_intersect_key( |
| 89 | 89 | $array, |
| 90 | - array_unique( array_map( "strtolower", $array ) ) |
|
| 90 | + array_unique(array_map("strtolower", $array)) |
|
| 91 | 91 | ); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -99,13 +99,13 @@ discard block |
||
| 99 | 99 | { |
| 100 | 100 | $keep = array(); |
| 101 | 101 | |
| 102 | - foreach($words as $word) |
|
| 102 | + foreach ($words as $word) |
|
| 103 | 103 | { |
| 104 | - if(empty($word)) { |
|
| 104 | + if (empty($word)) { |
|
| 105 | 105 | continue; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if(mb_strlen($word) < $this->minWordLength) { |
|
| 108 | + if (mb_strlen($word) < $this->minWordLength) { |
|
| 109 | 109 | continue; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | protected IniHelper $ini; |
| 27 | 27 | protected string $name; |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var INILine[] |
|
| 31 | - */ |
|
| 29 | + /** |
|
| 30 | + * @var INILine[] |
|
| 31 | + */ |
|
| 32 | 32 | protected array $lines = array(); |
| 33 | 33 | |
| 34 | 34 | public function __construct(IniHelper $ini, string $name) |
@@ -37,33 +37,33 @@ discard block |
||
| 37 | 37 | $this->name = $name; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * The section's name. |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 40 | + /** |
|
| 41 | + * The section's name. |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | 44 | public function getName() : string |
| 45 | 45 | { |
| 46 | 46 | return $this->name; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Whether this is the default section: this |
|
| 51 | - * is used internally to store all variables that |
|
| 52 | - * are not in any specific section. |
|
| 53 | - * |
|
| 54 | - * @return bool |
|
| 55 | - */ |
|
| 49 | + /** |
|
| 50 | + * Whether this is the default section: this |
|
| 51 | + * is used internally to store all variables that |
|
| 52 | + * are not in any specific section. |
|
| 53 | + * |
|
| 54 | + * @return bool |
|
| 55 | + */ |
|
| 56 | 56 | public function isDefault() : bool |
| 57 | 57 | { |
| 58 | 58 | return $this->name === IniHelper::SECTION_DEFAULT; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Adds a line instance to the section. |
|
| 63 | - * |
|
| 64 | - * @param INILine $line |
|
| 65 | - * @return IniHelper_Section |
|
| 66 | - */ |
|
| 61 | + /** |
|
| 62 | + * Adds a line instance to the section. |
|
| 63 | + * |
|
| 64 | + * @param INILine $line |
|
| 65 | + * @return IniHelper_Section |
|
| 66 | + */ |
|
| 67 | 67 | public function addLine(INILine $line) : IniHelper_Section |
| 68 | 68 | { |
| 69 | 69 | $this->lines[] = $line; |
@@ -71,12 +71,12 @@ discard block |
||
| 71 | 71 | return $this; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Converts the values contained in the section into |
|
| 76 | - * an associative array. |
|
| 77 | - * |
|
| 78 | - * @return array<string,array<int,string>> |
|
| 79 | - */ |
|
| 74 | + /** |
|
| 75 | + * Converts the values contained in the section into |
|
| 76 | + * an associative array. |
|
| 77 | + * |
|
| 78 | + * @return array<string,array<int,string>> |
|
| 79 | + */ |
|
| 80 | 80 | public function toArray() : array |
| 81 | 81 | { |
| 82 | 82 | $result = array(); |
@@ -136,12 +136,12 @@ discard block |
||
| 136 | 136 | return implode($this->ini->getEOLChar(), $lines); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Deletes a line from the section. |
|
| 141 | - * |
|
| 142 | - * @param INILine $toDelete |
|
| 143 | - * @return IniHelper_Section |
|
| 144 | - */ |
|
| 139 | + /** |
|
| 140 | + * Deletes a line from the section. |
|
| 141 | + * |
|
| 142 | + * @param INILine $toDelete |
|
| 143 | + * @return IniHelper_Section |
|
| 144 | + */ |
|
| 145 | 145 | public function deleteLine(INILine $toDelete) : IniHelper_Section |
| 146 | 146 | { |
| 147 | 147 | $keep = array(); |
@@ -226,15 +226,15 @@ discard block |
||
| 226 | 226 | return $this; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * Adds a variable value to the section. Unlike setValue(), this |
|
| 231 | - * will not overwrite any existing value. If the name is an existing |
|
| 232 | - * variable name, it will be converted to duplicate keys. |
|
| 233 | - * |
|
| 234 | - * @param string $name |
|
| 235 | - * @param mixed $value If this is an array, it will be treated as duplicate keys, and all values that are not present yet will be added. |
|
| 236 | - * @return IniHelper_Section |
|
| 237 | - */ |
|
| 229 | + /** |
|
| 230 | + * Adds a variable value to the section. Unlike setValue(), this |
|
| 231 | + * will not overwrite any existing value. If the name is an existing |
|
| 232 | + * variable name, it will be converted to duplicate keys. |
|
| 233 | + * |
|
| 234 | + * @param string $name |
|
| 235 | + * @param mixed $value If this is an array, it will be treated as duplicate keys, and all values that are not present yet will be added. |
|
| 236 | + * @return IniHelper_Section |
|
| 237 | + */ |
|
| 238 | 238 | public function addValue(string $name, $value) : IniHelper_Section |
| 239 | 239 | { |
| 240 | 240 | // array value? Treat it as duplicate keys. |
@@ -297,12 +297,12 @@ discard block |
||
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
| 300 | - /** |
|
| 301 | - * Retrieves all lines for the specified variable name. |
|
| 302 | - * |
|
| 303 | - * @param string $name |
|
| 304 | - * @return INILine[] |
|
| 305 | - */ |
|
| 300 | + /** |
|
| 301 | + * Retrieves all lines for the specified variable name. |
|
| 302 | + * |
|
| 303 | + * @param string $name |
|
| 304 | + * @return INILine[] |
|
| 305 | + */ |
|
| 306 | 306 | public function getLinesByVariable(string $name) : array |
| 307 | 307 | { |
| 308 | 308 | $result = array(); |
@@ -81,15 +81,15 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | $result = array(); |
| 83 | 83 | |
| 84 | - foreach($this->lines as $line) |
|
| 84 | + foreach ($this->lines as $line) |
|
| 85 | 85 | { |
| 86 | - if(!$line->isValue()) { |
|
| 86 | + if (!$line->isValue()) { |
|
| 87 | 87 | continue; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | $name = $line->getVarName(); |
| 91 | 91 | |
| 92 | - if(!isset($result[$name])) |
|
| 92 | + if (!isset($result[$name])) |
|
| 93 | 93 | { |
| 94 | 94 | $result[$name] = $line->getVarValue(); |
| 95 | 95 | continue; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | // name exists in collection? Then this is a |
| 99 | 99 | // duplicate key, and we need to convert it to |
| 100 | 100 | // an indexed array of values. |
| 101 | - if(!is_array($result[$name])) |
|
| 101 | + if (!is_array($result[$name])) |
|
| 102 | 102 | { |
| 103 | 103 | $result[$name] = array($result[$name]); |
| 104 | 104 | } |
@@ -118,15 +118,15 @@ discard block |
||
| 118 | 118 | public function toString() : string |
| 119 | 119 | { |
| 120 | 120 | $lines = array(); |
| 121 | - if(!$this->isDefault()) |
|
| 121 | + if (!$this->isDefault()) |
|
| 122 | 122 | { |
| 123 | 123 | $lines[] = '['.$this->getName().']'; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - foreach($this->lines as $line) |
|
| 126 | + foreach ($this->lines as $line) |
|
| 127 | 127 | { |
| 128 | 128 | // we already did this |
| 129 | - if($line->isSection()) { |
|
| 129 | + if ($line->isSection()) { |
|
| 130 | 130 | continue; |
| 131 | 131 | } |
| 132 | 132 | |
@@ -146,9 +146,9 @@ discard block |
||
| 146 | 146 | { |
| 147 | 147 | $keep = array(); |
| 148 | 148 | |
| 149 | - foreach($this->lines as $line) |
|
| 149 | + foreach ($this->lines as $line) |
|
| 150 | 150 | { |
| 151 | - if($line !== $toDelete) { |
|
| 151 | + if ($line !== $toDelete) { |
|
| 152 | 152 | $keep[] = $line; |
| 153 | 153 | } |
| 154 | 154 | } |
@@ -174,23 +174,23 @@ discard block |
||
| 174 | 174 | // Removes any superfluous values that may |
| 175 | 175 | // already exist, if there are more than the |
| 176 | 176 | // new set of values. |
| 177 | - if(is_array($value)) |
|
| 177 | + if (is_array($value)) |
|
| 178 | 178 | { |
| 179 | 179 | $values = array_values($value); |
| 180 | 180 | $amountNew = count($values); |
| 181 | 181 | $amountExisting = count($lines); |
| 182 | 182 | |
| 183 | 183 | $max = $amountNew; |
| 184 | - if($amountExisting > $max) { |
|
| 184 | + if ($amountExisting > $max) { |
|
| 185 | 185 | $max = $amountExisting; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - for($i=0; $i < $max; $i++) |
|
| 188 | + for ($i = 0; $i < $max; $i++) |
|
| 189 | 189 | { |
| 190 | 190 | // new value exists |
| 191 | - if(isset($values[$i])) |
|
| 191 | + if (isset($values[$i])) |
|
| 192 | 192 | { |
| 193 | - if(isset($lines[$i])) { |
|
| 193 | + if (isset($lines[$i])) { |
|
| 194 | 194 | $lines[$i]->setValue($values[$i]); |
| 195 | 195 | } else { |
| 196 | 196 | $this->addValueLine($name, $values[$i]); |
@@ -208,12 +208,12 @@ discard block |
||
| 208 | 208 | else |
| 209 | 209 | { |
| 210 | 210 | // remove all superfluous lines |
| 211 | - if(!empty($lines)) |
|
| 211 | + if (!empty($lines)) |
|
| 212 | 212 | { |
| 213 | 213 | $line = array_shift($lines); // keep only the first line |
| 214 | 214 | $line->setValue($value); |
| 215 | 215 | |
| 216 | - foreach($lines as $delete) { |
|
| 216 | + foreach ($lines as $delete) { |
|
| 217 | 217 | $this->deleteLine($delete); |
| 218 | 218 | } |
| 219 | 219 | } |
@@ -238,11 +238,11 @@ discard block |
||
| 238 | 238 | public function addValue(string $name, $value) : IniHelper_Section |
| 239 | 239 | { |
| 240 | 240 | // array value? Treat it as duplicate keys. |
| 241 | - if(is_array($value)) |
|
| 241 | + if (is_array($value)) |
|
| 242 | 242 | { |
| 243 | 243 | $values = array_values($value); |
| 244 | 244 | |
| 245 | - foreach($values as $setValue) |
|
| 245 | + foreach ($values as $setValue) |
|
| 246 | 246 | { |
| 247 | 247 | $this->addValue($name, $setValue); |
| 248 | 248 | } |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | $lines = $this->getLinesByVariable($name); |
| 254 | 254 | |
| 255 | - if(empty($lines)) |
|
| 255 | + if (empty($lines)) |
|
| 256 | 256 | { |
| 257 | 257 | $this->addValueLine($name, $value); |
| 258 | 258 | } |
@@ -260,15 +260,15 @@ discard block |
||
| 260 | 260 | { |
| 261 | 261 | $found = false; |
| 262 | 262 | |
| 263 | - foreach($lines as $line) |
|
| 263 | + foreach ($lines as $line) |
|
| 264 | 264 | { |
| 265 | - if($line->getVarValue() === $value) { |
|
| 265 | + if ($line->getVarValue() === $value) { |
|
| 266 | 266 | $found = $line; |
| 267 | 267 | break; |
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - if(!$found) |
|
| 271 | + if (!$found) |
|
| 272 | 272 | { |
| 273 | 273 | $this->addValueLine($name, $value); |
| 274 | 274 | } |
@@ -307,9 +307,9 @@ discard block |
||
| 307 | 307 | { |
| 308 | 308 | $result = array(); |
| 309 | 309 | |
| 310 | - foreach($this->lines as $line) |
|
| 310 | + foreach ($this->lines as $line) |
|
| 311 | 311 | { |
| 312 | - if($line->isValue() && $line->getVarName() === $name) { |
|
| 312 | + if ($line->isValue() && $line->getVarName() === $name) { |
|
| 313 | 313 | $result[] = $line; |
| 314 | 314 | } |
| 315 | 315 | } |
@@ -27,9 +27,9 @@ |
||
| 27 | 27 | protected RequestParam $param; |
| 28 | 28 | protected bool $isSubvalue = false; |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var mixed|NULL |
|
| 32 | - */ |
|
| 30 | + /** |
|
| 31 | + * @var mixed|NULL |
|
| 32 | + */ |
|
| 33 | 33 | protected $value; |
| 34 | 34 | |
| 35 | 35 | public function __construct(RequestParam $param, bool $subval) |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | |
| 21 | 21 | protected function _filter() : string |
| 22 | 22 | { |
| 23 | - if(!is_scalar($this->value)) { |
|
| 23 | + if (!is_scalar($this->value)) { |
|
| 24 | 24 | return ''; |
| 25 | 25 | } |
| 26 | 26 | |
@@ -26,11 +26,11 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | protected function _filter() : array |
| 28 | 28 | { |
| 29 | - if(is_array($this->value)) { |
|
| 29 | + if (is_array($this->value)) { |
|
| 30 | 30 | return $this->value; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - if($this->value === '' || !is_string($this->value)) { |
|
| 33 | + if ($this->value === '' || !is_string($this->value)) { |
|
| 34 | 34 | return array(); |
| 35 | 35 | } |
| 36 | 36 | |
@@ -38,19 +38,19 @@ discard block |
||
| 38 | 38 | $stripEmptyEntries = $this->getBoolOption('stripEmptyEntries'); |
| 39 | 39 | $result = explode(',', $this->value); |
| 40 | 40 | |
| 41 | - if(!$trimEntries && !$stripEmptyEntries) { |
|
| 41 | + if (!$trimEntries && !$stripEmptyEntries) { |
|
| 42 | 42 | return $result; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | $keep = array(); |
| 46 | 46 | |
| 47 | - foreach($result as $entry) |
|
| 47 | + foreach ($result as $entry) |
|
| 48 | 48 | { |
| 49 | - if($trimEntries === true) { |
|
| 49 | + if ($trimEntries === true) { |
|
| 50 | 50 | $entry = trim($entry); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - if($stripEmptyEntries === true && $entry === '') { |
|
| 53 | + if ($stripEmptyEntries === true && $entry === '') { |
|
| 54 | 54 | continue; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | protected function _validate() |
| 34 | 34 | { |
| 35 | - if(in_array($this->value, $this->getArrayOption('values'), true)) { |
|
| 35 | + if (in_array($this->value, $this->getArrayOption('values'), true)) { |
|
| 36 | 36 | return $this->value; |
| 37 | 37 | } |
| 38 | 38 | |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | |
| 31 | 31 | protected function _validate() : ?int |
| 32 | 32 | { |
| 33 | - if(ConvertHelper::isInteger($this->value)) { |
|
| 33 | + if (ConvertHelper::isInteger($this->value)) { |
|
| 34 | 34 | return (int)$this->value; |
| 35 | 35 | } |
| 36 | 36 | |
@@ -27,13 +27,13 @@ |
||
| 27 | 27 | |
| 28 | 28 | protected function _validate() : ?string |
| 29 | 29 | { |
| 30 | - if(!is_scalar($this->value)) { |
|
| 30 | + if (!is_scalar($this->value)) { |
|
| 31 | 31 | return null; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | $value = (string)$this->value; |
| 35 | 35 | |
| 36 | - if(preg_match('/\A[a-zA-Z]+\z/', $value)) { |
|
| 36 | + if (preg_match('/\A[a-zA-Z]+\z/', $value)) { |
|
| 37 | 37 | return $value; |
| 38 | 38 | } |
| 39 | 39 | |