Completed
Push — master ( 265a2d...f9e310 )
by jerome
05:38 queued 02:58
created

SettingsWriter::write()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace DP\Core\CoreBundle\Settings;
4
5
use Symfony\Component\Yaml\Yaml;
6
7
class SettingsWriter
8
{
9
    /**
10
     * @var string
11
     */
12
    private $filePath;
13
14
    /**
15
     * @param string $filePath
16
     */
17
    public function __construct($filePath)
18
    {
19
        $this->filePath = $filePath;
20
    }
21
22
    /**
23
     * @param Settings $settings
24
     *
25
     * @return bool
26
     */
27
    public function write(Settings $settings)
28
    {
29
        $yaml = Yaml::dump($this->convertToArray($settings), 2);
30
31
        return (bool) file_put_contents($this->filePath, $yaml);
32
    }
33
34
    /**
35
     * @return bool
36
     */
37
    public function isWritable()
38
    {
39
        return is_writable($this->filePath);
40
    }
41
42
    /**
43
     * @param Settings $settings
44
     *
45
     * @return array
46
     */
47
    private function convertToArray(Settings $settings)
48
    {
49
        return [
50
            'debug' => (bool) $settings->getDebug(),
51
        ];
52
    }
53
}
54