Completed
Push — master ( 53e675...162e5c )
by Valentin
30s queued 24s
created

StreamFunctions::fopen()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Pheanstalk\Socket;
4
5
/**
6
 * Wrapper around PHP stream functions.
7
 *
8
 * Facilitates mocking/stubbing stream operations in unit tests.
9
 *
10
 * @author  Paul Annesley
11
 * @package Pheanstalk
12
 * @license http://www.opensource.org/licenses/mit-license.php
13
 */
14
class StreamFunctions
15
{
16
    private static $_instance;
17
18
    /**
19
     * Singleton accessor.
20
     */
21 27
    public static function instance()
22
    {
23 27
        if (empty(self::$_instance)) {
24 1
            self::$_instance = new self();
25
        }
26
27 27
        return self::$_instance;
28
    }
29
30
    // ----------------------------------------
31
32 24
    public function fgets($handle, $length = null)
33
    {
34 24
        if (isset($length)) {
35 2
            return fgets($handle, $length);
36
        } else {
37 22
            return fgets($handle);
38
        }
39
    }
40
41 23
    public function fsockopen($hostname, $port = -1, &$errno = null, &$errstr = null, $timeout = null)
42
    {
43 23
        return @fsockopen($hostname, $port, $errno, $errstr, $timeout);
44
    }
45
46 4
    public function pfsockopen($hostname, $port = -1, &$errno = null, &$errstr = null, $timeout = null)
47
    {
48 4
        return @pfsockopen($hostname, $port, $errno, $errstr, $timeout);
49
    }
50
51 23
    public function fwrite($handle, $string)
52
    {
53 23
        return fwrite($handle, $string);
54
    }
55
56 2
    public function fclose($handle)
57
    {
58 2
        fclose($handle);
59
    }
60
61 25
    public function stream_set_timeout($stream, $seconds, $microseconds = 0)
1 ignored issue
show
Coding Style introduced by
Method name "StreamFunctions::stream_set_timeout" is not in camel caps format
Loading history...
62
    {
63 25
        return stream_set_timeout($stream, $seconds, $microseconds);
64
    }
65
}
66