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

DefaultWriter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 34
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A write() 0 13 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