Skip to content

Commit 07176c4

Browse files
Merge pull request #18933 from kamil-tekiela/type-hint-in-events-getDetails
Add type hints in Events::getDetails
2 parents 3c4fccf + ed51a8b commit 07176c4

4 files changed

Lines changed: 20 additions & 54 deletions

File tree

phpstan-baseline.neon

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,19 +1775,14 @@ parameters:
17751775
count: 1
17761776
path: src/Controllers/Database/DesignerController.php
17771777

1778-
-
1779-
message: "#^Cannot access offset 'name' on mixed\\.$#"
1780-
count: 1
1781-
path: src/Controllers/Database/EventsController.php
1782-
17831778
-
17841779
message: "#^Cannot call method isSuccess\\(\\) on mixed\\.$#"
17851780
count: 1
17861781
path: src/Controllers/Database/EventsController.php
17871782

17881783
-
17891784
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
1790-
count: 18
1785+
count: 16
17911786
path: src/Controllers/Database/EventsController.php
17921787

17931788
-
@@ -1797,7 +1792,7 @@ parameters:
17971792

17981793
-
17991794
message: "#^Parameter \\#1 \\$identifier of static method PhpMyAdmin\\\\Util\\:\\:backquote\\(\\) expects string\\|Stringable\\|null, mixed given\\.$#"
1800-
count: 3
1795+
count: 2
18011796
path: src/Controllers/Database/EventsController.php
18021797

18031798
-
@@ -6935,21 +6930,6 @@ parameters:
69356930
count: 6
69366931
path: src/Database/Events.php
69376932

6938-
-
6939-
message: "#^Cannot access offset 'Name' on mixed\\.$#"
6940-
count: 1
6941-
path: src/Database/Events.php
6942-
6943-
-
6944-
message: "#^Cannot access offset 'Status' on mixed\\.$#"
6945-
count: 1
6946-
path: src/Database/Events.php
6947-
6948-
-
6949-
message: "#^Cannot access offset 'Type' on mixed\\.$#"
6950-
count: 1
6951-
path: src/Database/Events.php
6952-
69536933
-
69546934
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
69556935
count: 13

psalm-baseline.xml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,16 +1024,9 @@
10241024
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
10251025
<code><![CDATA[$GLOBALS['errors']]]></code>
10261026
</InvalidArrayOffset>
1027-
<MixedArgument>
1028-
<code><![CDATA[$event['name']]]></code>
1029-
</MixedArgument>
1030-
<MixedArrayAccess>
1031-
<code><![CDATA[$event['name']]]></code>
1032-
</MixedArrayAccess>
10331027
<MixedAssignment>
10341028
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
10351029
<code><![CDATA[$GLOBALS['errors']]]></code>
1036-
<code>$event</code>
10371030
<code><![CDATA[$item['item_original_name']]]></code>
10381031
</MixedAssignment>
10391032
<PossiblyInvalidArgument>
@@ -4778,11 +4771,6 @@
47784771
<MixedArgument>
47794772
<code><![CDATA[$GLOBALS['errors']]]></code>
47804773
</MixedArgument>
4781-
<MixedArrayAccess>
4782-
<code><![CDATA[$event['Name']]]></code>
4783-
<code><![CDATA[$event['Status']]]></code>
4784-
<code><![CDATA[$event['Type']]]></code>
4785-
</MixedArrayAccess>
47864774
<MixedArrayAssignment>
47874775
<code><![CDATA[$GLOBALS['errors'][]]]></code>
47884776
<code><![CDATA[$GLOBALS['errors'][]]]></code>
@@ -4796,7 +4784,6 @@
47964784
</MixedArrayAssignment>
47974785
<MixedAssignment>
47984786
<code><![CDATA[$GLOBALS['errors']]]></code>
4799-
<code>$event</code>
48004787
<code><![CDATA[$retval['item_comment']]]></code>
48014788
<code><![CDATA[$retval['item_definer']]]></code>
48024789
<code><![CDATA[$retval['item_definition']]]></code>

src/Controllers/Database/EventsController.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,23 @@ public function __invoke(ServerRequest $request): void
8686
mb_strtoupper($_POST['item_name']),
8787
),
8888
);
89-
if (! empty($event)) {
90-
$sqlDrop = sprintf(
91-
'DROP EVENT IF EXISTS %s',
92-
Util::backquote($event['name']),
93-
);
94-
$this->response->addJSON(
95-
'new_row',
96-
$this->template->render('database/events/row', [
97-
'db' => Current::$database,
98-
'table' => Current::$table,
99-
'event' => $event,
100-
'has_privilege' => Util::currentUserHasPrivilege('EVENT', Current::$database),
101-
'sql_drop' => $sqlDrop,
102-
'row_class' => '',
103-
]),
104-
);
105-
}
89+
$sqlDrop = sprintf(
90+
'DROP EVENT IF EXISTS %s',
91+
Util::backquote($event['name']),
92+
);
93+
$this->response->addJSON(
94+
'new_row',
95+
$this->template->render('database/events/row', [
96+
'db' => Current::$database,
97+
'table' => Current::$table,
98+
'event' => $event,
99+
'has_privilege' => Util::currentUserHasPrivilege('EVENT', Current::$database),
100+
'sql_drop' => $sqlDrop,
101+
'row_class' => '',
102+
]),
103+
);
106104

107-
$this->response->addJSON('insert', ! empty($event));
105+
$this->response->addJSON('insert', true);
108106
$this->response->addJSON('message', $output);
109107
} else {
110108
$this->response->setRequestStatus(false);

src/Database/Events.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ private function checkResult(string|null $createStatement, array $errors): array
362362
* @param string $db db name
363363
* @param string $name event name
364364
*
365-
* @return mixed[] information about EVENTs
365+
* @return array{name:string, type:string, status:string}[] information about EVENTs
366366
*/
367367
public function getDetails(string $db, string $name = ''): array
368368
{
@@ -381,6 +381,7 @@ public function getDetails(string $db, string $name = ''): array
381381
$result = [];
382382
$events = $this->dbi->fetchResult($query);
383383

384+
/** @var string[] $event */
384385
foreach ($events as $event) {
385386
$result[] = ['name' => $event['Name'], 'type' => $event['Type'], 'status' => $event['Status']];
386387
}

0 commit comments

Comments
 (0)