Completed
Push — master ( 66c020...88a4bc )
by Enrico
01:49
created

BusinessContact   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 65.38%

Importance

Changes 0
Metric Value
wmc 31
lcom 1
cbo 2
dl 0
loc 152
ccs 17
cts 26
cp 0.6538
rs 9.8
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B makePersonNameDescription() 0 14 6
F asTurtleFragment() 0 55 25
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
	private function makePersonNameDescription()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
90
	{	
91
		if(empty($this->data['alternateName'])){
92
			$this->data['alternateName'] ='';
93
			if(!empty($this->data['givenName'])) { $this->data['alternateName'].= $this->data['givenName'].' ';}						
94
			if(!empty($this->data['additionalName'])) { $this->data['alternateName'].= $this->data['additionalName'].' ';}		
95
			if(!empty($this->data['familyName'])) { $this->data['alternateName'].= $this->data['familyName'].' ';}
96
		}
97
		
98
		if(!empty($this->data['alternateName'])){
99
			$this->data['alternateName']=\BOTK\Filters::FILTER_SANITIZE_PERSON_NAME($this->data['alternateName']);
100
		}
101
102
	}
103
	
104
	
105 4
	public function asTurtleFragment()
106
	{
107 4
		if(is_null($this->rdf)) {
108 4
			extract($this->data);
109
110
			// create uris
111 4
			$personUri = $this->getUri();
112
			
113
			// make a default for altenatename (can be empty)
114 4
			if(empty($alternateName)){
115 3
				$this->data['alternateName'] ='';
116 3
				if(!empty($givenName)) { $this->data['alternateName'].= $givenName.' ';}						
117 3
				if(!empty($additionalName)) { $this->data['alternateName'].= $additionalName.' ';}		
118 3
				if(!empty($familyName)) { $this->data['alternateName'].= $familyName.' ';}
119
			}
120
			
121 4
			$turtleString = parent::asTurtleFragment();
122 4
			$tripleCounter = $this->tripleCount;
123
			
124
			// define $_ as a macro to write simple rdf
125 4
			$_= function($format, $var,$sanitize=true) use(&$turtleString, &$tripleCounter){
126 4
				foreach((array)$var as $v){
127 4
					if($var){
128 4
						$turtleString.= sprintf($format,$sanitize?\BOTK\Filters::FILTER_SANITIZE_TURTLE_STRING($v):$v);
129 4
						$tripleCounter++;
130
					}
131
				}
132 4
			};
133
134
	 		// serialize schema:LocalBusiness	
135
			$turtleString .= "<$personUri> ";	
136
			!empty($aggregateRatingValue)&& $_('schema:aggregateRating [a schema:AggregateRating; schema:ratingValue "%s"^^xsd:float];', $aggregateRatingValue);
137
			!empty($taxID) 				&& $_('schema:taxID "%s";', $taxID);
138
			!empty($givenName)			&& $_('schema:givenName "%s";', $givenName);
139
			!empty($familyName)			&& $_('schema:familyName "%s";', $familyName);
140
			!empty($additionalName) 	&& $_('schema:additionalName "%s";', $additionalName);
141
			!empty($telephone) 			&& $_('schema:telephone "%s";', $telephone);
142
			!empty($faxNumber) 			&& $_('schema:faxNumber "%s";', $faxNumber);
143
			!empty($jobTitle)			&& $_('schema:jobTitle "%s";', $jobTitle);
144
			!empty($honorificPrefix)	&& $_('schema:honorificPrefix "%s";', $honorificPrefix);
145
			!empty($honorificSuffix)	&& $_('schema:honorificSuffix "%s";', $honorificSuffix);
146
			!empty($email) 				&& $_('schema:email "%s";', $email);
147
			!empty($gender)				&& $_('schema:gender "%s";', $gender);
148
			!empty($worksFor)			&& $_('schema:worksFor <%s> ;', $worksFor,false);
149
			!empty($spokenLanguage)		&& $_('botk:spokenLanguage "%s";', $spokenLanguage);
150
			!empty($hasOptInOptOutDate)	&& $_('botk:hasOptInOptOutDate "%s"^^xsd:dateTime;', $hasOptInOptOutDate);
151
			!empty($privacyFlag)		&& $_('botk:privacyFlag %s ;', $privacyFlag);		
152
			$_('a schema:Person.', $personUri);
153
154
			$this->rdf = $turtleString;
155
			$this->tripleCount = $tripleCounter;
156
		}
157
158
		return $this->rdf;
159
	}
160
161
}