LoveTrackOnLastfm::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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