Test Failed
Push — master ( 1d9659...d79195 )
by Enrico
01:25
created

BusinessContact   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 142
ccs 24
cts 27
cp 0.8889
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C asTurtleFragment() 0 61 13
1
<?php
2
namespace BOTK\Model;
3
4
5
/**
6
 * An ibrid class that merge the semantic of schema:organization, schema:place and schema:geo, 
7
 * it is similar to schema:LocalBusiness.
8
 * Allows the bulk setup of properties
9
 */
10
class BusinessContact extends Thing 
11
{
12
13
	protected static $DEFAULT_OPTIONS = array (
14
		'taxID'				=> array(	
15
			'filter'    => FILTER_CALLBACK,
16
			'options' 	=> '\BOTK\Filters::FILTER_SANITIZE_TOKEN',
17
			'flags'  	=> FILTER_REQUIRE_SCALAR,
18
			),
19
		'alternateName'		=> array(
20
			'filter'    => FILTER_CALLBACK,
21
			'options' 	=> '\BOTK\Filters::FILTER_SANITIZE_PERSON_NAME',
22
			'flags'  	=> FILTER_FORCE_ARRAY,
23
			),
24
		'givenName'				=> array(
25
			'filter'    => FILTER_CALLBACK,
26
			'options' 	=> '\BOTK\Filters::FILTER_SANITIZE_PERSON_NAME',
27
			'flags'  	=> FILTER_REQUIRE_SCALAR,
28
			),
29
		'familyName'				=> array(
30
			'filter'    => FILTER_CALLBACK,
31
			'options' 	=> '\BOTK\Filters::FILTER_SANITIZE_PERSON_NAME',
32
			'flags'  	=> FILTER_REQUIRE_SCALAR,
33
			),
34
		'additionalName'			=> array(
35
			'filter'    => FILTER_CALLBACK,
36
			'options' 	=> '\BOTK\Filters::FILTER_SANITIZE_PERSON_NAME',
37
			'flags'  	=> FILTER_REQUIRE_SCALAR,
38
			),
39
		'jobTitle'	=> array(
40
			'filter'    => FILTER_DEFAULT,
41
			'flags'  	=> FILTER_FORCE_ARRAY,
42
			),
43
		'honorificPrefix'	=> array(
44
			'filter'    => FILTER_DEFAULT,
45
			'flags'  	=> FILTER_FORCE_ARRAY,
46
			),
47
		'honorificSuffix'	=> array(
48
			'filter'    => FILTER_DEFAULT,
49
			'flags'  	=> FILTER_FORCE_ARRAY,
50
			),
51
		'gender'	=> array(	
52
			'filter'    => FILTER_CALLBACK,
53
			'options'    => '\BOTK\Filters::FILTER_SANITIZE_GENDER',
54
			'flags'  	=> FILTER_REQUIRE_SCALAR,
55
			),
56
		'worksFor'	=> array(		
57
			'filter'    => FILTER_CALLBACK,
58
			'options' 	=> '\BOTK\Filters::FILTER_VALIDATE_URI',
59
			'flags'  	=> FILTER_REQUIRE_SCALAR,
60
			),
61
		'telephone'			=> array(	
62
			'filter'    => FILTER_CALLBACK,	
63
			'options' 	=> '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE',
64
			'flags'  	=> FILTER_FORCE_ARRAY,
65
			),
66
		'email'				=> array(	
67
			'filter'    => FILTER_CALLBACK,
68
			'options' 	=> '\BOTK\Filters::FILTER_SANITIZE_EMAIL',
69
			'flags'  	=> FILTER_FORCE_ARRAY,
70
			),
71
		'spokenLanguage'			=> array(	
72
			'filter'    => FILTER_CALLBACK,
73
			'options' 	=> '\BOTK\Filters::FILTER_SANITIZE_LANGUAGE',
74
			'flags'  	=> FILTER_FORCE_ARRAY,
75
			),
76
		'hasOptInOptOutDate'				=> array(	
77
			'filter'    => FILTER_CALLBACK,
78
			'options' 	=> '\BOTK\Filters::FILTER_SANITIZE_DATETIME',
79
			'flags'  	=> FILTER_REQUIRE_SCALAR,
80
			),
81
		'privacyFlag'		=> array(	
82
			'filter'    => FILTER_CALLBACK,
83
			'options' 	=> '\BOTK\Filters::FILTER_SANITIZE_BOOLEAN',
84
			'flags'  	=> FILTER_REQUIRE_SCALAR,
85
			),
86
		);
87
88
	
89 4
	public function asTurtleFragment()
90
	{
91 4
		static $uriVars = array(
92
			'gender' => 'schema:gender',
93
			'worksFor' => 'schema:worksFor',
94
		);
95 4
		static $stringVars = array(
96
			'taxID' => 'schema:taxID',
97
			'givenName' => 'schema:givenName',
98
			'familyName' => 'schema:familyName',
99
			'additionalName' => 'schema:additionalName',
100
			'telephone' => 'schema:telephone',
101
			'faxNumber' => 'schema:faxNumber',
102
			'jobTitle' => 'schema:jobTitle',
103
			'honorificPrefix' => 'schema:honorificPrefix',
104
			'honorificSuffix' => 'schema:honorificSuffix',
105
			'email' => 'schema:email',
106
			'spokenLanguage' => 'schema:spokenLanguage',
107
		);
108
		
109
		
110 4
		if(is_null($this->rdf)) {
111
			
112
			// make a default for altenatename (can be empty) before calling parent::asTurtleFragment
113 4
			if(empty($this->data['alternateName'])){
114 3
				$this->data['alternateName'] ='';
115 3
				if(!empty($this->data['givenName'])) { $this->data['alternateName'].= $this->data['givenName'].' ';}						
116 3
				if(!empty($this->data['additionalName'])) { $this->data['alternateName'].= $this->data['additionalName'].' ';}		
117 3
				if(!empty($this->data['familyName'])) { $this->data['alternateName'].= $this->data['familyName'].' ';}
118 3
				$this->data['alternateName'] = trim($this->data['alternateName']);
119
			}			
120 4
			$this->rdf = parent::asTurtleFragment();
121
		
122 4
			$personUri = $this->getUri();
123
			
124
	 		// serialize schema:LocalBusiness	
125 4
			$this->rdf .= "<$personUri> ";	
126 4
			foreach ( $uriVars as $uriVar => $property) {
127 4
				if(!empty($this->data[$uriVar])){
128 4
					$this->addFragment("$property <%s>;", $this->data[$uriVar],false);	
129
				}
130
			}
131 4
			foreach ($stringVars as $stringVar => $property) {
132 4
				if(!empty($this->data[$stringVar])){
133 4
					$this->addFragment("$property \"%s\";", $this->data[$stringVar]);	
134
				}
135
			}
136 4
			!empty($this->data['hasOptInOptOutDate'])&& $this->addFragment('botk:hasOptInOptOutDate "%s"^^xsd:dateTime;', $this->data['hasOptInOptOutDate']);
137 4
			!empty($this->data['privacyFlag'])	&& $this->addFragment('botk:privacyFlag %s ;', $this->data['privacyFlag']);			
138 4
			$this->addFragment('a schema:Person.', $personUri);
139
					
140 4
			if(!empty($this->data['aggregateRatingValue'])){
141
				$ratingUri=$this->data['base'].'rating_'.$this->data['aggregateRatingValue'].
142
				$this->rdf .= "<$personUri> schema:aggregateRating <$ratingUri>.<$ratingUri> schema:ratingValue \"{$this->data['aggregateRatingValue']}\"^^xsd:float.";
143
				$this->tripleCount +=2;
144
			}
145
146
		}
147
148 4
		return $this->rdf;
149
	}
150
151
}