1 | <?php |
||
22 | class File implements ConnectorInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var resource|bool The file pointer to send data to. |
||
26 | */ |
||
27 | protected $resource = false; |
||
28 | |||
29 | /** |
||
30 | * Construct new connector, given a filename |
||
31 | * If created a binary file must be granted the necessary |
||
32 | * permissions to create and write the system file |
||
33 | * @param string|null $filename |
||
34 | */ |
||
35 | public function __construct($filename = null) |
||
36 | 8 | { |
|
37 | if (!is_null($filename) && empty($filename)) { |
||
38 | 8 | throw new InvalidArgumentException("A filename must be passed!"); |
|
39 | 1 | } |
|
40 | if (!is_null($filename)) { |
||
41 | 7 | $command = 'rb+'; |
|
42 | 7 | if (!is_file($filename)) { |
|
43 | 1 | $command = 'wb+'; |
|
44 | 1 | } |
|
45 | 7 | $this->resource = @fopen($filename, $command); |
|
46 | 7 | if ($this->resource === false) { |
|
47 | 1 | throw new RuntimeException("Failed to open the file. Check the permissions!"); |
|
48 | } |
||
49 | 6 | } |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * Destruct conection closing the file |
||
54 | 6 | */ |
|
55 | public function __destruct() |
||
56 | 6 | { |
|
57 | 5 | if ($this->resource != false) { |
|
58 | 5 | $this->close(); |
|
59 | 6 | } |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Close file pointer |
||
64 | 6 | */ |
|
65 | public function close() |
||
66 | 6 | { |
|
67 | 6 | if (is_resource($this->resource)) { |
|
68 | if (! @fclose($this->resource)) { |
||
|
|||
69 | //when a fclose returns false ?? |
||
70 | 6 | } |
|
71 | 6 | } |
|
72 | 6 | $this->resource = false; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * Write data to the file |
||
77 | * @param string $data |
||
78 | * @return int |
||
79 | */ |
||
80 | 2 | public function write($data = '') |
|
87 | |||
88 | /** |
||
89 | * Read some bytes from file |
||
90 | * @param int $len |
||
91 | * @return string |
||
92 | */ |
||
93 | 2 | public function read($len = null) |
|
108 | } |
||
109 |
This check looks for the bodies of
if
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.