Skip to content

Commit 917c7a1

Browse files
Merge pull request #18959 from kamil-tekiela/Refactor-getPageIdsAndNames
Refactor getPageIdsAndNames()
2 parents 45b5577 + 3da0bf8 commit 917c7a1

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

src/Database/Designer.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use stdClass;
1818

1919
use function __;
20-
use function intval;
2120
use function is_array;
2221
use function json_decode;
2322
use function str_contains;
@@ -74,7 +73,7 @@ public function getHtmlForPageSaveAs(string $db): string
7473
*
7574
* @param string $db database name
7675
*
77-
* @return mixed[] array of schema page id and names
76+
* @return array<string|null> array of schema page id and names
7877
*/
7978
private function getPageIdsAndNames(string $db): array
8079
{
@@ -94,12 +93,7 @@ private function getPageIdsAndNames(string $db): array
9493
return [];
9594
}
9695

97-
$result = [];
98-
while ($currPage = $pageRs->fetchAssoc()) {
99-
$result[intval($currPage['page_nr'])] = $currPage['page_descr'];
100-
}
101-
102-
return $result;
96+
return $pageRs->fetchAllKeyPair();
10397
}
10498

10599
/**

tests/classes/Database/DesignerTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,12 @@ private function mockDatabaseInteraction(string $db): void
6868
)
6969
->willReturn($resultStub);
7070

71-
$resultStub->expects($this->exactly(3))
72-
->method('fetchAssoc')
73-
->willReturn(
74-
['page_nr' => '1', 'page_descr' => 'page1'],
75-
['page_nr' => '2', 'page_descr' => 'page2'],
76-
[],
77-
);
71+
$resultStub->expects($this->exactly(1))
72+
->method('fetchAllKeyPair')
73+
->willReturn([
74+
'1' => 'page1',
75+
'2' => 'page2',
76+
]);
7877

7978
$dbi->expects($this->any())->method('quoteString')
8079
->willReturnCallback(static fn (string $string): string => "'" . $string . "'");

0 commit comments

Comments
 (0)