Skip to content

Commit

Permalink
Cleanup: Reduce complexity of getSizesAndMultiplierFromRootline()
Browse files Browse the repository at this point in the history
  • Loading branch information
d-g-codappix committed Apr 4, 2024
1 parent 5a9a3de commit 3e4c5fa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Classes/Sizes/AbstractContentElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ protected function readConfigurationByPath(string $configurationPath): array

if (is_array($configuration)) {
if (isset($configuration['multiplier'])) {
$multiplier = array_map(static fn($multiplier): float => Multiplier::parse($multiplier), $configuration['multiplier']);
$multiplier = array_map(static fn ($multiplier): float => Multiplier::parse($multiplier), $configuration['multiplier']);
}

if (isset($configuration['sizes'])) {
$sizes = array_map(static fn($size): int => (int)$size, $configuration['sizes']);
$sizes = array_map(static fn ($size): int => (int) $size, $configuration['sizes']);
}
}

Expand Down
1 change: 0 additions & 1 deletion Classes/Sizes/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public function readConfiguration(): void
$this->contentType,
]);


[$multiplier, $sizes] = $this->readConfigurationByPath($configurationPath);

$this->multiplier = $multiplier;
Expand Down
50 changes: 31 additions & 19 deletions Classes/Sizes/Rootline.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,32 @@ public function getFinalSizes(): array
return $this->finalSizes;
}

public function getSizesAndMultiplierFromContentElement(
mixed $contentElement,
array $sizes,
array $multiplier
): array {
if ($contentElement instanceof ContentElementInterface) {
if ($contentElement instanceof Container) {
$sizes = $contentElement->getActiveColumn()->getSizes();
if (!empty($sizes)) {
return [$sizes, $multiplier];
}

$multiplier[] = $contentElement->getActiveColumn()->getMultiplier();
}

$sizes = $contentElement->getSizes();
if (!empty($sizes)) {
return [$sizes, $multiplier];
}

$multiplier[] = $contentElement->getMultiplier();
}

return [$sizes, $multiplier];
}

private function determineBackendLayout(): void
{
$typoscriptFrontendController = $GLOBALS['TSFE'];
Expand Down Expand Up @@ -144,31 +170,17 @@ private function calculateSizes(): void
private function getSizesAndMultiplierFromRootline(): array
{
$multiplier = [];
$sizes = [];

foreach ($this->rootline as $contentElement) {
if ($contentElement instanceof ContentElementInterface) {
if ($contentElement instanceof Container) {
$sizes = $contentElement->getActiveColumn()->getSizes();
if (!empty($sizes)) {
break;
}

$multiplier[] = $contentElement->getActiveColumn()->getMultiplier();
}
$sizes = [];
[$sizes, $multiplier] = $this->getSizesAndMultiplierFromContentElement($contentElement, $sizes, $multiplier);

$sizes = $contentElement->getSizes();
if (!empty($sizes)) {
break;
}

$multiplier[] = $contentElement->getMultiplier();
if (!empty($sizes)) {
return [$sizes, $multiplier];
}
}

if (empty($sizes)) {
$sizes = $this->backendLayout->getSizes();
}
$sizes = $this->backendLayout->getSizes();

return [$sizes, $multiplier];
}
Expand Down

0 comments on commit 3e4c5fa

Please sign in to comment.