Completed
Push — master ( ea1059...a4c072 )
by Rougin
04:55
created

File::getContents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Rougin\Combustor\Common;
4
5
/**
6
 * File
7
 *
8
 * A simple object-oriented interface for handling files.
9
 *
10
 * @package Combustor
11
 * @author  Rougin Royce Gutib <[email protected]>
12
 */
13
class File
14
{
15
    /**
16
     * @var resource
17
     */
18
    protected $file;
19
20
    /**
21
     * @var string
22
     */
23
    protected $path;
24
25
    /**
26
     * @param string $path
27
     * @param string $mode
28
     */
29 48
    public function __construct($path, $mode = 'wb')
30
    {
31 48
        $this->path = $path;
32 48
        $this->file = fopen($path, $mode);
33 48
    }
34
35
    /**
36
     * Closes an open file pointer.
37
     *
38
     * @return boolean
39
     */
40 45
    public function close()
41
    {
42 45
        return fclose($this->file);
43
    }
44
45
    /**
46
     * Reads entire file into a string.
47
     *
48
     * @return string
49
     */
50 3
    public function getContents()
51
    {
52 3
        return file_get_contents($this->path);
53
    }
54
55
    /**
56
     * Writes a string to a file.
57
     *
58
     * @param  string $content
59
     * @return integer|boolean
60
     */
61 45
    public function putContents($content)
62
    {
63 45
        return file_put_contents($this->path, $content);
64
    }
65
66
    /**
67
     * Changes the file mode of the file.
68
     *
69
     * @param  integer $mode
70
     * @return boolean
71
     */
72 30
    public function chmod($mode)
73
    {
74 30
        return chmod($this->path, $mode);
75
    }
76
}
77