Skip to content

Commit 0f7887a

Browse files
Merge pull request #20099 from kamil-tekiela/Refactoring-of-properties
Refactoring of Properties
2 parents 5002b5b + 992e56f commit 0f7887a

32 files changed

+28
-575
lines changed

phpstan-baseline.neon

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8295,18 +8295,6 @@ parameters:
82958295
count: 2
82968296
path: src/Pdf.php
82978297

8298-
-
8299-
message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#'
8300-
identifier: foreach.nonIterable
8301-
count: 1
8302-
path: src/Plugins.php
8303-
8304-
-
8305-
message: '#^Call to an undefined method PhpMyAdmin\\Properties\\Options\\OptionsPropertyItem\:\:getProperties\(\)\.$#'
8306-
identifier: method.notFound
8307-
count: 1
8308-
path: src/Plugins.php
8309-
83108298
-
83118299
message: '''
83128300
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
@@ -8316,12 +8304,6 @@ parameters:
83168304
count: 2
83178305
path: src/Plugins.php
83188306

8319-
-
8320-
message: '#^Call to function in_array\(\) with arguments \(class\-string\<PhpMyAdmin\\Properties\\Options\\Groups\\OptionsPropertySubgroup\>&literal\-string\)\|null, array\{''PhpMyAdmin\\\\Properties\\\\Options\\\\Items\\\\BoolPropertyItem'', ''PhpMyAdmin\\\\Properties\\\\Options\\\\Items\\\\MessageOnlyPropertyItem'', ''PhpMyAdmin\\\\Properties\\\\Options\\\\Items\\\\SelectPropertyItem'', ''PhpMyAdmin\\\\Properties\\\\Options\\\\Items\\\\TextPropertyItem''\} and true will always evaluate to false\.$#'
8321-
identifier: function.impossibleType
8322-
count: 1
8323-
path: src/Plugins.php
8324-
83258307
-
83268308
message: '#^Call to function method_exists\(\) with PhpMyAdmin\\Properties\\Options\\OptionsPropertyItem and ''getText'' will always evaluate to true\.$#'
83278309
identifier: function.alreadyNarrowedType
@@ -8352,24 +8334,6 @@ parameters:
83528334
count: 2
83538335
path: src/Plugins.php
83548336

8355-
-
8356-
message: '#^Parameter \#1 \$link of static method PhpMyAdmin\\Html\\MySQLDocumentation\:\:show\(\) expects string, mixed given\.$#'
8357-
identifier: argument.type
8358-
count: 2
8359-
path: src/Plugins.php
8360-
8361-
-
8362-
message: '#^Parameter \#2 \$anchor of static method PhpMyAdmin\\Html\\MySQLDocumentation\:\:showDocumentation\(\) expects string, mixed given\.$#'
8363-
identifier: argument.type
8364-
count: 1
8365-
path: src/Plugins.php
8366-
8367-
-
8368-
message: '#^Parameter \#5 \$anchor of static method PhpMyAdmin\\Html\\MySQLDocumentation\:\:show\(\) expects string, mixed given\.$#'
8369-
identifier: argument.type
8370-
count: 1
8371-
path: src/Plugins.php
8372-
83738337
-
83748338
message: '''
83758339
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
@@ -10644,12 +10608,6 @@ parameters:
1064410608
count: 1
1064510609
path: src/Profiling.php
1064610610

10647-
-
10648-
message: '#^Method PhpMyAdmin\\Properties\\Options\\OptionsPropertyGroup\:\:count\(\) should return int\<0, max\> but returns int\.$#'
10649-
identifier: return.type
10650-
count: 1
10651-
path: src/Properties/Options/OptionsPropertyGroup.php
10652-
1065310611
-
1065410612
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
1065510613
identifier: equal.notAllowed
@@ -16509,6 +16467,12 @@ parameters:
1650916467
count: 1
1651016468
path: tests/unit/PluginsTest.php
1651116469

16470+
-
16471+
message: '#^You should use assertCount\(\$expectedCount, \$variable\) instead of assertSame\(\$expectedCount, \$variable\-\>count\(\)\)\.$#'
16472+
identifier: phpunit.assertCount
16473+
count: 1
16474+
path: tests/unit/Properties/Options/OptionsPropertyGroupTest.php
16475+
1651216476
-
1651316477
message: '''
1651416478
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:

psalm-baseline.xml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5606,15 +5606,7 @@
56065606
<code><![CDATA[Config::getInstance()]]></code>
56075607
<code><![CDATA[Config::getInstance()]]></code>
56085608
</DeprecatedMethod>
5609-
<MixedArgument>
5610-
<code><![CDATA[$doc[0]]]></code>
5611-
<code><![CDATA[$doc[1]]]></code>
5612-
<code><![CDATA[$doc[1]]]></code>
5613-
<code><![CDATA[$doc[2]]]></code>
5614-
</MixedArgument>
56155609
<MixedAssignment>
5616-
<code><![CDATA[$doc]]></code>
5617-
<code><![CDATA[$propertyItem]]></code>
56185610
<code><![CDATA[$val]]></code>
56195611
<code><![CDATA[$val]]></code>
56205612
</MixedAssignment>
@@ -5652,17 +5644,6 @@
56525644
<RiskyTruthyFalsyComparison>
56535645
<code><![CDATA[empty(Config::getInstance()->settings[$section][$opt])]]></code>
56545646
</RiskyTruthyFalsyComparison>
5655-
<TypeDoesNotContainType>
5656-
<code><![CDATA[in_array($propertyClass, [
5657-
BoolPropertyItem::class,
5658-
MessageOnlyPropertyItem::class,
5659-
SelectPropertyItem::class,
5660-
TextPropertyItem::class,
5661-
], true)]]></code>
5662-
</TypeDoesNotContainType>
5663-
<UndefinedMethod>
5664-
<code><![CDATA[getProperties]]></code>
5665-
</UndefinedMethod>
56665647
</file>
56675648
<file src="src/Plugins/Auth/AuthenticationConfig.php">
56685649
<DeprecatedMethod>

src/Plugins.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use PhpMyAdmin\Plugins\ImportPlugin;
1818
use PhpMyAdmin\Plugins\Plugin;
1919
use PhpMyAdmin\Plugins\SchemaPlugin;
20+
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
2021
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertySubgroup;
2122
use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem;
2223
use PhpMyAdmin\Properties\Options\Items\DocPropertyItem;
@@ -28,6 +29,7 @@
2829
use PhpMyAdmin\Properties\Options\Items\TextPropertyItem;
2930
use PhpMyAdmin\Properties\Options\OptionsPropertyGroup;
3031
use PhpMyAdmin\Properties\Options\OptionsPropertyItem;
32+
use PhpMyAdmin\Properties\Options\OptionsPropertyOneItem;
3133
use SplFileInfo;
3234
use Throwable;
3335

@@ -44,7 +46,6 @@
4446
use function mb_substr;
4547
use function method_exists;
4648
use function sprintf;
47-
use function str_contains;
4849
use function str_starts_with;
4950
use function strcasecmp;
5051
use function usort;
@@ -297,7 +298,7 @@ private static function getOneOption(
297298
$properties = null;
298299
if (! $isSubgroup) {
299300
// for subgroup headers
300-
if (str_contains($propertyGroup::class, 'PropertyItem')) {
301+
if ($propertyGroup instanceof OptionsPropertyOneItem) {
301302
$properties = [$propertyGroup];
302303
} else {
303304
// for main groups
@@ -326,14 +327,12 @@ private static function getOneOption(
326327

327328
$propertyClass = null;
328329
if ($properties !== null) {
329-
/** @var OptionsPropertySubgroup $propertyItem */
330330
foreach ($properties as $propertyItem) {
331331
$propertyClass = $propertyItem::class;
332332
// if the property is a subgroup, we deal with it recursively
333-
if (str_contains($propertyClass, 'Subgroup')) {
333+
if ($propertyItem instanceof OptionsPropertySubgroup) {
334334
// for subgroups
335335
// each subgroup can have a header, which may also be a form element
336-
/** @var OptionsPropertyItem|null $subgroupHeader */
337336
$subgroupHeader = $propertyItem->getSubgroupHeader();
338337
if ($subgroupHeader !== null) {
339338
$ret .= self::getOneOption($plugin, $section, $pluginName, $subgroupHeader);
@@ -363,7 +362,7 @@ private static function getOneOption(
363362
$ret .= '</ul></div>';
364363
}
365364

366-
if (method_exists($propertyGroup, 'getDoc')) {
365+
if ($propertyGroup instanceof OptionsPropertyOneItem) {
367366
$doc = $propertyGroup->getDoc();
368367
if (is_array($doc)) {
369368
if (count($doc) === 3) {
@@ -581,7 +580,8 @@ public static function getOptions(string $section, array $list): string
581580
$ret .= '<h3>' . $plugin->getTranslatedText($text) . '</h3>';
582581

583582
$noOptions = true;
584-
if ($options !== null && count($options) > 0) {
583+
if ($options !== null && $options->count() > 0) {
584+
/** @var OptionsPropertyMainGroup $propertyMainGroup */
585585
foreach ($options->getProperties() as $propertyMainGroup) {
586586
// check for hidden properties
587587
$noOptions = true;

src/Properties/Options/Groups/OptionsPropertyMainGroup.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,4 @@
1111
*/
1212
class OptionsPropertyMainGroup extends OptionsPropertyGroup
1313
{
14-
/**
15-
* Returns the property item type of either an instance of
16-
* - PhpMyAdmin\Properties\Options\OptionsPropertyOneItem ( f.e. "bool",
17-
* "text", "radio", etc ) or
18-
* - PhpMyAdmin\Properties\Options\OptionsPropertyGroup ( "root", "main"
19-
* or "subgroup" )
20-
* - PhpMyAdmin\Properties\Plugins\PluginPropertyItem ( "export", "import", "transformations" )
21-
*/
22-
public function getItemType(): string
23-
{
24-
return 'main';
25-
}
2614
}

src/Properties/Options/Groups/OptionsPropertyRootGroup.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,4 @@
1111
*/
1212
class OptionsPropertyRootGroup extends OptionsPropertyGroup
1313
{
14-
/**
15-
* Returns the property item type of either an instance of
16-
* - PhpMyAdmin\Properties\Options\OptionsPropertyOneItem ( f.e. "bool",
17-
* "text", "radio", etc ) or
18-
* - PhpMyAdmin\Properties\Options\OptionsPropertyGroup ( "root", "main"
19-
* or "subgroup" )
20-
* - PhpMyAdmin\Properties\Plugins\PluginPropertyItem ( "export", "import", "transformations" )
21-
*/
22-
public function getItemType(): string
23-
{
24-
return 'root';
25-
}
2614
}

src/Properties/Options/Groups/OptionsPropertySubgroup.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,21 @@
55
namespace PhpMyAdmin\Properties\Options\Groups;
66

77
use PhpMyAdmin\Properties\Options\OptionsPropertyGroup;
8-
use PhpMyAdmin\Properties\PropertyItem;
8+
use PhpMyAdmin\Properties\Options\OptionsPropertyOneItem;
99

1010
/**
1111
* Group property item class of type subgroup
1212
*/
1313
class OptionsPropertySubgroup extends OptionsPropertyGroup
1414
{
15-
private PropertyItem|null $subgroupHeader = null;
16-
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
15+
private OptionsPropertyOneItem|null $subgroupHeader = null;
1716

18-
/**
19-
* Returns the property item type of either an instance of
20-
* - PhpMyAdmin\Properties\Options\OptionsPropertyOneItem ( f.e. "bool",
21-
* "text", "radio", etc ) or
22-
* - PhpMyAdmin\Properties\Options\OptionsPropertyGroup ( "root", "main"
23-
* or "subgroup" )
24-
* - PhpMyAdmin\Properties\Plugins\PluginPropertyItem ( "export", "import", "transformations" )
25-
*/
26-
public function getItemType(): string
27-
{
28-
return 'subgroup';
29-
}
30-
31-
public function getSubgroupHeader(): PropertyItem|null
17+
public function getSubgroupHeader(): OptionsPropertyOneItem|null
3218
{
3319
return $this->subgroupHeader;
3420
}
3521

36-
public function setSubgroupHeader(PropertyItem $subgroupHeader): void
22+
public function setSubgroupHeader(OptionsPropertyOneItem $subgroupHeader): void
3723
{
3824
$this->subgroupHeader = $subgroupHeader;
3925
}

src/Properties/Options/Items/BoolPropertyItem.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,4 @@
1111
*/
1212
class BoolPropertyItem extends OptionsPropertyOneItem
1313
{
14-
/**
15-
* Returns the property item type of either an instance of
16-
* - PhpMyAdmin\Properties\Options\OptionsPropertyOneItem ( f.e. "bool",
17-
* "text", "radio", etc ) or
18-
* - PhpMyAdmin\Properties\Options\OptionsPropertyGroup ( "root", "main"
19-
* or "subgroup" )
20-
* - PhpMyAdmin\Properties\Plugins\PluginPropertyItem ( "export", "import", "transformations" )
21-
*/
22-
public function getItemType(): string
23-
{
24-
return 'bool';
25-
}
2614
}

src/Properties/Options/Items/DocPropertyItem.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,4 @@
1111
*/
1212
class DocPropertyItem extends OptionsPropertyOneItem
1313
{
14-
/**
15-
* Returns the property item type of either an instance of
16-
* - PhpMyAdmin\Properties\Options\OptionsPropertyOneItem ( f.e. "bool",
17-
* "text", "radio", etc ) or
18-
* - PhpMyAdmin\Properties\Options\OptionsPropertyGroup ( "root", "main"
19-
* or "subgroup" )
20-
* - PhpMyAdmin\Properties\Plugins\PluginPropertyItem ( "export", "import", "transformations" )
21-
*/
22-
public function getItemType(): string
23-
{
24-
return 'doc';
25-
}
2614
}

src/Properties/Options/Items/HiddenPropertyItem.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,4 @@
1111
*/
1212
class HiddenPropertyItem extends OptionsPropertyOneItem
1313
{
14-
/**
15-
* Returns the property item type of either an instance of
16-
* - PhpMyAdmin\Properties\Options\OptionsPropertyOneItem ( f.e. "bool",
17-
* "text", "radio", etc ) or
18-
* - PhpMyAdmin\Properties\Options\OptionsPropertyGroup ( "root", "main"
19-
* or "subgroup" )
20-
* - PhpMyAdmin\Properties\Plugins\PluginPropertyItem ( "export", "import", "transformations" )
21-
*/
22-
public function getItemType(): string
23-
{
24-
return 'hidden';
25-
}
2614
}

src/Properties/Options/Items/MessageOnlyPropertyItem.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,4 @@
1111
*/
1212
class MessageOnlyPropertyItem extends OptionsPropertyOneItem
1313
{
14-
/**
15-
* Returns the property item type of either an instance of
16-
* - PhpMyAdmin\Properties\Options\OptionsPropertyOneItem ( f.e. "bool",
17-
* "text", "radio", etc ) or
18-
* - PhpMyAdmin\Properties\Options\OptionsPropertyGroup ( "root", "main"
19-
* or "subgroup" )
20-
* - PhpMyAdmin\Properties\Plugins\PluginPropertyItem ( "export", "import", "transformations" )
21-
*/
22-
public function getItemType(): string
23-
{
24-
return 'messageOnly';
25-
}
2614
}

0 commit comments

Comments
 (0)