Passed
Pull Request — master (#25)
by Valentin
03:06
created

StreamFunctions   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 11
eloc 18
c 2
b 0
f 0
dl 0
loc 59
ccs 18
cts 22
cp 0.8182
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 7 2
A fclose() 0 3 1
A fwrite() 0 6 2
A fgets() 0 6 2
A stream_set_timeout() 0 3 1
A pfsockopen() 0 3 1
A fsockopen() 0 3 1
A fopen() 0 3 1
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 25
    public static function instance()
22
    {
23 25
        if (empty(self::$_instance)) {
24 1
            self::$_instance = new self();
25
        }
26
27 25
        return self::$_instance;
28
    }
29
30
    // ----------------------------------------
31
32 22
    public function fgets($handle, $length = null)
33
    {
34 22
        if (isset($length)) {
35
            return fgets($handle, $length);
36
        } else {
37 22
            return fgets($handle);
38
        }
39
    }
40
41
    public function fopen($filename, $mode)
42
    {
43
        return fopen($filename, $mode);
44
    }
45
46 23
    public function fsockopen($hostname, $port = -1, &$errno = null, &$errstr = null, $timeout = null)
47
    {
48 23
        return @fsockopen($hostname, $port, $errno, $errstr, $timeout);
49
    }
50
51 2
    public function pfsockopen($hostname, $port = -1, &$errno = null, &$errstr = null, $timeout = null)
52
    {
53 2
        return @pfsockopen($hostname, $port, $errno, $errstr, $timeout);
54
    }
55
56 23
    public function fwrite($handle, $string, $length = null)
57
    {
58 23
        if (isset($length)) {
59
            return fwrite($handle, $string, $length);
60
        } else {
61 23
            return fwrite($handle, $string);
62
        }
63
    }
64
65 1
    public function fclose($handle)
66
    {
67 1
        fclose($handle);
68
    }
69
70 23
    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...
71
    {
72 23
        return stream_set_timeout($stream, $seconds, $microseconds);
73
    }
74
}
75