Skip to content

Commit 3b4b32d

Browse files
committed
wip
1 parent 72048a3 commit 3b4b32d

1 file changed

Lines changed: 25 additions & 38 deletions

File tree

app/Models/Speaking.php

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,11 @@ protected function speaking(Builder $query): void
6767
/** @return array<int, array<string, mixed>> */
6868
public function getRows(): array
6969
{
70-
/** @var Collection<int, array<string, mixed>> $collection */
71-
$collection = collect(iterator_to_array($this->files()))
72-
->map(fn (SplFileInfo $file): array => $this->parseFile($file))
73-
->values();
74-
75-
$collectionWithTranscripts = $this->transcriptPath($collection);
76-
7770
/** @var array<int, array<string, mixed>> */
78-
return $collectionWithTranscripts
71+
return collect(iterator_to_array($this->files()))
72+
->map(fn (SplFileInfo $file): array => $this->parseFile($file))
73+
->values()
74+
->pipe(fn (Collection $items): Collection => $this->transcriptPath($items))
7975
->sortBy('published_at')
8076
->values()
8177
->toArray();
@@ -140,39 +136,28 @@ protected function transcriptPath(Collection $items): Collection
140136
/** @return Attribute<string|null, never> */
141137
protected function videoThumbnail(): Attribute
142138
{
143-
/** @var Attribute<string|null, never> */
144-
return new Attribute(
145-
get: function (): ?string {
146-
$id = $this->youtubeId();
147-
148-
return $id ? "https://img.youtube.com/vi/{$id}/mqdefault.jpg" : null;
149-
}
139+
return Attribute::make(
140+
get: fn (): ?string => ($id = $this->youtubeId())
141+
? "https://img.youtube.com/vi/{$id}/mqdefault.jpg"
142+
: null,
150143
);
151144
}
152145

153146
/** @return Attribute<string|null, never> */
154147
protected function videoEmbedUrl(): Attribute
155148
{
156-
/** @var Attribute<string|null, never> */
157-
return new Attribute(
158-
get: function (): ?string {
159-
$id = $this->youtubeId();
160-
161-
return $id ? "https://www.youtube.com/embed/{$id}" : null;
162-
}
149+
return Attribute::make(
150+
get: fn (): ?string => ($id = $this->youtubeId())
151+
? "https://www.youtube.com/embed/{$id}"
152+
: null,
163153
);
164154
}
165155

166156
/** @return Attribute<string|null, never> */
167157
protected function durationMmss(): Attribute
168158
{
169159
return Attribute::make(
170-
get: function (): string {
171-
$duration = $this->getAttribute('duration');
172-
$durationInt = is_int($duration) ? $duration : 0;
173-
174-
return $this->formatDuration($durationInt);
175-
}
160+
get: fn (): string => $this->formatDuration((int) ($this->duration ?? 0)),
176161
);
177162
}
178163

@@ -193,11 +178,15 @@ protected function contextName(): Attribute
193178
{
194179
return Attribute::make(
195180
get: function (): ?string {
196-
$showName = $this->getAttribute('show_name');
181+
$showName = $this->show_name;
197182
$eventName = $this->getAttribute('event_name');
198183

199-
return is_string($showName) ? $showName : (is_string($eventName) ? $eventName : null);
200-
}
184+
return match (true) {
185+
is_string($showName) => $showName,
186+
is_string($eventName) => $eventName,
187+
default => null,
188+
};
189+
},
201190
);
202191
}
203192

@@ -227,12 +216,10 @@ private function youtubeId(): ?string
227216

228217
public function toSitemapTag(): Url
229218
{
230-
$url = Url::create("/speaking/{$this->slug}");
231-
232-
if ($this->published_at) {
233-
$url->setLastModificationDate($this->published_at);
234-
}
235-
236-
return $url;
219+
return tap(Url::create("/speaking/{$this->slug}"), function (Url $url): void {
220+
if ($this->published_at) {
221+
$url->setLastModificationDate($this->published_at);
222+
}
223+
});
237224
}
238225
}

0 commit comments

Comments
 (0)