Skip to content

Commit 1e4af77

Browse files
Refactor Plugins.php (#17960)
* Remove temporary variable Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Remove pass-by-ref Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Refactor getOneOption Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Refactor getOptions Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
1 parent 08a27b8 commit 1e4af77

4 files changed

Lines changed: 48 additions & 44 deletions

File tree

libraries/classes/Plugins.php

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use function count;
2929
use function get_class;
3030
use function htmlspecialchars;
31+
use function is_array;
3132
use function is_subclass_of;
3233
use function mb_strpos;
3334
use function mb_strtolower;
@@ -289,12 +290,12 @@ public static function getChoice(array $list, string $default): array
289290
*
290291
* @return string table row with option
291292
*/
292-
public static function getOneOption(
293-
$section,
294-
$plugin_name,
295-
&$propertyGroup,
296-
$is_subgroup = false
297-
) {
293+
private static function getOneOption(
294+
string $section,
295+
string $plugin_name,
296+
OptionsPropertyItem $propertyGroup,
297+
bool $is_subgroup = false
298+
): string {
298299
$ret = "\n";
299300

300301
$properties = null;
@@ -320,15 +321,15 @@ public static function getOneOption(
320321
}
321322

322323
$not_subgroup_header = false;
323-
if (! isset($properties)) {
324+
if ($properties === null) {
324325
$not_subgroup_header = true;
325326
if (method_exists($propertyGroup, 'getProperties')) {
326327
$properties = $propertyGroup->getProperties();
327328
}
328329
}
329330

330331
$property_class = null;
331-
if (isset($properties)) {
332+
if ($properties !== null) {
332333
/** @var OptionsPropertySubgroup $propertyItem */
333334
foreach ($properties as $propertyItem) {
334335
$property_class = get_class($propertyItem);
@@ -368,7 +369,7 @@ public static function getOneOption(
368369

369370
if (method_exists($propertyGroup, 'getDoc')) {
370371
$doc = $propertyGroup->getDoc();
371-
if ($doc != null) {
372+
if (is_array($doc)) {
372373
if (count($doc) === 3) {
373374
$ret .= MySQLDocumentation::show($doc[1], false, null, null, $doc[2]);
374375
} elseif (count($doc) === 1) {
@@ -380,15 +381,13 @@ public static function getOneOption(
380381
}
381382

382383
// Close the list element after $doc link is displayed
383-
if ($property_class !== null) {
384-
if (
385-
$property_class == BoolPropertyItem::class
386-
|| $property_class == MessageOnlyPropertyItem::class
387-
|| $property_class == SelectPropertyItem::class
388-
|| $property_class == TextPropertyItem::class
389-
) {
390-
$ret .= '</li>';
391-
}
384+
if (
385+
$property_class === BoolPropertyItem::class
386+
|| $property_class === MessageOnlyPropertyItem::class
387+
|| $property_class === SelectPropertyItem::class
388+
|| $property_class === TextPropertyItem::class
389+
) {
390+
$ret .= '</li>';
392391
}
393392

394393
return $ret . "\n";
@@ -573,18 +572,14 @@ public static function getHtmlForProperty(
573572
*
574573
* @return string html fieldset with plugin options
575574
*/
576-
public static function getOptions($section, array $list)
575+
public static function getOptions(string $section, array $list): string
577576
{
578577
$ret = '';
579578
// Options for plugins that support them
580579
foreach ($list as $plugin) {
581580
$properties = $plugin->getProperties();
582-
$text = null;
583-
$options = null;
584-
if ($properties != null) {
585-
$text = $properties->getText();
586-
$options = $properties->getOptions();
587-
}
581+
$text = $properties->getText();
582+
$options = $properties->getOptions();
588583

589584
$plugin_name = $plugin->getName();
590585

libraries/classes/Plugins/ExportPlugin.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ public function getRelationString(
341341
$db,
342342
array $aliases = []
343343
) {
344-
$relation = '';
345344
$foreigner = $this->relation->searchColumnInForeigners($foreigners, $fieldName);
346345
if ($foreigner) {
347346
$ftable = $foreigner['foreign_table'];
@@ -354,10 +353,10 @@ public function getRelationString(
354353
$ftable = $aliases[$db]['tables'][$ftable]['alias'];
355354
}
356355

357-
$relation = $ftable . ' (' . $ffield . ')';
356+
return $ftable . ' (' . $ffield . ')';
358357
}
359358

360-
return $relation;
359+
return '';
361360
}
362361

363362
public static function isAvailable(): bool

phpstan-baseline.neon

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5756,18 +5756,33 @@ parameters:
57565756
path: libraries/classes/Plugins.php
57575757

57585758
-
5759-
message: "#^Left side of \\|\\| is always false\\.$#"
5759+
message: "#^Parameter \\#2 \\$str2 of function strcmp expects string, class\\-string\\|false given\\.$#"
57605760
count: 1
57615761
path: libraries/classes/Plugins.php
57625762

57635763
-
5764-
message: "#^Parameter \\#2 \\$str2 of function strcmp expects string, class\\-string\\|false given\\.$#"
5764+
message: "#^Result of \\|\\| is always false\\.$#"
5765+
count: 3
5766+
path: libraries/classes/Plugins.php
5767+
5768+
-
5769+
message: "#^Strict comparison using \\=\\=\\= between class\\-string\\<PhpMyAdmin\\\\Properties\\\\Options\\\\Groups\\\\OptionsPropertySubgroup\\>\\|null and 'PhpMyAdmin\\\\\\\\Properties\\\\\\\\Options\\\\\\\\Items\\\\\\\\BoolPropertyItem' will always evaluate to false\\.$#"
57655770
count: 1
57665771
path: libraries/classes/Plugins.php
57675772

57685773
-
5769-
message: "#^Right side of \\|\\| is always false\\.$#"
5770-
count: 3
5774+
message: "#^Strict comparison using \\=\\=\\= between class\\-string\\<PhpMyAdmin\\\\Properties\\\\Options\\\\Groups\\\\OptionsPropertySubgroup\\>\\|null and 'PhpMyAdmin\\\\\\\\Properties\\\\\\\\Options\\\\\\\\Items\\\\\\\\MessageOnlyPropertyItem' will always evaluate to false\\.$#"
5775+
count: 1
5776+
path: libraries/classes/Plugins.php
5777+
5778+
-
5779+
message: "#^Strict comparison using \\=\\=\\= between class\\-string\\<PhpMyAdmin\\\\Properties\\\\Options\\\\Groups\\\\OptionsPropertySubgroup\\>\\|null and 'PhpMyAdmin\\\\\\\\Properties\\\\\\\\Options\\\\\\\\Items\\\\\\\\SelectPropertyItem' will always evaluate to false\\.$#"
5780+
count: 1
5781+
path: libraries/classes/Plugins.php
5782+
5783+
-
5784+
message: "#^Strict comparison using \\=\\=\\= between class\\-string\\<PhpMyAdmin\\\\Properties\\\\Options\\\\Groups\\\\OptionsPropertySubgroup\\>\\|null and 'PhpMyAdmin\\\\\\\\Properties\\\\\\\\Options\\\\\\\\Items\\\\\\\\TextPropertyItem' will always evaluate to false\\.$#"
5785+
count: 1
57715786
path: libraries/classes/Plugins.php
57725787

57735788
-

psalm-baseline.xml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9008,9 +9008,7 @@
90089008
<InvalidReturnType occurrences="1">
90099009
<code>string</code>
90109010
</InvalidReturnType>
9011-
<MixedArgument occurrences="12">
9012-
<code>$doc</code>
9013-
<code>$doc</code>
9011+
<MixedArgument occurrences="10">
90149012
<code>$doc[0]</code>
90159013
<code>$doc[1]</code>
90169014
<code>$doc[1]</code>
@@ -9022,12 +9020,6 @@
90229020
<code>$val</code>
90239021
<code>$val</code>
90249022
</MixedArgument>
9025-
<MixedArrayAccess occurrences="4">
9026-
<code>$doc[0]</code>
9027-
<code>$doc[1]</code>
9028-
<code>$doc[1]</code>
9029-
<code>$doc[2]</code>
9030-
</MixedArrayAccess>
90319023
<MixedAssignment occurrences="7">
90329024
<code>$doc</code>
90339025
<code>$properties</code>
@@ -9077,9 +9069,12 @@
90779069
<code>$propertyItem-&gt;getName()</code>
90789070
<code>$subgroup_header-&gt;getName()</code>
90799071
</PossiblyNullOperand>
9080-
<RedundantConditionGivenDocblockType occurrences="1">
9081-
<code>$properties != null</code>
9082-
</RedundantConditionGivenDocblockType>
9072+
<TypeDoesNotContainType occurrences="4">
9073+
<code>$property_class === BoolPropertyItem::class</code>
9074+
<code>$property_class === MessageOnlyPropertyItem::class</code>
9075+
<code>$property_class === SelectPropertyItem::class</code>
9076+
<code>$property_class === TextPropertyItem::class</code>
9077+
</TypeDoesNotContainType>
90839078
<UnnecessaryVarAnnotation occurrences="3">
90849079
<code>RadioPropertyItem</code>
90859080
<code>SelectPropertyItem</code>

0 commit comments

Comments
 (0)