Test Setup Failed
Branch botk5 (3fe4ef)
by Enrico
02:33
created

FactsFactory::generateLinkedDataFooter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
namespace BOTK;
3
4
class FactsFactory implements FactsFactoryInterface {
5
	
6
	protected $profile;
7
	protected $tripleCount =0;
8
	protected $errors = array();
9
	
10
	
11
	public function __construct( array $profile )
12
	{
13
		assert(!empty($profile['model']) && class_exists('\BOTK\Model\\'.$profile['model']));
14
		assert(isset($profile['datamapper']) && is_callable($profile['datamapper']));
15
		assert(isset($profile['options']) && is_array($profile['options']));
16
		$this->profile = $profile;
17
	}
18
	
19
	
20
	/**
21
	 * two level filter array
22
	 */
23
	public function removeEmpty( array $data )
24
	{
25
		$a = array();
26
	    foreach ($data as $key => $value) {
27
	       $a[$key] = is_array($value)?array_filter($value):$value;
28
	    }
29
	    return array_filter($a);
30
	}
31
	
32
	
33
	public function factualize( array $rawData )
34
	{
35
		$datamapper = $this->profile['datamapper'];
36
		$class = '\BOTK\Model\\'.$this->profile['model'];
37
		$data =$this->removeEmpty($datamapper($rawData));
38
		return new $class($data,$this->profile['options']);
39
	}
40
	
41
	
42
	public function generateLinkedDataHeader()
43
	{
44
		$class = '\BOTK\Model\\'.$this->profile['model'];
45
		$model = new $class();
46
		return $model->getTurtleHeader(); 
47
	}
48
	
49
	
50
	public function generateLinkedDataFooter()
51
	{
52
		$errorCount = count($this->errors);
53
		return "\n#\n# Generated {$this->tripleCount} triples and $errorCount errors\n#\n"; 
54
	}
55
	
56
	public function  addToTripleCounter( $triplesCount)
57
	{
58
		$this->tripleCount += intval($triplesCount);
59
		return $this;
60
	}	
61
	
62
	
63
	public function getTripleCount()
64
	{
65
		return $this->tripleCount;
66
	}
67
	
68
		
69
	public function addError($error)
70
	{
71
		$this->errors[]= (string) $error;
72
		return $this;
73
	}
74
75
}