Visitar URL original
Improve boolean conditions with arrays (#18417) · phpmyadmin/phpmyadmin@4ec3b99 · GitHub
Skip to content

Commit 4ec3b99

Browse files
Improve boolean conditions with arrays (#18417)
* Remove empty() on array Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Remove boolean count() Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> --------- Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
1 parent 64b0fd5 commit 4ec3b99

45 files changed

Lines changed: 71 additions & 89 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎libraries/classes/Charsets.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
use function __;
1414
use function array_keys;
15-
use function count;
1615
use function explode;
1716
use function is_string;
1817
use function ksort;
@@ -74,7 +73,7 @@ class Charsets
7473
private static function loadCharsets(DatabaseInterface $dbi, bool $disableIs): void
7574
{
7675
/* Data already loaded */
77-
if (count(self::$charsets) > 0) {
76+
if (self::$charsets !== []) {
7877
return;
7978
}
8079

@@ -106,7 +105,7 @@ private static function loadCharsets(DatabaseInterface $dbi, bool $disableIs): v
106105
private static function loadCollations(DatabaseInterface $dbi, bool $disableIs): void
107106
{
108107
/* Data already loaded */
109-
if (count(self::$collations) > 0) {
108+
if (self::$collations !== []) {
110109
return;
111110
}
112111

‎libraries/classes/Charsets/Collation.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use function __;
1111
use function _pgettext;
12-
use function count;
1312
use function explode;
1413
use function implode;
1514

@@ -238,7 +237,7 @@ private function buildName(string $result, string|null $variant, array $suffixes
238237
$result .= ' (' . $variant . ')';
239238
}
240239

241-
if (count($suffixes) > 0) {
240+
if ($suffixes !== []) {
242241
$result .= ', ' . implode(', ', $suffixes);
243242
}
244243

‎libraries/classes/Config/FormDisplay.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use function array_flip;
2424
use function array_keys;
2525
use function array_search;
26-
use function count;
2726
use function explode;
2827
use function function_exists;
2928
use function gettype;
@@ -155,7 +154,7 @@ public function process(bool $allowPartialSave = true, bool $checkFormSubmit = t
155154
}
156155

157156
// save forms
158-
if (count($this->forms) > 0) {
157+
if ($this->forms !== []) {
159158
return $this->save(array_keys($this->forms), $allowPartialSave);
160159
}
161160

@@ -187,7 +186,7 @@ private function validate(): void
187186
$errors = Validator::validate($this->configFile, $paths, $values, false);
188187

189188
// change error keys from canonical paths to work paths
190-
if (is_array($errors) && count($errors) > 0) {
189+
if (is_array($errors) && $errors !== []) {
191190
$this->errors = [];
192191
foreach ($errors as $path => $errorList) {
193192
$workPath = array_search($path, $this->systemPaths);

‎libraries/classes/Config/Settings.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use function __;
1717
use function array_map;
18-
use function count;
1918
use function defined;
2019
use function in_array;
2120
use function is_array;
@@ -3548,7 +3547,7 @@ private function setNavigationTreeTableSeparator(array $settings): false|string|
35483547
return (string) $settings['NavigationTreeTableSeparator'];
35493548
}
35503549

3551-
if (count($settings['NavigationTreeTableSeparator']) > 0) {
3550+
if ($settings['NavigationTreeTableSeparator'] !== []) {
35523551
$navigationTreeTableSeparator = [];
35533552
/** @var mixed $separator */
35543553
foreach ($settings['NavigationTreeTableSeparator'] as $separator) {

‎libraries/classes/Config/Settings/Server.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace PhpMyAdmin\Config\Settings;
66

7-
use function count;
87
use function in_array;
98
use function is_array;
109

@@ -1382,7 +1381,7 @@ private function setOnlyDb(array $server): string|array
13821381
if (isset($server['only_db'])) {
13831382
if (! is_array($server['only_db'])) {
13841383
$onlyDb = (string) $server['only_db'];
1385-
} elseif (count($server['only_db']) > 0) {
1384+
} elseif ($server['only_db'] !== []) {
13861385
$onlyDb = [];
13871386
/** @var mixed $database */
13881387
foreach ($server['only_db'] as $database) {

‎libraries/classes/ConfigStorage/Relation.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,7 @@ public function getRelationsAndStatus(bool $condition, string $db, string $table
16691669
// an array
16701670
$resRel = $this->getForeigners($db, $table);
16711671

1672-
$haveRel = count($resRel) > 0;
1672+
$haveRel = $resRel !== [];
16731673
}
16741674

16751675
return [$resRel, $haveRel];

‎libraries/classes/Controllers/Database/ExportController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function __invoke(ServerRequest $request): void
125125

126126
$exportList = Plugins::getExport($exportType, isset($GLOBALS['single_table']));
127127

128-
if (empty($exportList)) {
128+
if ($exportList === []) {
129129
$this->response->addHTML(Message::error(
130130
__('Could not load export plugins, please check your installation!'),
131131
)->getDisplay());

‎libraries/classes/Controllers/Database/ImportController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __invoke(ServerRequest $request): void
5555

5656
$importList = Plugins::getImport('database');
5757

58-
if (empty($importList)) {
58+
if ($importList === []) {
5959
$this->response->addHTML(Message::error(__(
6060
'Could not load import plugins, please check your installation!',
6161
))->getDisplay());

‎libraries/classes/Controllers/Database/Structure/DropFormController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __invoke(ServerRequest $request): void
4141

4242
foreach ($selected as $selectedValue) {
4343
$current = $selectedValue;
44-
if (! empty($views) && in_array($current, $views)) {
44+
if ($views !== [] && in_array($current, $views)) {
4545
$fullQueryViews .= (empty($fullQueryViews) ? 'DROP VIEW ' : ', ')
4646
. Util::backquote(htmlspecialchars($current));
4747
} else {

‎libraries/classes/Controllers/Database/Structure/DropTableController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __invoke(ServerRequest $request): void
5858
$this->relationCleanup->table($GLOBALS['db'], $selected[$i]);
5959
$current = $selected[$i];
6060

61-
if (! empty($views) && in_array($current, $views)) {
61+
if ($views !== [] && in_array($current, $views)) {
6262
$sqlQueryViews .= (empty($sqlQueryViews) ? 'DROP VIEW ' : ', ') . Util::backquote($current);
6363
} else {
6464
$GLOBALS['sql_query'] .= (empty($GLOBALS['sql_query']) ? 'DROP TABLE ' : ', ')

0 commit comments

Comments
 (0)