Skip to content

Commit 0f57dff

Browse files
Merge pull request #17800 from kamil-tekiela/Fix-phpstan-issues-2
Fix PHPStan issues 2
2 parents 0216137 + 746dbc5 commit 0f57dff

15 files changed

Lines changed: 119 additions & 250 deletions

libraries/classes/Controllers/Database/DesignerController.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public function __invoke(ServerRequest $request): void
4646
$GLOBALS['success'] = $GLOBALS['success'] ?? null;
4747
$GLOBALS['page'] = $GLOBALS['page'] ?? null;
4848
$GLOBALS['message'] = $GLOBALS['message'] ?? null;
49-
$GLOBALS['display_page'] = $GLOBALS['display_page'] ?? null;
5049
$GLOBALS['selected_page'] = $GLOBALS['selected_page'] ?? null;
5150
$GLOBALS['tab_pos'] = $GLOBALS['tab_pos'] ?? null;
5251
$GLOBALS['fullTableNames'] = $GLOBALS['fullTableNames'] ?? null;
@@ -174,24 +173,23 @@ public function __invoke(ServerRequest $request): void
174173

175174
$GLOBALS['script_display_field'] = $this->designerCommon->getTablesInfo();
176175

177-
$GLOBALS['display_page'] = -1;
178176
$GLOBALS['selected_page'] = null;
179177

180178
$visualBuilderMode = isset($_GET['query']);
181179

182180
if ($visualBuilderMode) {
183-
$GLOBALS['display_page'] = $this->designerCommon->getDefaultPage($_GET['db']);
181+
$displayPage = $this->designerCommon->getDefaultPage($_GET['db']);
184182
} elseif (! empty($_GET['page'])) {
185-
$GLOBALS['display_page'] = $_GET['page'];
183+
$displayPage = (int) $_GET['page'];
186184
} else {
187-
$GLOBALS['display_page'] = $this->designerCommon->getLoadingPage($_GET['db']);
185+
$displayPage = $this->designerCommon->getLoadingPage($_GET['db']);
188186
}
189187

190-
if ($GLOBALS['display_page'] != -1) {
191-
$GLOBALS['selected_page'] = $this->designerCommon->getPageName($GLOBALS['display_page']);
188+
if ($displayPage != -1) {
189+
$GLOBALS['selected_page'] = $this->designerCommon->getPageName($displayPage);
192190
}
193191

194-
$GLOBALS['tab_pos'] = $this->designerCommon->getTablePositions($GLOBALS['display_page']);
192+
$GLOBALS['tab_pos'] = $this->designerCommon->getTablePositions($displayPage);
195193

196194
$GLOBALS['fullTableNames'] = [];
197195

@@ -258,7 +256,7 @@ public function __invoke(ServerRequest $request): void
258256
$GLOBALS['script_tables'],
259257
$GLOBALS['script_contr'],
260258
$GLOBALS['script_display_field'],
261-
$GLOBALS['display_page'],
259+
$displayPage,
262260
$visualBuilderMode,
263261
$GLOBALS['selected_page'],
264262
$GLOBALS['classes_side_menu'],

libraries/classes/Controllers/Table/SearchController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function getDataRowAction(): void
225225
$i = 0;
226226
foreach ($row as $col => $val) {
227227
if (isset($fields_meta[$i]) && $fields_meta[$i]->isMappedTypeBit) {
228-
$row[$col] = Util::printableBitValue((int) $val, (int) $fields_meta[$i]->length);
228+
$row[$col] = Util::printableBitValue((int) $val, $fields_meta[$i]->length);
229229
}
230230

231231
$i++;

libraries/classes/Controllers/Table/ZoomSearchController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function getDataRowAction(): void
284284
$i = 0;
285285
foreach ($row as $col => $val) {
286286
if ($fields_meta[$i]->isMappedTypeBit) {
287-
$row[$col] = Util::printableBitValue((int) $val, (int) $fields_meta[$i]->length);
287+
$row[$col] = Util::printableBitValue((int) $val, $fields_meta[$i]->length);
288288
}
289289

290290
$i++;

libraries/classes/Database/CentralColumns.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ public function getFromTable(
557557
bool $allFields = false
558558
): array {
559559
$cfgCentralColumns = $this->getParams();
560-
if (empty($cfgCentralColumns)) {
560+
if ($cfgCentralColumns === false || $cfgCentralColumns === []) {
561561
return [];
562562
}
563563

@@ -569,12 +569,8 @@ public function getFromTable(
569569
}
570570

571571
$cols = trim($cols, ',');
572-
$has_list = $this->findExistingColNames($db, $cols, $allFields);
573-
if (! empty($has_list)) {
574-
return (array) $has_list;
575-
}
576572

577-
return [];
573+
return $this->findExistingColNames($db, $cols, $allFields);
578574
}
579575

580576
/**
@@ -763,7 +759,7 @@ public function getListRaw(string $db, string $table): array
763759
}
764760

765761
$centralTable = $cfgCentralColumns['table'];
766-
if (empty($table) || $table == '') {
762+
if ($table === '') {
767763
$query = 'SELECT * FROM ' . Util::backquote($centralTable) . ' '
768764
. 'WHERE db_name = \'' . $this->dbi->escapeString($db) . '\';';
769765
} else {

libraries/classes/Database/Designer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public function getHtmlForMain(
326326
array $scriptTables,
327327
array $scriptContr,
328328
array $scriptDisplayField,
329-
$displayPage,
329+
int $displayPage,
330330
bool $visualBuilderMode,
331331
$selectedPage,
332332
array $paramsArray,
@@ -386,15 +386,15 @@ public function getHtmlForMain(
386386
$designerConfig->scriptContr = $scriptContr;
387387
$designerConfig->server = $GLOBALS['server'];
388388
$designerConfig->scriptDisplayField = $displayedFields;
389-
$designerConfig->displayPage = (int) $displayPage;
389+
$designerConfig->displayPage = $displayPage;
390390
$designerConfig->tablesEnabled = $relationParameters->pdfFeature !== null;
391391

392392
return $this->template->render('database/designer/main', [
393393
'db' => $db,
394394
'text_dir' => $GLOBALS['text_dir'],
395395
'get_db' => $getDb,
396396
'designer_config' => json_encode($designerConfig),
397-
'display_page' => (int) $displayPage,
397+
'display_page' => $displayPage,
398398
'has_query' => $visualBuilderMode,
399399
'visual_builder' => $visualBuilderMode,
400400
'selected_page' => $selectedPage,

libraries/classes/Database/Designer/Common.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public function getScriptTabs(array $designerTables): array
266266
*
267267
* @return array|null of table positions
268268
*/
269-
public function getTablePositions($pg): ?array
269+
public function getTablePositions(int $pg): ?array
270270
{
271271
$pdfFeature = $this->relation->getRelationParameters()->pdfFeature;
272272
if ($pdfFeature === null) {
@@ -299,7 +299,7 @@ public function getTablePositions($pg): ?array
299299
*
300300
* @return string|null table name
301301
*/
302-
public function getPageName($pg)
302+
public function getPageName(int $pg)
303303
{
304304
$pdfFeature = $this->relation->getRelationParameters()->pdfFeature;
305305
if ($pdfFeature === null) {
@@ -351,9 +351,9 @@ public function deletePage($pg): bool
351351
*
352352
* @param string $db database
353353
*
354-
* @return int|null id of the default pdf page for the database
354+
* @return int id of the default pdf page for the database
355355
*/
356-
public function getDefaultPage($db): ?int
356+
public function getDefaultPage($db): int
357357
{
358358
$pdfFeature = $this->relation->getRelationParameters()->pdfFeature;
359359
if ($pdfFeature === null) {
@@ -424,7 +424,7 @@ public function getLoadingPage($db)
424424

425425
$default_page_no = $this->getDefaultPage($db);
426426
if ($default_page_no != -1) {
427-
return intval($default_page_no);
427+
return $default_page_no;
428428
}
429429

430430
$query = 'SELECT MIN(`page_nr`)'

libraries/classes/Display/Results.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,9 @@ private function getTableHeadersForColumns(
871871
$displayParams['desc'][] = ' <th '
872872
. 'class="draggable'
873873
. ($conditionField ? ' condition"' : '')
874-
. '" data-column="' . htmlspecialchars((string) $fieldsMeta[$i]->name)
874+
. '" data-column="' . htmlspecialchars($fieldsMeta[$i]->name)
875875
. '"> '
876-
. htmlspecialchars((string) $fieldsMeta[$i]->name)
876+
. htmlspecialchars($fieldsMeta[$i]->name)
877877
. $comments . ' </th>';
878878
}
879879

@@ -3147,7 +3147,7 @@ private function getDataCellForNonNumericColumns(
31473147
}
31483148

31493149
if ($meta->isMappedTypeBit) {
3150-
$displayedColumn = Util::printableBitValue((int) $displayedColumn, (int) $meta->length);
3150+
$displayedColumn = Util::printableBitValue((int) $displayedColumn, $meta->length);
31513151

31523152
// some results of PROCEDURE ANALYSE() are reported as
31533153
// being BINARY but they are quite readable,

libraries/classes/ErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function __destruct()
110110
break;
111111
}
112112

113-
if ((! ($error instanceof Error)) || $error->isDisplayed()) {
113+
if ($error->isDisplayed()) {
114114
continue;
115115
}
116116

libraries/classes/Navigation/NavigationTree.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,8 @@ public function __construct($template, DatabaseInterface $dbi)
215215
*/
216216
private function getNavigationDbPos(): int
217217
{
218-
$retval = 0;
219-
220218
if (strlen($GLOBALS['db'] ?? '') === 0) {
221-
return $retval;
219+
return 0;
222220
}
223221

224222
/**
@@ -379,14 +377,12 @@ private function buildPathPart(array $path, string $type2, int $pos2, string $ty
379377
return false;
380378
}
381379

382-
$retval = $db;
383-
384380
$containers = $this->addDbContainers($db, $type2, $pos2);
385381

386382
array_shift($path); // remove db
387383

388-
if ((count($path) <= 0 || ! array_key_exists($path[0], $containers)) && count($containers) != 1) {
389-
return $retval;
384+
if (($path === [] || ! array_key_exists($path[0], $containers)) && count($containers) != 1) {
385+
return $db;
390386
}
391387

392388
if (count($containers) === 1) {
@@ -398,8 +394,6 @@ private function buildPathPart(array $path, string $type2, int $pos2, string $ty
398394
}
399395
}
400396

401-
$retval = $container;
402-
403397
if (count($container->children) <= 1) {
404398
$dbData = $db->getData($container->realName, $pos2, $this->searchClause2);
405399
foreach ($dbData as $item) {
@@ -441,7 +435,7 @@ private function buildPathPart(array $path, string $type2, int $pos2, string $ty
441435

442436
array_shift($path); // remove container
443437
if (count($path) <= 0) {
444-
return $retval;
438+
return $container;
445439
}
446440

447441
/** @var NodeTable|null $table */
@@ -458,17 +452,22 @@ private function buildPathPart(array $path, string $type2, int $pos2, string $ty
458452

459453
$container->addChild($node);
460454
$table = $container->getChild($path[0], true);
455+
if ($table === null) {
456+
return false;
457+
}
461458
}
462459

463-
$retval = $table ?? false;
464460
$containers = $this->addTableContainers($table, $pos2, $type3, $pos3);
465461
array_shift($path); // remove table
466-
if (count($path) <= 0 || ! array_key_exists($path[0], $containers)) {
467-
return $retval;
462+
if ($path === [] || ! array_key_exists($path[0], $containers)) {
463+
return $table;
468464
}
469465

470466
$container = $table->getChild($path[0], true);
471-
$retval = $container ?? false;
467+
if ($container === null) {
468+
return false;
469+
}
470+
472471
$tableData = $table->getData($container->realName, $pos3);
473472
foreach ($tableData as $item) {
474473
switch ($container->realName) {
@@ -497,7 +496,7 @@ private function buildPathPart(array $path, string $type2, int $pos2, string $ty
497496
$container->addChild($node);
498497
}
499498

500-
return $retval;
499+
return $container;
501500
}
502501

503502
/**
@@ -515,7 +514,7 @@ private function buildPathPart(array $path, string $type2, int $pos2, string $ty
515514
* @param int $pos3 The position for the pagination of
516515
* the branch at the third level of the tree
517516
*
518-
* @return array An array of new nodes
517+
* @return Node[] An array of new nodes
519518
*/
520519
private function addTableContainers(NodeTable $table, int $pos2, string $type3, int $pos3): array
521520
{
@@ -568,7 +567,7 @@ private function addTableContainers(NodeTable $table, int $pos2, string $type3,
568567
* @param int $pos2 The position for the pagination of
569568
* the branch at the second level of the tree
570569
*
571-
* @return array An array of new nodes
570+
* @return Node[] An array of new nodes
572571
*/
573572
private function addDbContainers(NodeDatabase $db, string $type, int $pos2): array
574573
{

libraries/classes/Navigation/Nodes/Node.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ class Node
5858
*/
5959
public $visible = false;
6060
/**
61-
* @var Node A reference to the parent object of
61+
* @var Node|null A reference to the parent object of
6262
* this node, NULL for the root node.
6363
*/
64-
public $parent;
64+
public $parent = null;
6565
/**
6666
* @var Node[] An array of Node objects that are
6767
* direct children of this node
@@ -369,7 +369,7 @@ public function getPaths(): array
369369
*
370370
* @return array
371371
*/
372-
public function getData($type, $pos, $searchClause = '')
372+
public function getData(string $type, int $pos, string $searchClause = ''): array
373373
{
374374
if (isset($GLOBALS['cfg']['Server']['DisableIS']) && ! $GLOBALS['cfg']['Server']['DisableIS']) {
375375
return $this->getDataFromInfoSchema($pos, $searchClause);
@@ -650,7 +650,7 @@ public function getNavigationHidingData()
650650
*
651651
* @return array
652652
*/
653-
private function getDataFromInfoSchema($pos, $searchClause)
653+
private function getDataFromInfoSchema(int $pos, string $searchClause)
654654
{
655655
$maxItems = $GLOBALS['cfg']['FirstLevelNavigationItems'];
656656
if (! $GLOBALS['cfg']['NavigationTreeEnableGrouping'] || ! $GLOBALS['cfg']['ShowDatabasesNavigationAsTree']) {
@@ -687,7 +687,7 @@ private function getDataFromInfoSchema($pos, $searchClause)
687687
*
688688
* @return array
689689
*/
690-
private function getDataFromShowDatabases($pos, $searchClause)
690+
private function getDataFromShowDatabases(int $pos, string $searchClause)
691691
{
692692
$maxItems = $GLOBALS['cfg']['FirstLevelNavigationItems'];
693693
if (! $GLOBALS['cfg']['NavigationTreeEnableGrouping'] || ! $GLOBALS['cfg']['ShowDatabasesNavigationAsTree']) {
@@ -738,7 +738,7 @@ private function getDataFromShowDatabases($pos, $searchClause)
738738
}
739739
}
740740

741-
$prefixes = array_slice(array_keys($prefixMap), (int) $pos);
741+
$prefixes = array_slice(array_keys($prefixMap), $pos);
742742
}
743743

744744
$subClauses = [];
@@ -765,7 +765,7 @@ private function getDataFromShowDatabases($pos, $searchClause)
765765
*
766766
* @return array
767767
*/
768-
private function getDataFromShowDatabasesLike($pos, $searchClause)
768+
private function getDataFromShowDatabasesLike(int $pos, string $searchClause)
769769
{
770770
$maxItems = $GLOBALS['cfg']['FirstLevelNavigationItems'];
771771
if (! $GLOBALS['cfg']['NavigationTreeEnableGrouping'] || ! $GLOBALS['cfg']['ShowDatabasesNavigationAsTree']) {

0 commit comments

Comments
 (0)