MssqlBlob::__construct()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 4
nop 1
dl 0
loc 11
rs 8.8571
c 0
b 0
f 0
1
<?php
2
class MssqlBlob extends Blob {
3
	public function __construct( $data ) {
4
		if ( $data instanceof MssqlBlob ) {
5
			return $data;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
6
		} elseif ( $data instanceof Blob ) {
7
			$this->mData = $data->fetch();
8
		} elseif ( is_array( $data ) && is_object( $data ) ) {
9
			$this->mData = serialize( $data );
10
		} else {
11
			$this->mData = $data;
12
		}
13
	}
14
15
	/**
16
	 * Returns an unquoted hex representation of a binary string
17
	 * for insertion into varbinary-type fields
18
	 * @return string
19
	 */
20
	public function fetch() {
21
		if ( $this->mData === null ) {
22
			return 'null';
23
		}
24
25
		$ret = '0x';
26
		$dataLength = strlen( $this->mData );
27
		for ( $i = 0; $i < $dataLength; $i++ ) {
28
			$ret .= bin2hex( pack( 'C', ord( $this->mData[$i] ) ) );
29
		}
30
31
		return $ret;
32
	}
33
}
34