| Conditions | 1 |
| Paths | 1 |
| Total Lines | 18 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 1 |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | 3 | public function recommendEpisodesForPost(Post $post, int $amount): AudioEpisodeCollection |
|
| 20 | { |
||
| 21 | 3 | $tags = $post->tags() ?? []; |
|
| 22 | |||
| 23 | 3 | $recommended = $this->postRepository |
|
| 24 | 3 | ->withAudio() |
|
| 25 | ->filter(function (AudioEpisode $episode) use ($post) { |
||
| 26 | 3 | return $post->guid() !== $episode->guid(); |
|
| 27 | 3 | }) |
|
| 28 | ->sortByDesc(function (AudioEpisode $episode) { |
||
| 29 | 3 | return $episode->createdAt(); |
|
| 30 | 3 | }) |
|
| 31 | ->sortByDesc(function (AudioEpisode $episode) use ($tags) { |
||
| 32 | 3 | return count(array_intersect($episode->tags() ?? [], $tags)); |
|
| 33 | 3 | }) |
|
| 34 | 3 | ->take($amount); |
|
| 35 | |||
| 36 | 3 | return new AudioEpisodeCollection($recommended); |
|
| 37 | } |
||
| 39 |