FileDiffStorage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A createFile() 0 10 2
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