Completed
Push — master ( 3599e8...a4b34c )
by Rougin
05:04
created

File   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 5
c 4
b 0
f 1
lcom 2
cbo 0
dl 0
loc 64
ccs 12
cts 12
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A close() 0 4 1
A getContents() 0 4 1
A putContents() 0 4 1
A chmod() 0 4 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 pointer
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 45
    public function __construct($path, $mode = 'wb')
30
    {
31 45
        $this->path = $path;
32 45
        $this->file = fopen($path, $mode);
0 ignored issues
show
Documentation Bug introduced by
It seems like fopen($path, $mode) of type resource is incompatible with the declared type object<Rougin\Combustor\Common\pointer> of property $file.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
33 45
    }
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 30
    public function getContents()
51
    {
52 30
        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