Skip to content

Commit de50d36

Browse files
Merge pull request #19753 from MauricioFauth/strict-comparisons
Make some comparisons stricter
2 parents 26d685f + e7765ef commit de50d36

Some content is hidden

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

68 files changed

+296
-587
lines changed

phpstan-baseline.neon

Lines changed: 88 additions & 406 deletions
Large diffs are not rendered by default.

psalm-baseline.xml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@
480480
<DeprecatedMethod>
481481
<code><![CDATA[Config::getInstance()]]></code>
482482
</DeprecatedMethod>
483+
<RiskyTruthyFalsyComparison>
484+
<code><![CDATA[$_REQUEST['printview']]]></code>
485+
</RiskyTruthyFalsyComparison>
483486
</file>
484487
<file src="src/Config/ServerConfigChecks.php">
485488
<MixedAssignment>
@@ -613,6 +616,9 @@
613616
<DeprecatedMethod>
614617
<code><![CDATA[Config::getInstance()]]></code>
615618
</DeprecatedMethod>
619+
<DocblockTypeContradiction>
620+
<code><![CDATA[$foreign[$field] !== '']]></code>
621+
</DocblockTypeContradiction>
616622
<InvalidReturnStatement>
617623
<code><![CDATA[$tableNameReplacements]]></code>
618624
</InvalidReturnStatement>
@@ -660,6 +666,9 @@
660666
<PossiblyUnusedReturnValue>
661667
<code><![CDATA[bool]]></code>
662668
</PossiblyUnusedReturnValue>
669+
<RedundantConditionGivenDocblockType>
670+
<code><![CDATA[isset($foreign[$field]) && $foreign[$field] !== '']]></code>
671+
</RedundantConditionGivenDocblockType>
663672
<RiskyTruthyFalsyComparison>
664673
<code><![CDATA[$relationParams[$work]]]></code>
665674
<code><![CDATA[empty($this->config->selectedServer[$feature])]]></code>
@@ -2933,6 +2942,7 @@
29332942
<code><![CDATA[$_POST['maxPlotLimit']]]></code>
29342943
</RiskyCast>
29352944
<RiskyTruthyFalsyComparison>
2945+
<code><![CDATA[$_POST['get_data_row']]]></code>
29362946
<code><![CDATA[empty($_POST['maxPlotLimit'])]]></code>
29372947
<code><![CDATA[empty($row->collation)]]></code>
29382948
</RiskyTruthyFalsyComparison>
@@ -5887,9 +5897,6 @@
58875897
<code><![CDATA[Config::getInstance()]]></code>
58885898
<code><![CDATA[Config::getInstance()]]></code>
58895899
</DeprecatedMethod>
5890-
<DocblockTypeContradiction>
5891-
<code><![CDATA[$resp == null]]></code>
5892-
</DocblockTypeContradiction>
58935900
<MixedArgument>
58945901
<code><![CDATA[$serverCookie]]></code>
58955902
<code><![CDATA[$serverCookie]]></code>
@@ -7905,6 +7912,9 @@
79057912
<DeprecatedMethod>
79067913
<code><![CDATA[Config::getInstance()]]></code>
79077914
</DeprecatedMethod>
7915+
<RiskyTruthyFalsyComparison>
7916+
<code><![CDATA[$questionPos]]></code>
7917+
</RiskyTruthyFalsyComparison>
79087918
</file>
79097919
<file src="src/Sanitize.php">
79107920
<DeprecatedMethod>
@@ -8124,10 +8134,12 @@
81248134
<code><![CDATA[$row1[0]]]></code>
81258135
</PossiblyUndefinedArrayOffset>
81268136
<RiskyCast>
8137+
<code><![CDATA[$_POST['grant_count']]]></code>
81278138
<code><![CDATA[$_POST['max_connections']]]></code>
81288139
<code><![CDATA[$_POST['max_questions']]]></code>
81298140
<code><![CDATA[$_POST['max_updates']]]></code>
81308141
<code><![CDATA[$_POST['max_user_connections']]]></code>
8142+
<code><![CDATA[$_REQUEST['column_count']]]></code>
81318143
</RiskyCast>
81328144
<RiskyTruthyFalsyComparison>
81338145
<code><![CDATA[empty($_POST[$currentGrant[0] . '_none'])]]></code>
@@ -8402,7 +8414,6 @@
84028414
</MixedArrayAssignment>
84038415
<MixedAssignment>
84048416
<code><![CDATA[$maxRows]]></code>
8405-
<code><![CDATA[$pos]]></code>
84068417
<code><![CDATA[$sortCol]]></code>
84078418
<code><![CDATA[$unlimNumRows]]></code>
84088419
</MixedAssignment>
@@ -8417,8 +8428,6 @@
84178428
<code><![CDATA[$statementInfo->statement->where[0]->expr]]></code>
84188429
</MixedPropertyFetch>
84198430
<MixedReturnStatement>
8420-
<code><![CDATA[$pos]]></code>
8421-
<code><![CDATA[$pos]]></code>
84228431
<code><![CDATA[$unlimNumRows]]></code>
84238432
<code><![CDATA[$unlimNumRows]]></code>
84248433
<code><![CDATA[@((int) ceil($numberOfLine / $maxRows) - 1) * $maxRows]]></code>
@@ -8465,6 +8474,9 @@
84658474
</RedundantCondition>
84668475
<RiskyTruthyFalsyComparison>
84678476
<code><![CDATA[! $index->isUnique()]]></code>
8477+
<code><![CDATA[$_POST['grid_edit']]]></code>
8478+
<code><![CDATA[$_POST['printview']]]></code>
8479+
<code><![CDATA[$_POST['printview']]]></code>
84688480
<code><![CDATA[$table]]></code>
84698481
<code><![CDATA[empty($_GET['id_bookmark'])]]></code>
84708482
<code><![CDATA[empty($_GET['id_bookmark'])]]></code>
@@ -8910,9 +8922,6 @@
89108922
<code><![CDATA[$tokens[0]]]></code>
89118923
<code><![CDATA[$tokens[2]]]></code>
89128924
</PossiblyNullArrayAccess>
8913-
<PossiblyNullOperand>
8914-
<code><![CDATA[$statement]]></code>
8915-
</PossiblyNullOperand>
89168925
<PossiblyNullPropertyFetch>
89178926
<code><![CDATA[$parser->list->tokens]]></code>
89188927
<code><![CDATA[$statement->fields[0]->table]]></code>
@@ -8988,6 +8997,21 @@
89888997
<code><![CDATA[$tableName]]></code>
89898998
<code><![CDATA[$versionNumber]]></code>
89908999
</PossiblyNullArgument>
9000+
<RiskyTruthyFalsyComparison>
9001+
<code><![CDATA[$_POST['alter_table']]]></code>
9002+
<code><![CDATA[$_POST['alter_view']]]></code>
9003+
<code><![CDATA[$_POST['create_index']]]></code>
9004+
<code><![CDATA[$_POST['create_table']]]></code>
9005+
<code><![CDATA[$_POST['create_view']]]></code>
9006+
<code><![CDATA[$_POST['delete']]]></code>
9007+
<code><![CDATA[$_POST['drop_index']]]></code>
9008+
<code><![CDATA[$_POST['drop_table']]]></code>
9009+
<code><![CDATA[$_POST['drop_view']]]></code>
9010+
<code><![CDATA[$_POST['insert']]]></code>
9011+
<code><![CDATA[$_POST['rename_table']]]></code>
9012+
<code><![CDATA[$_POST['truncate']]]></code>
9013+
<code><![CDATA[$_POST['update']]]></code>
9014+
</RiskyTruthyFalsyComparison>
89919015
</file>
89929016
<file src="src/Transformations.php">
89939017
<LessSpecificReturnStatement>

src/Advisory/Advisor.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ public static function byTime(float $num, int $precision): string
396396
}
397397

398398
$num = round($num, $precision);
399-
400-
if ($num == 0) {
399+
if ($num === 0.0) {
401400
$num = '<' . 10 ** (-$precision);
402401
}
403402

src/Config.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function loadUserPreferences(ThemeManager $themeManager, bool $isMinimumC
285285
(! isset($configData['ThemeDefault'])
286286
&& $themeManager->theme->getId() !== 'original')
287287
|| isset($configData['ThemeDefault'])
288-
&& $configData['ThemeDefault'] != $themeManager->theme->getId()
288+
&& $configData['ThemeDefault'] !== $themeManager->theme->getId()
289289
) {
290290
$this->setUserValue(
291291
null,
@@ -295,7 +295,7 @@ public function loadUserPreferences(ThemeManager $themeManager, bool $isMinimumC
295295
);
296296
}
297297
} elseif (
298-
$this->settings['ThemeDefault'] != $themeManager->theme->getId()
298+
$this->settings['ThemeDefault'] !== $themeManager->theme->getId()
299299
&& $themeManager->themeExists($this->settings['ThemeDefault'])
300300
) {
301301
// no cookie - read default from settings
@@ -536,7 +536,7 @@ public function isHttps(): bool
536536
} elseif (Util::getProtoFromForwardedHeader(Core::getEnv('HTTP_FORWARDED')) === 'https') {
537537
// RFC 7239 Forwarded header
538538
$isHttps = true;
539-
} elseif (Core::getEnv('SERVER_PORT') == 443) {
539+
} elseif ((int) Core::getEnv('SERVER_PORT') === 443) {
540540
$isHttps = true;
541541
}
542542

src/Config/ConfigFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public function removeServer(int $server): void
430430

431431
unset($_SESSION[$this->id]['Servers'][$lastServer]);
432432

433-
if (! isset($_SESSION[$this->id]['ServerDefault']) || $_SESSION[$this->id]['ServerDefault'] != $lastServer) {
433+
if (! isset($_SESSION[$this->id]['ServerDefault']) || $_SESSION[$this->id]['ServerDefault'] !== $lastServer) {
434434
return;
435435
}
436436

src/Config/PageSettings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function init(string $formGroupName, string|null $elemId = null): void
5555
return;
5656
}
5757

58-
if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') {
58+
if (isset($_REQUEST['printview']) && $_REQUEST['printview']) {
5959
return;
6060
}
6161

@@ -72,7 +72,7 @@ public function init(string $formGroupName, string|null $elemId = null): void
7272

7373
// Process form
7474
$error = null;
75-
if (isset($_POST['submit_save']) && $_POST['submit_save'] == $formGroupName) {
75+
if (isset($_POST['submit_save']) && $_POST['submit_save'] === $formGroupName) {
7676
$error = $this->processPageSettings($formDisplay, $configFile);
7777
}
7878

src/Config/ServerConfigChecks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ protected function performConfigChecksLoginCookie(): void
351351
// $cfg['LoginCookieStore']
352352
// LoginCookieValidity must be less or equal to LoginCookieStore
353353
if (
354-
$this->cfg->getValue('LoginCookieStore') == 0
354+
$this->cfg->getValue('LoginCookieStore') === 0
355355
|| $loginCookieValidity <= $this->cfg->getValue('LoginCookieStore')
356356
) {
357357
return;

src/ConfigStorage/Relation.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -160,43 +160,43 @@ private function fillRelationParamsWithTableNames(array $relationParams): array|
160160
}
161161

162162
foreach ($tables as $table) {
163-
if ($table == $this->config->selectedServer['bookmarktable']) {
163+
if ($table === $this->config->selectedServer['bookmarktable']) {
164164
$relationParams['bookmark'] = $table;
165-
} elseif ($table == $this->config->selectedServer['relation']) {
165+
} elseif ($table === $this->config->selectedServer['relation']) {
166166
$relationParams['relation'] = $table;
167-
} elseif ($table == $this->config->selectedServer['table_info']) {
167+
} elseif ($table === $this->config->selectedServer['table_info']) {
168168
$relationParams['table_info'] = $table;
169-
} elseif ($table == $this->config->selectedServer['table_coords']) {
169+
} elseif ($table === $this->config->selectedServer['table_coords']) {
170170
$relationParams['table_coords'] = $table;
171-
} elseif ($table == $this->config->selectedServer['column_info']) {
171+
} elseif ($table === $this->config->selectedServer['column_info']) {
172172
$relationParams['column_info'] = $table;
173-
} elseif ($table == $this->config->selectedServer['pdf_pages']) {
173+
} elseif ($table === $this->config->selectedServer['pdf_pages']) {
174174
$relationParams['pdf_pages'] = $table;
175-
} elseif ($table == $this->config->selectedServer['history']) {
175+
} elseif ($table === $this->config->selectedServer['history']) {
176176
$relationParams['history'] = $table;
177-
} elseif ($table == $this->config->selectedServer['recent']) {
177+
} elseif ($table === $this->config->selectedServer['recent']) {
178178
$relationParams['recent'] = $table;
179-
} elseif ($table == $this->config->selectedServer['favorite']) {
179+
} elseif ($table === $this->config->selectedServer['favorite']) {
180180
$relationParams['favorite'] = $table;
181-
} elseif ($table == $this->config->selectedServer['table_uiprefs']) {
181+
} elseif ($table === $this->config->selectedServer['table_uiprefs']) {
182182
$relationParams['table_uiprefs'] = $table;
183-
} elseif ($table == $this->config->selectedServer['tracking']) {
183+
} elseif ($table === $this->config->selectedServer['tracking']) {
184184
$relationParams['tracking'] = $table;
185-
} elseif ($table == $this->config->selectedServer['userconfig']) {
185+
} elseif ($table === $this->config->selectedServer['userconfig']) {
186186
$relationParams['userconfig'] = $table;
187-
} elseif ($table == $this->config->selectedServer['users']) {
187+
} elseif ($table === $this->config->selectedServer['users']) {
188188
$relationParams['users'] = $table;
189-
} elseif ($table == $this->config->selectedServer['usergroups']) {
189+
} elseif ($table === $this->config->selectedServer['usergroups']) {
190190
$relationParams['usergroups'] = $table;
191-
} elseif ($table == $this->config->selectedServer['navigationhiding']) {
191+
} elseif ($table === $this->config->selectedServer['navigationhiding']) {
192192
$relationParams['navigationhiding'] = $table;
193-
} elseif ($table == $this->config->selectedServer['savedsearches']) {
193+
} elseif ($table === $this->config->selectedServer['savedsearches']) {
194194
$relationParams['savedsearches'] = $table;
195-
} elseif ($table == $this->config->selectedServer['central_columns']) {
195+
} elseif ($table === $this->config->selectedServer['central_columns']) {
196196
$relationParams['central_columns'] = $table;
197-
} elseif ($table == $this->config->selectedServer['designer_settings']) {
197+
} elseif ($table === $this->config->selectedServer['designer_settings']) {
198198
$relationParams['designer_settings'] = $table;
199-
} elseif ($table == $this->config->selectedServer['export_templates']) {
199+
} elseif ($table === $this->config->selectedServer['export_templates']) {
200200
$relationParams['export_templates'] = $table;
201201
}
202202
}
@@ -421,7 +421,7 @@ public function getForeignersInternal(string $db, string $table, string $column
421421
foreach ($internalRelations[$table] as $field => $relations) {
422422
if (
423423
($column !== '' && $column !== $field)
424-
|| (isset($foreign[$field]) && $foreign[$field] != '')
424+
|| (isset($foreign[$field]) && $foreign[$field] !== '')
425425
) {
426426
continue;
427427
}
@@ -750,7 +750,7 @@ public function foreignDropdown(
750750
// beginning of dropdown
751751
$ret = '<option value="">&nbsp;</option>';
752752
$topCount = count($top);
753-
if ($max == -1 || $topCount < $max) {
753+
if ($max === -1 || $topCount < $max) {
754754
$ret .= implode('', $top);
755755
if ($foreignDisplay && $topCount > 0) {
756756
// this empty option is to visually mark the beginning of the
@@ -796,7 +796,7 @@ public function getForeignData(
796796
}
797797

798798
$foreigner = $this->searchColumnInForeigners($foreigners, $field);
799-
if ($foreigner == false) {
799+
if ($foreigner === false || $foreigner === []) {
800800
break;
801801
}
802802

src/Controllers/Database/DesignerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function __invoke(ServerRequest $request): Response
189189
}
190190

191191
$selectedPage = null;
192-
if ($displayPage != -1) {
192+
if ($displayPage !== -1) {
193193
$selectedPage = $this->designerCommon->getPageName($displayPage);
194194
}
195195

src/Controllers/Database/Structure/FavoriteTableController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function __invoke(ServerRequest $request): Response
8080
} elseif (isset($_REQUEST['add_favorite'])) {
8181
if (! $alreadyFavorite) {
8282
$numTables = count($favoriteInstance->getTables());
83-
if ($numTables == $this->config->settings['NumFavoriteTables']) {
83+
if ($numTables === $this->config->settings['NumFavoriteTables']) {
8484
$changes = false;
8585
} else {
8686
// Otherwise add to favorite list.

0 commit comments

Comments
 (0)