Skip to content

Commit f900fce

Browse files
Merge pull request #18934 from kamil-tekiela/Refactor-Routines-getDetails
Refactor Routines::getDetails()
2 parents 07176c4 + bd79b27 commit f900fce

7 files changed

Lines changed: 52 additions & 114 deletions

File tree

phpstan-baseline.neon

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ parameters:
19171917

19181918
-
19191919
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
1920-
count: 24
1920+
count: 23
19211921
path: src/Controllers/Database/RoutinesController.php
19221922

19231923
-
@@ -1935,11 +1935,6 @@ parameters:
19351935
count: 1
19361936
path: src/Controllers/Database/RoutinesController.php
19371937

1938-
-
1939-
message: "#^Parameter \\#1 \\$routine of method PhpMyAdmin\\\\Database\\\\Routines\\:\\:getRow\\(\\) expects array, mixed given\\.$#"
1940-
count: 2
1941-
path: src/Controllers/Database/RoutinesController.php
1942-
19431938
-
19441939
message: "#^Parameter \\#1 \\$string of function htmlentities expects string, mixed given\\.$#"
19451940
count: 3
@@ -6995,31 +6990,6 @@ parameters:
69956990
count: 9
69966991
path: src/Database/Routines.php
69976992

6998-
-
6999-
message: "#^Cannot access offset 'DTD_IDENTIFIER' on mixed\\.$#"
7000-
count: 1
7001-
path: src/Database/Routines.php
7002-
7003-
-
7004-
message: "#^Cannot access offset 'Db' on mixed\\.$#"
7005-
count: 1
7006-
path: src/Database/Routines.php
7007-
7008-
-
7009-
message: "#^Cannot access offset 'Definer' on mixed\\.$#"
7010-
count: 1
7011-
path: src/Database/Routines.php
7012-
7013-
-
7014-
message: "#^Cannot access offset 'Name' on mixed\\.$#"
7015-
count: 1
7016-
path: src/Database/Routines.php
7017-
7018-
-
7019-
message: "#^Cannot access offset 'Type' on mixed\\.$#"
7020-
count: 1
7021-
path: src/Database/Routines.php
7022-
70236993
-
70246994
message: "#^Cannot access offset 'value' on mixed\\.$#"
70256995
count: 1
@@ -7132,7 +7102,7 @@ parameters:
71327102

71337103
-
71347104
message: "#^Parameter \\#1 \\$identifier of static method PhpMyAdmin\\\\Util\\:\\:backquote\\(\\) expects string\\|Stringable\\|null, mixed given\\.$#"
7135-
count: 10
7105+
count: 9
71367106
path: src/Database/Routines.php
71377107

71387108
-
@@ -7157,7 +7127,7 @@ parameters:
71577127

71587128
-
71597129
message: "#^Parameter \\#1 \\$str of method PhpMyAdmin\\\\DatabaseInterface\\:\\:quoteString\\(\\) expects string, mixed given\\.$#"
7160-
count: 5
7130+
count: 3
71617131
path: src/Database/Routines.php
71627132

71637133
-
@@ -7220,19 +7190,14 @@ parameters:
72207190
count: 1
72217191
path: src/Database/Routines.php
72227192

7223-
-
7224-
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
7225-
count: 1
7226-
path: src/Database/Routines.php
7227-
72287193
-
72297194
message: "#^Parameter \\#3 \\$name of static method PhpMyAdmin\\\\Database\\\\Routines\\:\\:getFunctionDefinition\\(\\) expects string, mixed given\\.$#"
7230-
count: 3
7195+
count: 2
72317196
path: src/Database/Routines.php
72327197

72337198
-
72347199
message: "#^Parameter \\#3 \\$name of static method PhpMyAdmin\\\\Database\\\\Routines\\:\\:getProcedureDefinition\\(\\) expects string, mixed given\\.$#"
7235-
count: 3
7200+
count: 2
72367201
path: src/Database/Routines.php
72377202

72387203
-
@@ -13950,21 +13915,11 @@ parameters:
1395013915
count: 1
1395113916
path: src/Server/Privileges.php
1395213917

13953-
-
13954-
message: "#^Cannot access offset 'name' on mixed\\.$#"
13955-
count: 3
13956-
path: src/Server/Privileges.php
13957-
1395813918
-
1395913919
message: "#^Cannot access offset 'privs' on mixed\\.$#"
1396013920
count: 1
1396113921
path: src/Server/Privileges.php
1396213922

13963-
-
13964-
message: "#^Cannot access offset 'type' on mixed\\.$#"
13965-
count: 1
13966-
path: src/Server/Privileges.php
13967-
1396813923
-
1396913924
message: "#^Cannot access offset 0 on mixed\\.$#"
1397013925
count: 2
@@ -14010,11 +13965,6 @@ parameters:
1401013965
count: 1
1401113966
path: src/Server/Privileges.php
1401213967

14013-
-
14014-
message: "#^Method PhpMyAdmin\\\\Server\\\\Privileges\\:\\:getRoutineType\\(\\) should return string but returns mixed\\.$#"
14015-
count: 1
14016-
path: src/Server/Privileges.php
14017-
1401813968
-
1401913969
message: "#^Offset '@@old_passwords' does not exist on array\\|null\\.$#"
1402013970
count: 1
@@ -14137,7 +14087,7 @@ parameters:
1413714087

1413814088
-
1413914089
message: "#^Parameter \\#1 \\$string of function mb_strtolower expects string, mixed given\\.$#"
14140-
count: 2
14090+
count: 1
1414114091
path: src/Server/Privileges.php
1414214092

1414314093
-

psalm-baseline.xml

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,8 +1149,6 @@
11491149
<code><![CDATA[$GLOBALS['errors']]]></code>
11501150
</InvalidArrayOffset>
11511151
<MixedArgument>
1152-
<code>$item</code>
1153-
<code>$routine</code>
11541152
<code><![CDATA[$routine['item_param_length'][$i]]]></code>
11551153
<code><![CDATA[$routine['item_param_name'][$i]]]></code>
11561154
</MixedArgument>
@@ -1185,8 +1183,6 @@
11851183
<MixedAssignment>
11861184
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
11871185
<code><![CDATA[$GLOBALS['errors']]]></code>
1188-
<code>$item</code>
1189-
<code>$routine</code>
11901186
<code><![CDATA[$routine['item_num_params']]]></code>
11911187
<code><![CDATA[$routine['item_num_params']]]></code>
11921188
<code><![CDATA[$routine['item_original_name']]]></code>
@@ -4834,6 +4830,11 @@
48344830
<code>DatabaseInterface::getInstance()</code>
48354831
</DeprecatedMethod>
48364832
</file>
4833+
<file src="src/Database/Routine.php">
4834+
<PossiblyUnusedProperty>
4835+
<code>$returns</code>
4836+
</PossiblyUnusedProperty>
4837+
</file>
48374838
<file src="src/Database/Routines.php">
48384839
<DeprecatedMethod>
48394840
<code>Config::getInstance()</code>
@@ -4876,12 +4877,6 @@
48764877
<code><![CDATA[$routine['item_param_type'][$i]]]></code>
48774878
<code><![CDATA[$routine['item_param_type'][$i]]]></code>
48784879
<code><![CDATA[$routine['item_param_type'][$i]]]></code>
4879-
<code><![CDATA[$routine['name']]]></code>
4880-
<code><![CDATA[$routine['name']]]></code>
4881-
<code><![CDATA[$routine['name']]]></code>
4882-
<code><![CDATA[$routine['name']]]></code>
4883-
<code><![CDATA[$routine['type']]]></code>
4884-
<code><![CDATA[$routine['type']]]></code>
48854880
<code>$value</code>
48864881
<code>$value</code>
48874882
<code>$value</code>
@@ -4900,11 +4895,6 @@
49004895
<code>$priv[5]</code>
49014896
<code>$priv[6]</code>
49024897
<code>$priv[7]</code>
4903-
<code><![CDATA[$routine['DTD_IDENTIFIER']]]></code>
4904-
<code><![CDATA[$routine['Db']]]></code>
4905-
<code><![CDATA[$routine['Definer']]]></code>
4906-
<code><![CDATA[$routine['Name']]]></code>
4907-
<code><![CDATA[$routine['Type']]]></code>
49084898
<code><![CDATA[$routine['item_param_dir'][$i]]]></code>
49094899
<code><![CDATA[$routine['item_param_dir'][$i]]]></code>
49104900
<code><![CDATA[$routine['item_param_length_arr'][$i]]]></code>
@@ -4966,7 +4956,6 @@
49664956
<code><![CDATA[$retval['item_name']]]></code>
49674957
<code><![CDATA[$retval['item_sqldataaccess']]]></code>
49684958
<code><![CDATA[$retval['item_type']]]></code>
4969-
<code>$routine</code>
49704959
<code>$string</code>
49714960
<code>$value</code>
49724961
<code>$value</code>
@@ -10607,7 +10596,6 @@
1060710596
<code>$passwordSetReal</code>
1060810597
<code>$privilege</code>
1060910598
<code>$realSqlQuery</code>
10610-
<code><![CDATA[$routine['name']]]></code>
1061110599
<code>$row</code>
1061210600
<code>$row</code>
1061310601
<code><![CDATA[$row1['Type']]]></code>
@@ -10643,10 +10631,6 @@
1064310631
<code><![CDATA[$privilege['Host']]]></code>
1064410632
<code><![CDATA[$privilege['User']]]></code>
1064510633
<code><![CDATA[$privilege['User']]]></code>
10646-
<code><![CDATA[$routine['name']]]></code>
10647-
<code><![CDATA[$routine['name']]]></code>
10648-
<code><![CDATA[$routine['name']]]></code>
10649-
<code><![CDATA[$routine['type']]]></code>
1065010634
<code><![CDATA[$row['Db']]]></code>
1065110635
<code><![CDATA[$row['Grant_priv']]]></code>
1065210636
<code><![CDATA[$row['Proc_priv']]]></code>
@@ -10698,9 +10682,6 @@
1069810682
<code>$queries[]</code>
1069910683
<code>$queries[]</code>
1070010684
<code>$queries[]</code>
10701-
<code>$routine</code>
10702-
<code>$routine</code>
10703-
<code>$routines[]</code>
1070410685
<code>$row</code>
1070510686
<code><![CDATA[$row['password']]]></code>
1070610687
<code><![CDATA[$row['password']]]></code>
@@ -10714,7 +10695,6 @@
1071410695
<code>$value</code>
1071510696
</MixedAssignment>
1071610697
<MixedInferredReturnType>
10717-
<code>string</code>
1071810698
<code>string|null</code>
1071910699
</MixedInferredReturnType>
1072010700
<MixedOperand>
@@ -10726,7 +10706,6 @@
1072610706
<code>$sqlQuery</code>
1072710707
</MixedOperand>
1072810708
<MixedReturnStatement>
10729-
<code><![CDATA[$routine['type']]]></code>
1073010709
<code><![CDATA[$row['password']]]></code>
1073110710
</MixedReturnStatement>
1073210711
<MixedReturnTypeCoercion>

resources/templates/database/routines/index.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</h2>
66

77
<div class="d-flex flex-wrap my-3">
8-
{%- if items is not empty %}
8+
{%- if has_any_routines %}
99
<div>
1010
<div class="input-group">
1111
<div class="input-group-text">
@@ -31,7 +31,7 @@
3131
</div>
3232
{%- endif %}
3333

34-
<div{{ items is not empty ? ' class="ms-2"' }}>
34+
<div{{ has_any_routines ? ' class="ms-2"' }}>
3535
<a class="ajax add_anchor btn btn-primary{{ not has_privilege ? ' disabled' }}" href="{{ url('/database/routines', {'db': db, 'table': table, 'add_item': true}) }}" role="button"{{ not has_privilege ? ' tabindex="-1" aria-disabled="true"' }}>
3636
{{ get_icon('b_routine_add', 'Create new routine'|trans) }}
3737
</a>
@@ -41,11 +41,11 @@
4141
<form id="rteListForm" class="ajax" action="{{ url('/database/routines') }}">
4242
{{ get_hidden_inputs(db, table) }}
4343

44-
<div id="nothing2display"{{ items is not empty ? ' class="hide"' }}>
44+
<div id="nothing2display"{{ has_any_routines ? ' class="hide"' }}>
4545
{{ 'There are no routines to display.'|trans|notice }}
4646
</div>
4747

48-
<table id="routinesTable" class="table table-striped table-hover{{ items is empty ? ' hide' }} data w-auto">
48+
<table id="routinesTable" class="table table-striped table-hover{{ not has_any_routines ? ' hide' }} data w-auto">
4949
<thead>
5050
<tr>
5151
<th></th>

src/Controllers/Database/RoutinesController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function __invoke(ServerRequest $request): void
145145
'new_row',
146146
$this->template->render('database/routines/row', $this->routines->getRow($routine)),
147147
);
148-
$this->response->addJSON('insert', ! empty($routine));
148+
$this->response->addJSON('insert', true);
149149
$this->response->addJSON('message', $output);
150150
$this->response->addJSON('tableType', 'routines');
151151

@@ -484,7 +484,7 @@ public function __invoke(ServerRequest $request): void
484484
$this->render('database/routines/index', [
485485
'db' => Current::$database,
486486
'table' => Current::$table,
487-
'items' => $items,
487+
'has_any_routines' => $items !== [],
488488
'rows' => $rows,
489489
'has_privilege' => Util::currentUserHasPrivilege('CREATE ROUTINE', Current::$database, Current::$table),
490490
]);

src/Database/Routine.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Database;
6+
7+
final class Routine
8+
{
9+
public function __construct(
10+
public readonly string $name,
11+
public readonly string $type,
12+
public readonly string $returns,
13+
) {
14+
}
15+
}

0 commit comments

Comments
 (0)