Merge pull request #19325 from kamil-tekiela/Refactoring-BrowseForeigners
Refactoring browse foreigners
This commit is contained in:
commit
681e02dd65
@ -148,21 +148,11 @@ parameters:
|
||||
count: 1
|
||||
path: src/Bookmarks/BookmarkRepository.php
|
||||
|
||||
-
|
||||
message: "#^Cannot cast mixed to string\\.$#"
|
||||
count: 1
|
||||
path: src/BrowseForeigners.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$description of method PhpMyAdmin\\\\BrowseForeigners\\:\\:getDescriptionAndTitle\\(\\) expects string, mixed given\\.$#"
|
||||
count: 2
|
||||
path: src/BrowseForeigners.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$string of function htmlspecialchars expects string, mixed given\\.$#"
|
||||
count: 1
|
||||
path: src/BrowseForeigners.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$state of static method PhpMyAdmin\\\\Charsets\\\\Charset\\:\\:fromServer\\(\\) expects array\\{Charset\\?\\: string, Description\\?\\: string, Default collation\\?\\: string, Maxlen\\?\\: string\\}, array\\<string\\|null\\> given\\.$#"
|
||||
count: 1
|
||||
@ -1391,6 +1381,11 @@ parameters:
|
||||
count: 1
|
||||
path: src/Console.php
|
||||
|
||||
-
|
||||
message: "#^Cannot cast mixed to int\\.$#"
|
||||
count: 1
|
||||
path: src/Controllers/BrowseForeignersController.php
|
||||
|
||||
-
|
||||
message: """
|
||||
#^Call to deprecated method getInstance\\(\\) of class PhpMyAdmin\\\\Config\\:
|
||||
|
||||
@ -87,16 +87,6 @@
|
||||
<code><![CDATA[$leftKeyname]]></code>
|
||||
<code><![CDATA[$rightKeyname]]></code>
|
||||
</MixedAssignment>
|
||||
<PossiblyInvalidArgument>
|
||||
<code><![CDATA[$_POST['foreign_filter']]]></code>
|
||||
</PossiblyInvalidArgument>
|
||||
<PossiblyInvalidCast>
|
||||
<code><![CDATA[$_POST['rownumber']]]></code>
|
||||
</PossiblyInvalidCast>
|
||||
<PossiblyInvalidOperand>
|
||||
<code><![CDATA[$pos]]></code>
|
||||
<code><![CDATA[$this->settings->maxRows]]></code>
|
||||
</PossiblyInvalidOperand>
|
||||
</file>
|
||||
<file src="src/Cache.php">
|
||||
<MixedAssignment>
|
||||
|
||||
@ -130,21 +130,24 @@ class BrowseForeigners
|
||||
/**
|
||||
* Function to get html for relational field selection
|
||||
*
|
||||
* @param string $db current database
|
||||
* @param string $table current table
|
||||
* @param string $field field
|
||||
* @param string|null $fieldKey field key
|
||||
* @param string $currentValue current columns's value
|
||||
* @param string $db current database
|
||||
* @param string $table current table
|
||||
* @param string $field field
|
||||
* @param string $fieldKey field key
|
||||
* @param string $currentValue current columns's value
|
||||
*/
|
||||
public function getHtmlForRelationalFieldSelection(
|
||||
string $db,
|
||||
string $table,
|
||||
string $field,
|
||||
ForeignData $foreignData,
|
||||
string|null $fieldKey,
|
||||
string $fieldKey,
|
||||
string $currentValue,
|
||||
int $pos,
|
||||
string $foreignFilter,
|
||||
string|null $rownumber,
|
||||
): string {
|
||||
$gotoPage = $this->getHtmlForGotoPage($foreignData);
|
||||
$gotoPage = $this->getHtmlForGotoPage($foreignData, $pos);
|
||||
$foreignShowAll = '';
|
||||
if (
|
||||
$foreignData->dispRow !== null &&
|
||||
@ -160,16 +163,13 @@ class BrowseForeigners
|
||||
. Url::getHiddenInputs($db, $table) . "\n"
|
||||
. '<input type="hidden" name="field" value="' . htmlspecialchars($field) . '">' . "\n"
|
||||
. '<input type="hidden" name="fieldkey" value="'
|
||||
. (isset($fieldKey) ? htmlspecialchars($fieldKey) : '') . '">' . "\n";
|
||||
. htmlspecialchars($fieldKey) . '">' . "\n";
|
||||
|
||||
if (isset($_POST['rownumber'])) {
|
||||
$output .= '<input type="hidden" name="rownumber" value="'
|
||||
. htmlspecialchars((string) $_POST['rownumber']) . '">';
|
||||
if ($rownumber !== null) {
|
||||
$output .= '<input type="hidden" name="rownumber" value="' . htmlspecialchars($rownumber) . '">';
|
||||
}
|
||||
|
||||
$filterValue = isset($_POST['foreign_filter'])
|
||||
? htmlspecialchars($_POST['foreign_filter'])
|
||||
: '';
|
||||
$filterValue = htmlspecialchars($foreignFilter);
|
||||
$output .= '<div class="col-auto">'
|
||||
. '<label class="form-label" for="input_foreign_filter">' . __('Search:') . '</label></div>' . "\n"
|
||||
. '<div class="col-auto"><input class="form-control" type="text" name="foreign_filter" '
|
||||
@ -238,7 +238,7 @@ class BrowseForeigners
|
||||
*
|
||||
* @param string $description the key name's description
|
||||
*
|
||||
* @return array<int,string> the new description and title
|
||||
* @return array{string, string} the new description and title
|
||||
*/
|
||||
private function getDescriptionAndTitle(string $description): array
|
||||
{
|
||||
@ -255,9 +255,8 @@ class BrowseForeigners
|
||||
/**
|
||||
* Function to get html for the goto page option
|
||||
*/
|
||||
private function getHtmlForGotoPage(ForeignData $foreignData): string
|
||||
private function getHtmlForGotoPage(ForeignData $foreignData, int $pos): string
|
||||
{
|
||||
isset($_POST['pos']) ? $pos = $_POST['pos'] : $pos = 0;
|
||||
if ($foreignData->dispRow === null) {
|
||||
return '';
|
||||
}
|
||||
@ -283,19 +282,12 @@ class BrowseForeigners
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get foreign limit
|
||||
*
|
||||
* @param string|null $foreignShowAll foreign navigation
|
||||
*/
|
||||
public function getForeignLimit(string|null $foreignShowAll): string|null
|
||||
public function getForeignLimit(string|null $foreignShowAll, int $pos): string
|
||||
{
|
||||
if ($foreignShowAll === __('Show all')) {
|
||||
return null;
|
||||
return '';
|
||||
}
|
||||
|
||||
isset($_POST['pos']) ? $pos = $_POST['pos'] : $pos = 0;
|
||||
|
||||
return 'LIMIT ' . $pos . ', ' . $this->settings->maxRows . ' ';
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,6 +38,8 @@ final class BrowseForeignersController implements InvocableController
|
||||
$foreignShowAll = $request->getParsedBodyParam('foreign_showAll');
|
||||
/** @var string $foreignFilter */
|
||||
$foreignFilter = $request->getParsedBodyParam('foreign_filter', '');
|
||||
/** @var string|null $rownumber */
|
||||
$rownumber = $request->getParsedBodyParam('rownumber');
|
||||
|
||||
if (! isset($database, $table, $field)) {
|
||||
return $this->response->response();
|
||||
@ -48,13 +50,14 @@ final class BrowseForeignersController implements InvocableController
|
||||
$header->disableMenuAndConsole();
|
||||
$header->setBodyId('body_browse_foreigners');
|
||||
|
||||
$foreignLimit = $this->browseForeigners->getForeignLimit($foreignShowAll);
|
||||
$pos = (int) $request->getParsedBodyParam('pos');
|
||||
$foreignLimit = $this->browseForeigners->getForeignLimit($foreignShowAll, $pos);
|
||||
$foreignData = $this->relation->getForeignData(
|
||||
$this->relation->getForeigners($database, $table),
|
||||
$field,
|
||||
true,
|
||||
$foreignFilter,
|
||||
$foreignLimit ?? '',
|
||||
$foreignLimit,
|
||||
true,
|
||||
);
|
||||
|
||||
@ -65,6 +68,9 @@ final class BrowseForeignersController implements InvocableController
|
||||
$foreignData,
|
||||
$fieldKey,
|
||||
$data,
|
||||
$pos,
|
||||
$foreignFilter,
|
||||
$rownumber,
|
||||
));
|
||||
|
||||
return $this->response->response();
|
||||
|
||||
@ -31,20 +31,19 @@ class BrowseForeignersTest extends AbstractTestCase
|
||||
*/
|
||||
public function testGetForeignLimit(): void
|
||||
{
|
||||
self::assertNull(
|
||||
$this->browseForeigners->getForeignLimit('Show all'),
|
||||
self::assertSame(
|
||||
'',
|
||||
$this->browseForeigners->getForeignLimit('Show all', 0),
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
'LIMIT 0, 25 ',
|
||||
$this->browseForeigners->getForeignLimit(null),
|
||||
$this->browseForeigners->getForeignLimit(null, 0),
|
||||
);
|
||||
|
||||
$_POST['pos'] = 10;
|
||||
|
||||
self::assertSame(
|
||||
'LIMIT 10, 25 ',
|
||||
$this->browseForeigners->getForeignLimit(null),
|
||||
$this->browseForeigners->getForeignLimit(null, 10),
|
||||
);
|
||||
|
||||
$config = new Config();
|
||||
@ -53,12 +52,12 @@ class BrowseForeignersTest extends AbstractTestCase
|
||||
|
||||
self::assertSame(
|
||||
'LIMIT 10, 50 ',
|
||||
$browseForeigners->getForeignLimit(null),
|
||||
$browseForeigners->getForeignLimit(null, 10),
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
'LIMIT 10, 50 ',
|
||||
$browseForeigners->getForeignLimit('xyz'),
|
||||
$browseForeigners->getForeignLimit('xyz', 10),
|
||||
);
|
||||
}
|
||||
|
||||
@ -74,11 +73,10 @@ class BrowseForeignersTest extends AbstractTestCase
|
||||
$this->browseForeigners,
|
||||
BrowseForeigners::class,
|
||||
'getHtmlForGotoPage',
|
||||
[$foreignData],
|
||||
[$foreignData, 0],
|
||||
),
|
||||
);
|
||||
|
||||
$_POST['pos'] = 15;
|
||||
$foreignData = new ForeignData(false, 5, '', [], '');
|
||||
|
||||
self::assertSame(
|
||||
@ -87,7 +85,7 @@ class BrowseForeignersTest extends AbstractTestCase
|
||||
$this->browseForeigners,
|
||||
BrowseForeigners::class,
|
||||
'getHtmlForGotoPage',
|
||||
[$foreignData],
|
||||
[$foreignData, 15],
|
||||
),
|
||||
);
|
||||
|
||||
@ -96,7 +94,7 @@ class BrowseForeignersTest extends AbstractTestCase
|
||||
$this->browseForeigners,
|
||||
BrowseForeigners::class,
|
||||
'getHtmlForGotoPage',
|
||||
[$foreignData],
|
||||
[$foreignData, 15],
|
||||
);
|
||||
|
||||
self::assertStringStartsWith('Page number:', $result);
|
||||
@ -153,8 +151,8 @@ class BrowseForeignersTest extends AbstractTestCase
|
||||
$foreignData = new ForeignData(false, 0, '', null, '');
|
||||
$fieldkey = 'bar';
|
||||
$currentValue = '';
|
||||
$_POST['rownumber'] = 1;
|
||||
$_POST['foreign_filter'] = '5';
|
||||
$rownumber = '1';
|
||||
$foreignFilter = '5';
|
||||
$result = $this->browseForeigners->getHtmlForRelationalFieldSelection(
|
||||
$db,
|
||||
$table,
|
||||
@ -162,6 +160,9 @@ class BrowseForeignersTest extends AbstractTestCase
|
||||
$foreignData,
|
||||
$fieldkey,
|
||||
$currentValue,
|
||||
0,
|
||||
$foreignFilter,
|
||||
$rownumber,
|
||||
);
|
||||
|
||||
self::assertStringContainsString(
|
||||
@ -206,6 +207,9 @@ class BrowseForeignersTest extends AbstractTestCase
|
||||
$foreignData,
|
||||
$fieldkey,
|
||||
$currentValue,
|
||||
0,
|
||||
$foreignFilter,
|
||||
$rownumber,
|
||||
);
|
||||
|
||||
self::assertStringContainsString(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user