Skip to content

Commit ab80bd8

Browse files
committed
Remove trigger_error from Config::checkServers()
Silent removes invalid server keys. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 2801ece commit ab80bd8

3 files changed

Lines changed: 7 additions & 19 deletions

File tree

libraries/classes/Config.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,10 @@
5757
use function substr;
5858
use function sys_get_temp_dir;
5959
use function time;
60-
use function trigger_error;
6160
use function trim;
6261

6362
use const ARRAY_FILTER_USE_KEY;
6463
use const DIRECTORY_SEPARATOR;
65-
use const E_USER_ERROR;
6664
use const PHP_OS;
6765
use const PHP_URL_PATH;
6866
use const PHP_URL_SCHEME;
@@ -1164,10 +1162,7 @@ public function checkServers(): void
11641162
foreach ($this->settings['Servers'] as $server_index => $each_server) {
11651163
// Detect wrong configuration
11661164
if (! is_int($server_index) || $server_index < 1) {
1167-
trigger_error(
1168-
sprintf(__('Invalid server index: %s'), $server_index),
1169-
E_USER_ERROR
1170-
);
1165+
continue;
11711166
}
11721167

11731168
$each_server = array_merge($this->defaultServer, $each_server);

psalm-baseline.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@
291291
<code>$gd_nfo['GD Version']</code>
292292
<code>$path</code>
293293
<code>$server['verbose']</code>
294-
<code>$server_index</code>
295294
<code>$this-&gt;settings['Servers']</code>
296295
<code>$this-&gt;settings['ThemeDefault']</code>
297296
<code>$this-&gt;settings['ThemeDefault']</code>
@@ -16570,10 +16569,6 @@
1657016569
</DeprecatedMethod>
1657116570
</file>
1657216571
<file src="test/classes/ConfigTest.php">
16573-
<DeprecatedMethod>
16574-
<code>expectError</code>
16575-
<code>expectErrorMessage</code>
16576-
</DeprecatedMethod>
1657716572
<InvalidArgument>
1657816573
<code>$v</code>
1657916574
</InvalidArgument>

test/classes/ConfigTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,18 +1110,16 @@ public static function serverSettingsProvider(): array
11101110
];
11111111
}
11121112

1113-
/**
1114-
* @group with-trigger-error
1115-
*/
11161113
public function testCheckServersWithInvalidServer(): void
11171114
{
1118-
$this->expectError();
1119-
$this->expectErrorMessage('Invalid server index: invalid');
1120-
1121-
$this->object->settings['Servers'] = ['invalid' => ['host' => '127.0.0.1'], 1 => ['host' => '127.0.0.1']];
1115+
$server = ['host' => '127.0.0.1'];
1116+
$this->object->settings['Servers'] = ['invalid' => $server, 0 => $server, 1 => $server];
11221117
$this->object->checkServers();
1123-
$expected = array_merge($this->object->defaultServer, ['host' => '127.0.0.1']);
1118+
$expected = array_merge($this->object->defaultServer, $server);
11241119

1120+
$this->assertArrayNotHasKey('invalid', $this->object->settings['Servers']);
1121+
$this->assertArrayNotHasKey(0, $this->object->settings['Servers']);
1122+
$this->assertArrayHasKey(1, $this->object->settings['Servers']);
11251123
$this->assertEquals($expected, $this->object->settings['Servers'][1]);
11261124
}
11271125

0 commit comments

Comments
 (0)