FileDiffStorage::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 8
rs 9.4285
cc 2
eloc 6
nc 2
nop 4
1
<?php
2
namespace DataDiff;
3
4
class FileDiffStorage extends DiffStorage {
5
	/**
6
	 * @param string $filename
7
	 * @param array $keySchema
8
	 * @param array $valueSchema
9
	 * @param array $options
10
	 */
11
	public function __construct($filename = null, array $keySchema, array $valueSchema, array $options = []) {
12
		if($filename === null) {
13
			$filename = tempnam(sys_get_temp_dir(), 'data-diff-');
14
		}
15
		$this->createFile($filename);
16
		$options['dsn'] = sprintf('sqlite:%s', $filename);
17
		parent::__construct($keySchema, $valueSchema, $options);
18
	}
19
20
	/**
21
	 * @param string $filename
22
	 */
23
	private function createFile($filename) {
24
		$fp = null;
25
		try {
26
			$fp = fopen($filename, 'w+');
27
		} finally {
28
			if(is_resource($fp)) {
29
				fclose($fp);
30
			}
31
		}
32
	}
33
}
34