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

SettingsWriter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 47
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A write() 0 6 1
A isWritable() 0 4 1
A convertToArray() 0 6 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