FileDumper   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A dump() 0 8 1
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