Skip to content

Commit 78be90b

Browse files
Merge pull request #18418 from kamil-tekiela/strlen
Remove strlen in boolean conditions
2 parents 1a549b9 + c13f68c commit 78be90b

8 files changed

Lines changed: 9 additions & 16 deletions

File tree

libraries/classes/Config/Settings.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use function is_string;
2323
use function min;
2424
use function sprintf;
25-
use function strlen;
2625

2726
use const DIRECTORY_SEPARATOR;
2827
use const ROOT_PATH;
@@ -3155,7 +3154,7 @@ private function setMysqlSslWarningSafeHosts(array $settings): array
31553154
/** @var mixed $host */
31563155
foreach ($settings['MysqlSslWarningSafeHosts'] as $host) {
31573156
$safeHost = (string) $host;
3158-
if (strlen($safeHost) === 0) {
3157+
if ($safeHost === '') {
31593158
continue;
31603159
}
31613160

libraries/classes/CreateAddField.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use function json_decode;
1515
use function min;
1616
use function preg_replace;
17-
use function strlen;
1817
use function trim;
1918

2019
/**
@@ -62,8 +61,7 @@ private function buildColumnCreationStatement(
6261
$definitions = [];
6362
$previousField = -1;
6463
for ($i = 0; $i < $fieldCount; ++$i) {
65-
// '0' is also empty for php :-(
66-
if (strlen($_POST['field_name'][$i]) === 0) {
64+
if ($_POST['field_name'][$i] === '') {
6765
continue;
6866
}
6967

libraries/classes/DatabaseInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
use function str_contains;
4949
use function str_starts_with;
5050
use function stripos;
51-
use function strlen;
5251
use function strtolower;
5352
use function strtoupper;
5453
use function strtr;
@@ -1795,7 +1794,7 @@ public function getFieldsMeta(ResultInterface $result): array
17951794
*/
17961795
foreach ($fields as $value) {
17971796
if (
1798-
strlen($value->orgtable) === 0 ||
1797+
$value->orgtable === '' ||
17991798
mb_strtolower($value->orgtable) !== mb_strtolower($value->table)
18001799
) {
18011800
continue;

libraries/classes/InsertEdit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ public function getGotoInclude(string|false $gotoInclude): string
960960
}
961961

962962
if (! $gotoInclude) {
963-
if (strlen($GLOBALS['table']) === 0) {
963+
if ($GLOBALS['table'] === '') {
964964
$gotoInclude = '/database/sql';
965965
} else {
966966
$gotoInclude = '/table/sql';

libraries/classes/Plugins/TwoFactorPlugin.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use function is_array;
1717
use function parse_url;
1818
use function sprintf;
19-
use function strlen;
2019

2120
/**
2221
* Two factor authentication plugin class
@@ -138,11 +137,11 @@ public function getAppId(bool $returnUrl): string
138137
}
139138
}
140139

141-
if (! isset($parsed['scheme']) || strlen($parsed['scheme']) === 0) {
140+
if (! isset($parsed['scheme']) || $parsed['scheme'] === '') {
142141
$parsed['scheme'] = $GLOBALS['config']->isHttps() ? 'https' : 'http';
143142
}
144143

145-
if (! isset($parsed['host']) || strlen($parsed['host']) === 0) {
144+
if (! isset($parsed['host']) || $parsed['host'] === '') {
146145
$parsed['host'] = Core::getenv('HTTP_HOST');
147146
}
148147

libraries/classes/Server/Status/Processes.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use function __;
1212
use function array_change_key_case;
1313
use function count;
14-
use function strlen;
1514

1615
use const CASE_LOWER;
1716

@@ -59,7 +58,7 @@ public function getList(bool $showExecuting, bool $showFullSql, string $orderByF
5958
'id' => $process['id'],
6059
'user' => $process['user'],
6160
'host' => $process['host'],
62-
'db' => ! isset($process['db']) || strlen($process['db']) === 0 ? '' : $process['db'],
61+
'db' => $process['db'] ?? '',
6362
'command' => $process['command'],
6463
'time' => $process['time'],
6564
'state' => ! empty($process['state']) ? $process['state'] : '---',

libraries/classes/UserPassword.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function setChangePasswordMsg(string $pmaPw, string $pmaPw2, bool $skipPa
3535
$message = Message::success(__('The profile has been updated.'));
3636

3737
if ($skipPassword === false) {
38-
if (strlen($pmaPw) === 0 || strlen($pmaPw2) === 0) {
38+
if ($pmaPw === '' || $pmaPw2 === '') {
3939
$message = Message::error(__('The password is empty!'));
4040
$error = true;
4141
} elseif ($pmaPw !== $pmaPw2) {

psalm-baseline.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4591,6 +4591,7 @@
45914591
</DeprecatedMethod>
45924592
<MixedArgument>
45934593
<code><![CDATA[$_POST['field_name'][$column['col_index']]]]></code>
4594+
<code><![CDATA[$_POST['field_name'][$i]]]></code>
45944595
<code>$fieldPrimary[0]</code>
45954596
<code>$index</code>
45964597
<code>$index</code>
@@ -4664,8 +4665,6 @@
46644665
<code><![CDATA[$_POST['field_length'][$i]]]></code>
46654666
<code><![CDATA[$_POST['field_name']]]></code>
46664667
<code><![CDATA[$_POST['field_name'][$column['col_index']]]]></code>
4667-
<code><![CDATA[$_POST['field_name'][$i]]]></code>
4668-
<code><![CDATA[$_POST['field_name'][$i]]]></code>
46694668
<code><![CDATA[$_POST['field_name'][$previousField]]]></code>
46704669
<code><![CDATA[$_POST['field_null'][$i] ?? 'NO']]></code>
46714670
<code><![CDATA[$_POST['field_type'][$i]]]></code>

0 commit comments

Comments
 (0)