Skip to content

Commit

Permalink
remove one line if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoLouwerse committed Nov 10, 2023
1 parent 8e9b129 commit b84ab13
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions api/src/Repository/ObjectEntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public function getFilterParameters(Entity $Entity, string $prefix = '', int $le
$filters[] = $prefix.$attribute->getName();
} elseif ($attribute->getObject() && $level < 3 && !str_contains($prefix, $attribute->getName().'.')) {
$attribute->getSearchable() && $filters[] = $prefix.$attribute->getName();
$embeddedString = $embedded && $level > 1 ? 'embedded.' : '';
$embeddedString = '';
if ($embedded && $level > 1) {
$embeddedString = 'embedded.';
}
$filters = array_merge($filters, $this->getFilterParameters($attribute->getObject(), $prefix.$embeddedString.$attribute->getName().'.', $level + 1, $embedded));
}
}
Expand All @@ -86,15 +89,21 @@ public function getFilterParameters(Entity $Entity, string $prefix = '', int $le
*/
public function getOrderParameters(Entity $Entity, string $prefix = '', int $level = 1, bool $embedded = false): array
{
$prefix = $embedded && $level === 2 ? "embedded.$prefix" : $prefix;
$prefix = $prefix;
if ($embedded && $level === 2) {
$prefix = "embedded.$prefix";
}
// defaults
$sortable = [$prefix.'_dateCreated', $prefix.'_dateModified'];

foreach ($Entity->getAttributes() as $attribute) {
if (in_array($attribute->getType(), ['string', 'date', 'datetime', 'integer', 'float', 'number']) && $attribute->getSortable()) {
$sortable[] = $prefix.$attribute->getName();
} elseif ($attribute->getObject() && $level < 3 && !str_contains($prefix, $attribute->getName().'.')) {
$embeddedString = $embedded && $level > 1 ? 'embedded.' : '';
$embeddedString = '';
if ($embedded && $level > 1) {
$embeddedString = 'embedded.';
}
$sortable = array_merge($sortable, $this->getOrderParameters($attribute->getObject(), $prefix.$embeddedString.$attribute->getName().'.', $level + 1));
}
}
Expand Down

0 comments on commit b84ab13

Please sign in to comment.