Passed
Pull Request — master (#5)
by Yo
02:29
created

DefaultWriter::write()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 2
crap 1
1
<?php
2
namespace Yoanm\ComposerConfigManager\Infrastructure\Writer;
3
4
use Symfony\Component\Filesystem\Filesystem;
5
use Symfony\Component\Serializer\SerializerInterface;
6
use Yoanm\ComposerConfigManager\Application\Writer\ConfigurationWriterInterface;
7
use Yoanm\ComposerConfigManager\Domain\Model\Configuration;
8
9
class DefaultWriter implements ConfigurationWriterInterface
10
{
11
    /** @var SerializerInterface */
12
    private $serializer;
13
    /** @var Filesystem */
14
    private $filesystem;
15
16
    /**
17
     * @param SerializerInterface $serializer
18
     * @param Filesystem          $filesystem
19
     */
20 1
    public function __construct(SerializerInterface $serializer, Filesystem $filesystem)
21
    {
22 1
        $this->serializer = $serializer;
23 1
        $this->filesystem = $filesystem;
24 1
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    public function write(Configuration $configuration, $destinationPath)
30
    {
31 1
        $data = $this->serializer->serialize($configuration, 'composer');
32
33 1
        $filename = sprintf(
34 1
            '%s%s%s',
35 1
            trim($destinationPath, DIRECTORY_SEPARATOR),
36 1
            DIRECTORY_SEPARATOR,
37
            self::FILENAME
38 1
        );
39
40 1
        $this->filesystem->dumpFile($filename, $data);
41 1
    }
42
}
43