Passed
Push — main ( 199c59...bc8763 )
by Daniel
10:26
created

DiscLengthUpdater::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Component\Disc;
6
7
use Uxmp\Core\Orm\Model\DiscInterface;
8
use Uxmp\Core\Orm\Repository\DiscRepositoryInterface;
9
10
final class DiscLengthUpdater implements DiscLengthUpdaterInterface
11
{
12 1
    public function __construct(
13
        private DiscRepositoryInterface $discRepository
14
    ) {
15 1
    }
16
17 1
    public function update(
18
        DiscInterface $disc,
19
    ): void {
20 1
        $length = 0;
21
22 1
        foreach ($disc->getSongs() as $song) {
23 1
            $length += $song->getLength();
24
        }
25
26 1
        $disc->setLength($length);
27
28 1
        $this->discRepository->save($disc);
29 1
    }
30
}
31