Passed
Pull Request — master (#1266)
by Matthew
04:19
created

TrackHooks::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * ownCloud - Music app
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Morris Jobke <[email protected]>
10
 * @author Pauli Järvinen <[email protected]>
11
 * @copyright Morris Jobke 2014
12
 * @copyright Pauli Järvinen 2017 - 2025
13
 */
14
15
namespace OCA\Music\Hooks;
16
17
use OCA\Music\BusinessLayer\TrackBusinessLayer;
18
use OCA\Music\Service\ScrobblerService;
19
20
class TrackHooks {
21
	private TrackBusinessLayer $trackBusinessLayer;
22
23
	private ScrobblerService $scrobblerService;
24
25
	public function __construct(TrackBusinessLayer $trackBusinessLayer, ScrobblerService $scrobblerService) {
26
		$this->trackBusinessLayer = $trackBusinessLayer;
27
		$this->scrobblerService = $scrobblerService;
28
	}
29
30
	public function register() : void {
31
		$this->trackBusinessLayer->listen(
32
			TrackBusinessLayer::class,
33
			'recordTrackPlayed',
34
			fn (int $trackId, string $userId, \DateTime $timeOfPlay) => $this->scrobble($trackId, $userId, $timeOfPlay)
35
		);
36
	}
37
38
	private function scrobble(int $trackId, string $userId, \DateTime $timeOfPlay) : void {
39
		$this->scrobblerService->scrobbleTrack([$trackId], $userId, $timeOfPlay);
40
	}
41
}
42