| Conditions | 47 |
| Paths | > 20000 |
| Total Lines | 86 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 96 | public function asTurtle() |
||
| 97 | { |
||
| 98 | if(is_null($this->rdf)) { |
||
| 99 | $tc =0; |
||
| 100 | $rdf=''; |
||
| 101 | extract($this->data); |
||
| 102 | |||
| 103 | // create uris |
||
| 104 | $organizationUri = empty($uri)?($base. (empty($id)?uniqid():$id)):$uri; |
||
| 105 | $addressUri = $organizationUri.'_address'; |
||
| 106 | $placeUri = $organizationUri.'_place'; |
||
| 107 | $geoUri = ( !empty($lat) && !empty($long) )?"geo:$lat,$long":($organizationUri.'_geo'); |
||
| 108 | |||
| 109 | |||
| 110 | // define the minimum condition to skipp the rdf generation |
||
| 111 | |||
| 112 | $skippAddress = empty($alternateName) && |
||
| 113 | empty($addressLocality) && |
||
| 114 | empty($streetAddress) && |
||
| 115 | empty($postalCode) && |
||
| 116 | empty($page) && |
||
| 117 | empty($telephone) && |
||
| 118 | empty($faxNumber) && |
||
| 119 | empty($email) |
||
| 120 | ; |
||
| 121 | $skippGeo = empty($geoDescription) && |
||
| 122 | empty($addressLocality) && |
||
| 123 | empty($streetAddress) && |
||
| 124 | empty($lat) && |
||
| 125 | empty($long) ; |
||
| 126 | $skippPlace = $skippGeo && $skippAddress; |
||
| 127 | |||
| 128 | $skippOrganization = $skippPlace && empty($id)&& empty($vatID) && empty($taxID) && empty($legalName) ; |
||
| 129 | |||
| 130 | // serialize schema:Organization |
||
| 131 | if( !$skippOrganization){ |
||
| 132 | $rdf.= sprintf( '<%s> a schema:Organization;', $organizationUri); $tc++; |
||
| 133 | if(!empty($id)) { $rdf.= sprintf( 'dct:identifier "%s";', $id); $tc++; } |
||
| 134 | if(!empty($vatID)) { $rdf.= sprintf( 'schema:vatID "%s"@%s;', $vatID, $lang); $tc++; } |
||
| 135 | if(!empty($taxtID)) { $rdf.= sprintf( 'schema:taxtID "%s"@%s;', $taxID, $lang); $tc++; } |
||
| 136 | if(!empty($legalName)) { $rdf.= sprintf( 'schema:legalName """%s"""@%s;', $legalName, $lang); $tc++; } |
||
| 137 | if( !$skippPlace) { $rdf.= sprintf( 'schema:location <%s>;', $placeUri); $tc++; } |
||
| 138 | $rdf.= " . "; |
||
| 139 | } |
||
| 140 | |||
| 141 | // serialize schema:PostalAddress |
||
| 142 | if( !$skippAddress){ |
||
| 143 | $rdf.= sprintf( '<%s> a schema:PostalAddress;', $addressUri); $tc++; |
||
| 144 | if(!empty($alternateName)) { $rdf.= sprintf( 'schema:alternateName """%s"""@%;', $addressCountry,$lang); $tc++; } |
||
| 145 | if(!empty($streetAddress)) { $rdf.= sprintf( 'schema:streetAddress """%s"""@%s;', $streetAddress, $lang); $tc++; } |
||
| 146 | if(!empty($postalCode)) { $rdf.= sprintf( 'schema:postalCode "%s"@%s;', $postalCode, $lang); $tc++; } |
||
| 147 | if(!empty($addressLocality)) { $rdf.= sprintf( 'schema:addressLocality """%s"""@%s;', $addressLocality, $lang); $tc++; } |
||
| 148 | if(!empty($addressRegion)) { $rdf.= sprintf( 'schema:addressRegion """%s"""@%s;', $addressRegion, $lang); $tc++; } |
||
| 149 | if(!empty($addressCountry)) { $rdf.= sprintf( 'schema:addressCountry "%s";', $addressCountry); $tc++; } |
||
| 150 | if(!empty($telephone)) { $rdf.= sprintf( 'schema:telephone """%s"""@%s;', $telephone, $lang); $tc++; } |
||
| 151 | if(!empty($faxNumber)) { $rdf.= sprintf( 'schema:faxNumber """%s"""@%s;', $faxNumber, $lang); $tc++; } |
||
| 152 | if(!empty($page)) { $rdf.= sprintf( 'schema:page <%s>;', $page); $tc++; } |
||
| 153 | if(!empty($email)) { $rdf.= sprintf( 'schema:email "%s";', $email); $tc++; } |
||
| 154 | $rdf.= " . "; |
||
| 155 | } |
||
| 156 | |||
| 157 | // serialize schema:GeoCoordinates |
||
| 158 | if( !$skippGeo){ |
||
| 159 | $geoLabel = \BOTK\Filters::buildNormalizedAddress($this->data); |
||
| 160 | $rdf.= sprintf( '<%s> a schema:GeoCoordinates;', $geoUri); $tc++; |
||
| 161 | if(!empty($geoLabel)) { $rdf.= sprintf( 'schema:alternateLabel ""%s""@%s;', $geoLabel, $lang); $tc++; } |
||
| 162 | if(!empty($geoDescription)) { $rdf.= sprintf( 'schema:alternateLabel ""%s""@%s;', $geoDescription, $lang); $tc++; } |
||
| 163 | if(!empty($lat)) { $rdf.= sprintf( 'wgs:lat %s ;', $lat); $tc++; } |
||
| 164 | if(!empty($long)) { $rdf.= sprintf( 'wgs:long %s ;', $long); $tc++; } |
||
| 165 | $rdf.= " . "; |
||
| 166 | } |
||
| 167 | |||
| 168 | // serialize schema:Place |
||
| 169 | if( !$skippPlace){ |
||
| 170 | $rdf.= sprintf( '<%s> a schema:LocalBusiness;', $placeUri); $tc++; |
||
| 171 | if(!$skippAddress) { $rdf.= sprintf( 'schema:address <%s>;', $addressUri); $tc++; } |
||
| 172 | if(!$skippGeo) { $rdf.= sprintf( 'schema:geo <%s>;', $geoUri); $tc++; } |
||
| 173 | $rdf.= " . "; |
||
| 174 | } |
||
| 175 | |||
| 176 | $this->rdf = $rdf; |
||
| 177 | $this->tripleCount = $tc; |
||
| 178 | } |
||
| 179 | |||
| 180 | return $this->rdf; |
||
| 181 | } |
||
| 182 | |||
| 183 | } |