Test Failed
Pull Request — master (#10)
by Yo
02:35
created

ConfigurationWriter   A

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
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 36
rs 10

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 ConfigurationWriter implements ConfigurationWriterInterface
10
{
11
    const FILENAME = 'composer.json';
12
13
    /** @var SerializerInterface */
14
    private $serializer;
15
    /** @var Filesystem */
16
    private $filesystem;
17
18
    /**
19
     * @param SerializerInterface $serializer
20
     * @param Filesystem          $filesystem
21
     */
22
    public function __construct(SerializerInterface $serializer, Filesystem $filesystem)
23
    {
24
        $this->serializer = $serializer;
25
        $this->filesystem = $filesystem;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function write(Configuration $configuration, $destinationPath)
32
    {
33
        $data = $this->serializer->serialize($configuration, 'composer');
34
35
        $filename = sprintf(
36
            '%s%s%s',
37
            trim($destinationPath, DIRECTORY_SEPARATOR),
38
            DIRECTORY_SEPARATOR,
39
            self::FILENAME
40
        );
41
42
        $this->filesystem->dumpFile($filename, $data);
43
    }
44
}
45