Completed
Push — master ( 77675a...fe304c )
by Yo
02:42
created

ConfigurationFileWriter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
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 36
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\ConfigurationFileWriterInterface;
7
use Yoanm\ComposerConfigManager\Domain\Model\ConfigurationFile;
8
9
class ConfigurationFileWriter implements ConfigurationFileWriterInterface
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 1
    public function __construct(SerializerInterface $serializer, Filesystem $filesystem)
23
    {
24 1
        $this->serializer = $serializer;
25 1
        $this->filesystem = $filesystem;
26 1
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    public function write(ConfigurationFile $configurationFile, $destinationPath)
32
    {
33 1
        $data = $this->serializer->serialize($configurationFile, 'composer');
34
35 1
        $filename = sprintf(
36 1
            '%s%s%s',
37 1
            trim($destinationPath, DIRECTORY_SEPARATOR),
38 1
            DIRECTORY_SEPARATOR,
39
            self::FILENAME
40 1
        );
41
42 1
        $this->filesystem->dumpFile($filename, $data);
43 1
    }
44
}
45