Passed
Pull Request — master (#1266)
by Matthew
03:51
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 Matthew Wells
10
 * @copyright Matthew Wells 2025
11
 */
12
13
namespace OCA\Music\Hooks;
14
15
use OCA\Music\BusinessLayer\TrackBusinessLayer;
16
use OCA\Music\Service\ScrobblerService;
17
18
class TrackHooks {
19
	private TrackBusinessLayer $trackBusinessLayer;
20
21
	private ScrobblerService $scrobblerService;
22
23
	public function __construct(TrackBusinessLayer $trackBusinessLayer, ScrobblerService $scrobblerService) {
24
		$this->trackBusinessLayer = $trackBusinessLayer;
25
		$this->scrobblerService = $scrobblerService;
26
	}
27
28
	public function register() : void {
29
		$this->trackBusinessLayer->listen(
30
			TrackBusinessLayer::class,
31
			'recordTrackPlayed',
32
			fn (int $trackId, string $userId, \DateTime $timeOfPlay) => $this->scrobble($trackId, $userId, $timeOfPlay)
33
		);
34
	}
35
36
	private function scrobble(int $trackId, string $userId, \DateTime $timeOfPlay) : void {
37
		$this->scrobblerService->scrobbleTrack([$trackId], $userId, $timeOfPlay);
38
	}
39
}
40