MssqlBlob   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 11 5
A fetch() 0 13 3
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