Filesystem::write()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of Bowerphp.
5
 *
6
 * (c) Massimiliano Arione <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bowerphp\Util;
13
14
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
15
use Symfony\Component\Filesystem\Filesystem as BaseFilesystem;
16
17
/**
18
 * Filesystem
19
 */
20
class Filesystem extends BaseFilesystem
21
{
22
    /**
23
     * Read a file
24
     *
25
     * @param string $filename
26
     *
27
     * @return string
28
     */
29
    public function read($filename)
30
    {
31
        if (!is_readable($filename)) {
32
            throw new FileNotFoundException(sprintf('File "%s" does not exist.', $filename), 0, null, $filename);
33
        }
34
35
        return file_get_contents($filename);
36
    }
37
38
    /**
39
     * Write a file
40
     *
41
     * @param string $filename The file to be written to
42
     * @param string $content  The data to write into the file
43
     * @param int    $mode     The file mode (octal)
44
     *
45
     * @throws \Symfony\Component\Filesystem\Exception\IOException If the file cannot be written to
46
     */
47
    public function write($filename, $content, $mode = 0644)
48
    {
49
        $this->dumpFile($filename, $content);
50
    }
51
}
52