FileDumper::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Workout\Dumper;
6
7
use Assert\Assertion;
8
use SportTrackerConnector\Core\Workout\Dumper\DumperInterface;
9
use SportTrackerConnector\Core\Workout\Workout;
10
11
final class FileDumper implements DumperInterface
12
{
13
    /**
14
     * @var DumperInterface
15
     */
16
    private $dumper;
17
18
    /**
19
     * @var string
20
     */
21
    private $outputFile;
22
23
    /**
24
     * @param DumperInterface $dumper
25
     * @param string $outputFile
26
     */
27
    public function __construct(DumperInterface $dumper, string $outputFile)
28
    {
29
        Assertion::writeable($outputFile);
30
31
        $this->dumper = $dumper;
32
        $this->outputFile = $outputFile;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function dump(Workout $workout): string
39
    {
40
        $dump = $this->dumper->dump($workout);
41
42
        file_put_contents($this->outputFile, $dump);
43
44
        return $dump;
45
    }
46
}
47