MockHttpStreamWrapper   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 2
cbo 0
dl 0
loc 80
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A stream_read() 0 10 2
A stream_eof() 0 3 1
A stream_set_option() 0 3 1
A stream_stat() 0 3 1
A stream_tell() 0 3 1
A stream_open() 0 7 1
A stream_write() 0 8 2
1
<?php
2
3
namespace Onoi\HttpRequest\Tests;
4
5
/**
6
 * @codeCoverageIgnore
7
 * @see https://gist.github.com/ukolka/8448362
8
 */
9
class MockHttpStreamWrapper {
10
11
	public static $mockBodyData = '';
12
	public static $mockResponseCode = 'HTTP/1.1 200 OK';
13
14
	public $context;
15
	public $position = 0;
16
	public $bodyData = 'test data';
17
	public $responseCode = '';
18
19
	protected $streamArray = array();
20
	protected $options = array();
21
	protected $isOpen = false;
22
23
	/**
24
	 * StreamWrapper::stream_open
25
	 */
26
	public function stream_open( $path, $mode, $options, &$opened_path ) {
0 ignored issues
show
Unused Code introduced by
The parameter $path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $mode is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opened_path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
27
		$this->bodyData = self::$mockBodyData;
28
		$this->responseCode = self::$mockResponseCode;
29
		array_push( $this->streamArray, self::$mockResponseCode );
30
		$this->isOpen = true;
31
		return true;
32
	}
33
34
	/**
35
	 * StreamWrapper::stream_write
36
	 */
37
	public function stream_write( $data ) {
38
39
		if ( $this->isOpen ) {
40
			return strlen( $data );
41
		}
42
43
		return 0;
44
	}
45
46
	/**
47
	 * StreamWrapper::stream_read
48
	 */
49
	public function stream_read( $count ) {
50
51
		if ( $this->position > strlen($this->bodyData)) {
52
			return false;
53
		}
54
55
		$result = substr( $this->bodyData, $this->position, $count );
56
		$this->position += $count;
57
		return $result;
58
	}
59
60
	/**
61
	 * StreamWrapper::stream_eof
62
	 */
63
	public function stream_eof() {
64
		return $this->position >= strlen($this->bodyData);
65
	}
66
67
	/**
68
	 * StreamWrapper::stream_set_option
69
	 */
70
	public function stream_set_option( $option, $arg1, $arg2 ) {
0 ignored issues
show
Unused Code introduced by
The parameter $arg1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $arg2 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
		$this->options[$option] = array();
72
	}
73
74
	/**
75
	 * StreamWrapper::stream_stat
76
	 */
77
	public function stream_stat() {
78
		return array( 'wrapper_data' => array( 'test' ) );
79
	}
80
81
	/**
82
	 * StreamWrapper::stream_tell
83
	 */
84
	public function stream_tell() {
85
		return $this->position;
86
	}
87
88
}
89