Completed
Push — master ( e2f106...c79eb3 )
by Nazar
04:11
created

Data   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A init_data() 0 7 3
1
<?php
2
/**
3
 * @package   CleverStyle CMS
4
 * @author    Nazar Mokrynskyi <[email protected]>
5
 * @copyright Copyright (c) 2016, Nazar Mokrynskyi
6
 * @license   MIT License, see license.txt
7
 */
8
namespace cs\Request;
9
10
trait Data {
11
	/**
12
	 * Data array, similar to `$_POST`
13
	 *
14
	 * @var array
15
	 */
16
	public $data;
17
	/**
18
	 * Data stream resource, similar to `fopen('php://input', 'br')`
19
	 *
20
	 * Make sure you're controlling position in stream where you read something, if code in some other place might seek on this stream
21
	 *
22
	 * @var null|resource
23
	 */
24
	public $data_stream;
25
	/**
26
	 * @param array                $data        Typically `$_POST`
27
	 * @param null|resource|string $data_stream String, like `php://input` or resource, like `fopen('php://input', 'br')`
28
	 */
29
	function init_data ($data = [], $data_stream = null) {
30
		if (is_resource($this->data_stream)) {
31
			fclose($this->data_stream);
32
		}
33
		$this->data        = $data;
34
		$this->data_stream = is_string($data_stream) ? fopen($data_stream, 'br') : $data_stream;
35
	}
36
}
37