Completed
Push — master ( d30cdc...16fa4d )
by Filip
05:56 queued 05:01
created

AbstractWriter::toFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Noodlehaus\Writer;
4
5
use Noodlehaus\Exception\WriteException;
6
7
/**
8
 * Base Writer.
9
 *
10
 * @package    Config
11
 * @author     Jesus A. Domingo <[email protected]>
12
 * @author     Hassan Khan <[email protected]>
13
 * @author     Filip Š <[email protected]>
14
 * @author     Mark de Groot <[email protected]>
15
 * @link       https://github.com/noodlehaus/config
16
 * @license    MIT
17
 */
18
abstract class AbstractWriter implements WriterInterface
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23 18
    public function toFile($config, $filename)
24
    {
25 18
        $contents = $this->toString($config);
26 18
        $success = @file_put_contents($filename, $contents);
27 18
        if ($success === false) {
28 9
            throw new WriteException(['file' => $filename]);
29
        }
30
31 9
        return $contents;
32
    }
33
}
34