UpdateLastfmNowPlaying   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 6
eloc 13
c 0
b 0
f 0
dl 0
loc 24
ccs 13
cts 14
cp 0.9286
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 15 5
A __construct() 0 3 1
1
<?php
2
3
namespace App\Listeners;
4
5
use App\Events\SongStartedPlaying;
6
use App\Models\Album;
7
use App\Services\LastfmService;
8
9
class UpdateLastfmNowPlaying
10
{
11
    private $lastfm;
12
13 1
    public function __construct(LastfmService $lastfm)
14
    {
15 1
        $this->lastfm = $lastfm;
16 1
    }
17
18 1
    public function handle(SongStartedPlaying $event): void
19
    {
20 1
        if (!$this->lastfm->enabled() ||
21 1
            !($sessionKey = $event->user->lastfm_session_key) ||
22 1
            $event->song->artist->is_unknown
23
        ) {
24
            return;
25
        }
26
27 1
        $this->lastfm->updateNowPlaying(
28 1
            $event->song->artist->name,
29 1
            $event->song->title,
30 1
            $event->song->album->name === Album::UNKNOWN_NAME ? '' : $event->song->album->name,
31 1
            $event->song->length,
32 1
            $sessionKey
33
        );
34 1
    }
35
}
36