Passed
Push — master ( 8152a8...e98e8e )
by Enrico
02:27
created

Thing   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 91
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B asTurtleFragment() 0 42 7
1
<?php
2
namespace BOTK\Model;
3
4
class Thing extends AbstractModel implements \BOTK\ModelInterface  
5
{
6
	
7
	protected static $DEFAULT_OPTIONS  = array(
8
		'page'				=> array(	
9
								'filter'    => FILTER_CALLBACK,
10
		                        'options' 	=> '\BOTK\Filters::FILTER_SANITIZE_HTTP_URL',
11
                            	'flags'  	=> FILTER_FORCE_ARRAY,
12
			                   ),
13
		'homepage'			=> array(	
14
								'filter'    => FILTER_CALLBACK,
15
		                        'options' 	=> '\BOTK\Filters::FILTER_SANITIZE_HTTP_URL',
16
                            	'flags'  	=> FILTER_FORCE_ARRAY,
17
			                   ),
18
		'disambiguatingDescription'=> array(	
19
								'filter'    => FILTER_DEFAULT,
20
                            	'flags'  	=> FILTER_FORCE_ARRAY,
21
			                   ),
22
		'subject'			=> array(	
23
								'filter'    => FILTER_CALLBACK,
24
		                        'options' 	=> '\BOTK\Filters::FILTER_VALIDATE_URI',
25
                            	'flags'  	=> FILTER_FORCE_ARRAY,
26
			                   ),
27
		'image'			=> array(	
28
								'filter'    => FILTER_CALLBACK,
29
		                        'options' 	=> '\BOTK\Filters::FILTER_SANITIZE_HTTP_URL',
30
                            	'flags'  	=> FILTER_FORCE_ARRAY,
31
			                   ),
32
		'sameAs'			=> array(	
33
								'filter'    => FILTER_CALLBACK,
34
		                        'options' 	=> '\BOTK\Filters::FILTER_VALIDATE_URI',
35
                            	'flags'  	=> FILTER_FORCE_ARRAY,
36
			                   ),
37
		'name'				=> array(		
38
								'filter'    => FILTER_DEFAULT,
39
                            	'flags'  	=> FILTER_FORCE_ARRAY,
40
			                   ),
41
		'alternateName'		=> array(		
42
								'filter'    => FILTER_DEFAULT,
43
                            	'flags'  	=> FILTER_FORCE_ARRAY,
44
			                   ),
45
		'description'		=> array(		
46
								'filter'    => FILTER_DEFAULT,
47
                            	'flags'  	=> FILTER_FORCE_ARRAY,
48
			                   ),
49
	);
50
51
	
52
	public function asTurtleFragment()
53
	{
54
		if(is_null($this->rdf)) {
55
			$uri = $this->getUri();
56
			
57
	 		// serialize uri properties
58
			$this->rdf = "<$uri> ";
59
			foreach (array(
60
				'page' 			=> 'foaf:page',
61
				'homepage'		=> 'foaf:homepage',
62
				'subject'		=> 'skos:subject',
63
				'image'			=> 'schema:image',
64
				'sameAs'		=> 'owl:sameAs',
65
			) as $uriVar=>$property) {
66
				if(!empty($this->data[$uriVar])){
67
					$this->addFragment("$property <%s>;", $this->data[$uriVar],false);	
68
				}
69
			}
70
			
71
			// serialize string properties
72
			foreach(array(
73
				'id'						=> 'dct:identifier',
74
				'disambiguatingDescription'	=> 'schema:disambiguatingDescription',
75
				'name'						=> 'schema:name',
76
				'alternateName'				=> 'schema:alternateName',
77
				'description'				=> 'schema:description',
78
			) as $stringVar=>$property) {
79
				if(!empty($this->data[$stringVar])){
80
					$this->addFragment("$property \"%s\";", $this->data[$stringVar]);	
81
				}
82
			}
83
			
84
			if($this->tripleCount){
85
				$this->rdf = substr($this->rdf, 0, -1).'.';
86
			} else {
87
				$this->rdf = ''; // no serialize if uri has no attributes
88
			}
89
			
90
		}
91
92
		return $this->rdf;
93
	}
94
}