Skip to content

Commit f6be1e9

Browse files
Merge pull request #20098 from MauricioFauth/template-di
Extract Config dependency from Template class
2 parents 210d186 + 2dabc83 commit f6be1e9

101 files changed

Lines changed: 358 additions & 216 deletions

File tree

Some content is hidden

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

‎phpstan-baseline.neon‎

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,15 @@ parameters:
13231323
count: 1
13241324
path: src/ConfigStorage/Relation.php
13251325

1326+
-
1327+
message: '''
1328+
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
1329+
Use dependency injection instead\.$#
1330+
'''
1331+
identifier: staticMethod.deprecated
1332+
count: 4
1333+
path: src/ConfigStorage/UserGroups.php
1334+
13261335
-
13271336
message: '''
13281337
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Dbal\\DatabaseInterface\:
@@ -5448,7 +5457,7 @@ parameters:
54485457
Use dependency injection instead\.$#
54495458
'''
54505459
identifier: staticMethod.deprecated
5451-
count: 4
5460+
count: 5
54525461
path: src/Encoding.php
54535462

54545463
-
@@ -5481,6 +5490,15 @@ parameters:
54815490
count: 1
54825491
path: src/Encoding.php
54835492

5493+
-
5494+
message: '''
5495+
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
5496+
Use dependency injection instead\.$#
5497+
'''
5498+
identifier: staticMethod.deprecated
5499+
count: 1
5500+
path: src/Engines/Innodb.php
5501+
54845502
-
54855503
message: '''
54865504
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Dbal\\DatabaseInterface\:
@@ -5520,6 +5538,15 @@ parameters:
55205538
count: 2
55215539
path: src/Error/Error.php
55225540

5541+
-
5542+
message: '''
5543+
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
5544+
Use dependency injection instead\.$#
5545+
'''
5546+
identifier: staticMethod.deprecated
5547+
count: 1
5548+
path: src/Error/Error.php
5549+
55235550
-
55245551
message: '#^Cannot access offset ''args'' on mixed\.$#'
55255552
identifier: offsetAccess.nonOffsetAccessible
@@ -5895,7 +5922,7 @@ parameters:
58955922
Use dependency injection instead\.$#
58965923
'''
58975924
identifier: staticMethod.deprecated
5898-
count: 3
5925+
count: 4
58995926
path: src/Favorites/RecentFavoriteTables.php
59005927

59015928
-
@@ -6846,7 +6873,7 @@ parameters:
68466873
Use dependency injection instead\.$#
68476874
'''
68486875
identifier: staticMethod.deprecated
6849-
count: 8
6876+
count: 9
68506877
path: src/Html/Generator.php
68516878

68526879
-
@@ -7572,6 +7599,15 @@ parameters:
75727599
count: 1
75737600
path: src/Menu.php
75747601

7602+
-
7603+
message: '''
7604+
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
7605+
Use dependency injection instead\.$#
7606+
'''
7607+
identifier: staticMethod.deprecated
7608+
count: 1
7609+
path: src/Message.php
7610+
75757611
-
75767612
message: '#^Cannot cast mixed to string\.$#'
75777613
identifier: cast.string
@@ -8592,7 +8628,7 @@ parameters:
85928628
Use dependency injection instead\.$#
85938629
'''
85948630
identifier: staticMethod.deprecated
8595-
count: 6
8631+
count: 7
85968632
path: src/Plugins/AuthenticationPlugin.php
85978633

85988634
-
@@ -10593,7 +10629,7 @@ parameters:
1059310629
Use dependency injection instead\.$#
1059410630
'''
1059510631
identifier: staticMethod.deprecated
10596-
count: 1
10632+
count: 2
1059710633
path: src/Plugins/TwoFactorPlugin.php
1059810634

1059910635
-
@@ -12591,15 +12627,6 @@ parameters:
1259112627
count: 6
1259212628
path: src/Table/TableMover.php
1259312629

12594-
-
12595-
message: '''
12596-
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
12597-
Use dependency injection instead\.$#
12598-
'''
12599-
identifier: staticMethod.deprecated
12600-
count: 1
12601-
path: src/Template.php
12602-
1260312630
-
1260412631
message: '#^Call to function in_array\(\) requires parameter \#3 to be set\.$#'
1260512632
identifier: function.strict
@@ -15873,7 +15900,7 @@ parameters:
1587315900
Use dependency injection instead\.$#
1587415901
'''
1587515902
identifier: staticMethod.deprecated
15876-
count: 21
15903+
count: 20
1587715904
path: tests/unit/InsertEditTest.php
1587815905

1587915906
-

‎psalm-baseline.xml‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,10 @@
629629
</file>
630630
<file src="src/ConfigStorage/UserGroups.php">
631631
<DeprecatedMethod>
632+
<code><![CDATA[Config::getInstance()]]></code>
633+
<code><![CDATA[Config::getInstance()]]></code>
634+
<code><![CDATA[Config::getInstance()]]></code>
635+
<code><![CDATA[Config::getInstance()]]></code>
632636
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
633637
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
634638
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
@@ -3932,6 +3936,7 @@
39323936
<code><![CDATA[Config::getInstance()]]></code>
39333937
<code><![CDATA[Config::getInstance()]]></code>
39343938
<code><![CDATA[Config::getInstance()]]></code>
3939+
<code><![CDATA[Config::getInstance()]]></code>
39353940
</DeprecatedMethod>
39363941
<PossiblyNullArgument>
39373942
<code><![CDATA[Config::getInstance()->getUploadTempDir()]]></code>
@@ -3942,6 +3947,7 @@
39423947
</file>
39433948
<file src="src/Engines/Innodb.php">
39443949
<DeprecatedMethod>
3950+
<code><![CDATA[Config::getInstance()]]></code>
39453951
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
39463952
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
39473953
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
@@ -3955,6 +3961,9 @@
39553961
</PossiblyUnusedMethod>
39563962
</file>
39573963
<file src="src/Error/Error.php">
3964+
<DeprecatedMethod>
3965+
<code><![CDATA[Config::getInstance()]]></code>
3966+
</DeprecatedMethod>
39583967
<MixedArgument>
39593968
<code><![CDATA[$step]]></code>
39603969
<code><![CDATA[$step['args']]]></code>
@@ -4161,6 +4170,7 @@
41614170
<code><![CDATA[Config::getInstance()]]></code>
41624171
<code><![CDATA[Config::getInstance()]]></code>
41634172
<code><![CDATA[Config::getInstance()]]></code>
4173+
<code><![CDATA[Config::getInstance()]]></code>
41644174
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
41654175
</DeprecatedMethod>
41664176
<MixedArgument>
@@ -4743,6 +4753,7 @@
47434753
<code><![CDATA[Config::getInstance()]]></code>
47444754
<code><![CDATA[Config::getInstance()]]></code>
47454755
<code><![CDATA[Config::getInstance()]]></code>
4756+
<code><![CDATA[Config::getInstance()]]></code>
47464757
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
47474758
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
47484759
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
@@ -5168,6 +5179,9 @@
51685179
</RiskyTruthyFalsyComparison>
51695180
</file>
51705181
<file src="src/Message.php">
5182+
<DeprecatedMethod>
5183+
<code><![CDATA[Config::getInstance()]]></code>
5184+
</DeprecatedMethod>
51715185
<MixedArgument>
51725186
<code><![CDATA[$this->params]]></code>
51735187
</MixedArgument>
@@ -5783,6 +5797,7 @@
57835797
<code><![CDATA[Config::getInstance()]]></code>
57845798
<code><![CDATA[Config::getInstance()]]></code>
57855799
<code><![CDATA[Config::getInstance()]]></code>
5800+
<code><![CDATA[Config::getInstance()]]></code>
57865801
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
57875802
</DeprecatedMethod>
57885803
<MixedArrayAssignment>
@@ -7223,6 +7238,7 @@
72237238
<file src="src/Plugins/TwoFactorPlugin.php">
72247239
<DeprecatedMethod>
72257240
<code><![CDATA[Config::getInstance()]]></code>
7241+
<code><![CDATA[Config::getInstance()]]></code>
72267242
</DeprecatedMethod>
72277243
</file>
72287244
<file src="src/Plugins/UploadInterface.php">
@@ -8240,11 +8256,6 @@
82408256
<code><![CDATA[$maintainRelations]]></code>
82418257
</UnusedVariable>
82428258
</file>
8243-
<file src="src/Template.php">
8244-
<DeprecatedMethod>
8245-
<code><![CDATA[Config::getInstance()]]></code>
8246-
</DeprecatedMethod>
8247-
</file>
82488259
<file src="src/Theme/Theme.php">
82498260
<MixedArgument>
82508261
<code><![CDATA[$data['name']]]></code>
@@ -10208,7 +10219,6 @@
1020810219
<code><![CDATA[Config::getInstance()]]></code>
1020910220
<code><![CDATA[Config::getInstance()]]></code>
1021010221
<code><![CDATA[Config::getInstance()]]></code>
10211-
<code><![CDATA[Config::getInstance()]]></code>
1021210222
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
1021310223
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
1021410224
</DeprecatedMethod>

‎src/Config/FormDisplayTemplate.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FormDisplayTemplate
2323

2424
public function __construct(protected Config $config)
2525
{
26-
$this->template = new Template();
26+
$this->template = new Template($this->config);
2727
}
2828

2929
/**

‎src/ConfigStorage/UserGroups.php‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace PhpMyAdmin\ConfigStorage;
99

10+
use PhpMyAdmin\Config;
1011
use PhpMyAdmin\ConfigStorage\Features\ConfigurableMenusFeature;
1112
use PhpMyAdmin\Dbal\ConnectionType;
1213
use PhpMyAdmin\Dbal\DatabaseInterface;
@@ -56,7 +57,7 @@ public static function getHtmlForListingUsersofAGroup(
5657
}
5758
}
5859

59-
$template = new Template();
60+
$template = new Template(Config::getInstance());
6061

6162
return $template->render('server/user_groups/user_listings', [
6263
'user_group_special_chars' => $userGroupSpecialChars,
@@ -116,7 +117,7 @@ public static function getHtmlForUserGroupsTable(ConfigurableMenusFeature $confi
116117

117118
$addUserUrl = Url::getFromRoute('/server/user-groups', ['addUserGroup' => 1]);
118119
$addUserIcon = Generator::getIcon('b_usradd');
119-
$template = new Template();
120+
$template = new Template(Config::getInstance());
120121

121122
return $template->render('server/user_groups/user_groups', [
122123
'action' => $action,
@@ -240,7 +241,7 @@ public static function getHtmlToEditUserGroup(
240241
$allowedTabs['table'],
241242
);
242243

243-
$template = new Template();
244+
$template = new Template(Config::getInstance());
244245

245246
return $template->render('server/user_groups/edit_user_groups', [
246247
'user_group' => $userGroup,
@@ -272,7 +273,7 @@ public static function getTabList(string $title, UserGroupLevel $level, array $s
272273
$tabDetails[] = $tabDetail;
273274
}
274275

275-
$template = new Template();
276+
$template = new Template(Config::getInstance());
276277

277278
return $template->render('server/user_groups/tab_list', [
278279
'title' => $title,

‎src/Database/CentralColumns.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct(private DatabaseInterface $dbi)
7171
$this->disableIs = $config->selectedServer['DisableIS'];
7272

7373
$this->relation = new Relation($this->dbi);
74-
$this->template = new Template();
74+
$this->template = new Template($config);
7575
}
7676

7777
/**

‎src/Display/Results.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public function __construct(
219219
) {
220220
$this->relation = new Relation($this->dbi);
221221
$this->transformations = new Transformations($this->dbi, $this->relation);
222-
$this->template = new Template();
222+
$this->template = new Template($this->config);
223223

224224
$this->setDefaultTransformations();
225225

‎src/Encoding.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public static function kanjiFileConv(string $file, string $enc, string $kana): s
282282
*/
283283
public static function kanjiEncodingForm(): string
284284
{
285-
$template = new Template();
285+
$template = new Template(Config::getInstance());
286286

287287
return $template->render('encoding/kanji_encoding_form');
288288
}

‎src/Engines/Innodb.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpMyAdmin\Engines;
66

7+
use PhpMyAdmin\Config;
78
use PhpMyAdmin\Dbal\DatabaseInterface;
89
use PhpMyAdmin\Engines\Innodb\BufferPool;
910
use PhpMyAdmin\StorageEngine;
@@ -109,7 +110,7 @@ public function getInfoPages(): array
109110
*/
110111
public function getPageBufferPool(): string
111112
{
112-
return (new Template())->render('server/engines/_innodb_buffer_pool', [
113+
return (new Template(Config::getInstance()))->render('server/engines/_innodb_buffer_pool', [
113114
'buffer_pool' => $this->getBufferPoolStatus(),
114115
]);
115116
}

‎src/Error/Error.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpMyAdmin\Error;
66

7+
use PhpMyAdmin\Config;
78
use PhpMyAdmin\Message;
89
use PhpMyAdmin\MessageType;
910
use PhpMyAdmin\Template;
@@ -422,7 +423,7 @@ public function getDisplay(): string
422423
{
423424
$this->isDisplayed(true);
424425

425-
$template = new Template();
426+
$template = new Template(Config::getInstance());
426427

427428
return $template->render('error/get_display', [
428429
'context' => $this->getLevel() === MessageType::Error ? 'danger' : 'primary',

‎src/Favorites/RecentFavoriteTables.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function __destruct()
8989
public static function getInstance(TableType $type): RecentFavoriteTables
9090
{
9191
if (! array_key_exists($type->value, self::$instances)) {
92-
$template = new Template();
92+
$template = new Template(Config::getInstance());
9393
$dbi = DatabaseInterface::getInstance();
9494
self::$instances[$type->value] = new RecentFavoriteTables(
9595
$template,

0 commit comments

Comments
 (0)