Skip to content

Commit ae6957f

Browse files
zeezo887ifox
authored andcommitted
Refactor endpoint initialization and remove redundant checks
1 parent 74aca54 commit ae6957f

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/View/Components/Fields/Browser.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public function __construct(
5050
default: $default
5151
);
5252

53-
if (!$this->endpoints) {
54-
$endpointsFromModules = isset($this->modules) ? collect($this->modules)->map(function ($module) {
53+
if (!$this->endpoints && isset($this->modules)) {
54+
$this->endpoints = collect($this->modules)->map(function ($module) {
5555
return [
5656
'label' => $module['label'] ?? ucfirst($module['name']),
5757
'value' => moduleRoute(
@@ -62,16 +62,14 @@ public function __construct(
6262
false
6363
),
6464
];
65-
})->toArray() : null;
65+
})->toArray();
6666
}
6767

68-
$this->endpoints = $this->endpoints === [] ? $endpointsFromModules ?? [] : [];
69-
7068
if (empty($this->endpoints)) {
71-
$routeEndpoint = $this->moduleName;
72-
if ($this->routePrefix) {
73-
$routeEndpoint = Str::replaceFirst($this->routePrefix . '.', '', $this->moduleName);
74-
}
69+
$routeEndpoint = $this->routePrefix
70+
? Str::replaceFirst($this->routePrefix . '.', '', $this->moduleName)
71+
: $this->moduleName;
72+
7573
$this->endpoint = $this->endpoint ?? (empty($endpoints) ? moduleRoute(
7674
// Remove the route prefix from the moduleName.
7775
$routeEndpoint,

0 commit comments

Comments
 (0)