Skip to content

Commit

Permalink
rex_list: refactor logic into new getColumnValue() method (#5828)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Sep 30, 2023
1 parent d194b34 commit 427f734
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
10 changes: 0 additions & 10 deletions .tools/phpstan/baseline.neon
Expand Up @@ -1900,11 +1900,6 @@ parameters:
count: 1
path: ../../redaxo/src/core/lib/list.php

-
message: "#^Method rex_list\\:\\:getColumnFormat\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../redaxo/src/core/lib/list.php

-
message: "#^Method rex_list\\:\\:getColumnLayout\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -1990,11 +1985,6 @@ parameters:
count: 1
path: ../../redaxo/src/core/lib/list.php

-
message: "#^Property rex_list\\:\\:\\$columnFormates type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../redaxo/src/core/lib/list.php

-
message: "#^Property rex_list\\:\\:\\$columnParams type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
3 changes: 0 additions & 3 deletions .tools/psalm/baseline.xml
Expand Up @@ -4057,7 +4057,6 @@
<MixedInferredReturnType>
<code>array</code>
<code><![CDATA[array<string, string|int>|null]]></code>
<code>array|null</code>
<code>string|null</code>
</MixedInferredReturnType>
<MixedOperand>
Expand All @@ -4071,8 +4070,6 @@
<code><![CDATA[$this->linkAttributes]]></code>
</MixedPropertyTypeCoercion>
<MixedReturnStatement>
<code><![CDATA[$this->columnFormates[$columnName] ?? $default]]></code>
<code><![CDATA[$this->columnFormates[$columnName] ?? $default]]></code>
<code><![CDATA[$this->columnNames[$columnIndex] ?? $default]]></code>
<code><![CDATA[$this->columnNames[$columnIndex] ?? $default]]></code>
<code><![CDATA[$this->linkAttributes[$column] ?? $default]]></code>
Expand Down
28 changes: 23 additions & 5 deletions redaxo/src/core/lib/list.php
Expand Up @@ -86,7 +86,7 @@ class rex_list implements rex_url_provider_interface
private $columnNames;
/** @var array<string, string> */
private $columnLabels;
/** @var array<string, array{string, mixed, array}> */
/** @var array<string, array{string, mixed, array<mixed>}> */
private $columnFormates;
/** @var array<string, array<string|int, mixed>> */
private $columnOptions;
Expand Down Expand Up @@ -513,6 +513,21 @@ protected function getEnabledColumnNames(): array
return $columnNames;
}

/**
* @param string $columnName
* @param null|array{string, mixed, array<mixed>} $columnFormat
* @return string
*/
protected function getColumnValue($columnName, $columnFormat)
{
return $this->formatValue(
$this->getValue($columnName),
$columnFormat,
!isset($this->customColumns[$columnName]),
$columnName,
);
}

/**
* Setzt ein Label für eine Spalte.
*
Expand Down Expand Up @@ -559,10 +574,12 @@ public function setColumnFormat($columnName, $formatType, $format = '', array $p
/**
* Gibt das Format für eine Spalte zurück.
*
* @template T
*
* @param string $columnName Name der Spalte
* @param mixed $default Defaultrückgabewert, falls keine Formatierung gesetzt ist
* @param T $default Defaultrückgabewert, falls keine Formatierung gesetzt ist
*
* @return array|null
* @return array{string, mixed, array<mixed>}|T
*/
public function getColumnFormat($columnName, $default = null)
{
Expand Down Expand Up @@ -1276,9 +1293,10 @@ public function get()

$s .= ' <tr' . $rowAttributes . ">\n";
foreach ($columnNames as $columnName) {
$columnValue = $this->formatValue($this->getValue($columnName), $columnFormates[$columnName], !isset($this->customColumns[$columnName]), $columnName);
$columnFormat = $columnFormates[$columnName];
$columnValue = $this->getColumnValue($columnName, $columnFormat);

if (!$this->isCustomFormat($columnFormates[$columnName]) && $this->hasColumnParams($columnName)) {
if (!$this->isCustomFormat($columnFormat) && $this->hasColumnParams($columnName)) {
$columnValue = $this->getColumnLink($columnName, $columnValue);
}

Expand Down

0 comments on commit 427f734

Please sign in to comment.