LoveTrackOnLastfm   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 5
eloc 12
c 0
b 0
f 0
dl 0
loc 23
ccs 12
cts 13
cp 0.9231
rs 10

2 Methods

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