Test Setup Failed
Push — master ( 0a8e7c...aa7267 )
by Phan
03:42
created

app/Listeners/LoveTrackOnLastfm.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace App\Listeners;
4
5
use App\Events\SongLikeToggled;
6
use App\Services\Lastfm;
7
8
class LoveTrackOnLastfm
9
{
10
    /**
11
     * The Last.fm service instance, which is DI'ed into our listener.
12
     *
13
     * @var Lastfm
14
     */
15
    protected $lastfm;
16
17
    /**
18
     * Create the event listener.
19
     *
20
     * @param Lastfm $lastfm
21
     */
22
    public function __construct(Lastfm $lastfm)
23
    {
24
        $this->lastfm = $lastfm;
25
    }
26
27
    /**
28
     * Handle the event.
29
     *
30
     * @param SongLikeToggled $event
31
     */
32
    public function handle(SongLikeToggled $event)
33
    {
34 View Code Duplication
        if (!$this->lastfm->enabled() ||
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
            !($sessionKey = $event->user->lastfm_session_key) ||
36
            $event->interaction->song->album->artist->isUnknown()
37
        ) {
38
            return;
39
        }
40
41
        $this->lastfm->toggleLoveTrack(
42
            $event->interaction->song->title,
43
            $event->interaction->song->album->artist->name,
44
            $sessionKey,
45
            $event->interaction->liked
46
        );
47
    }
48
}
49