| Conditions | 4 |
| Paths | 4 |
| Total Lines | 77 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 49 | public function DescribeFeatureType($request) |
||
| 50 | { |
||
| 51 | $model = $this->getModel($request); |
||
| 52 | $config = $this->getConfig($model); |
||
| 53 | $propertyMap = $config['property_map']; |
||
| 54 | |||
| 55 | if (count(array_intersect_key($params = array_intersect_key($request->requestVars(), array_fill_keys([ |
||
| 56 | 'service', |
||
| 57 | 'version', |
||
| 58 | 'request', |
||
| 59 | 'typeNames', |
||
| 60 | 'exceptions', |
||
| 61 | 'outputFormat', |
||
| 62 | ], null)), array_fill_keys([ |
||
| 63 | 'service', |
||
| 64 | 'version', |
||
| 65 | 'request', |
||
| 66 | 'typeNames', |
||
| 67 | ], null))) == 4) { |
||
| 68 | extract($params); |
||
| 69 | } else { |
||
| 70 | $xml = new SimpleXMLElement($raw = $request->getBody()); |
||
| 71 | $service = (string)$xml['service']; |
||
| 72 | $version = (string)$xml['version']; |
||
| 73 | $request = $xml->getName(); |
||
| 74 | $typeNames = []; |
||
| 75 | foreach ($xml->xpath('TypeName') as $typeName) { |
||
| 76 | $typeNames[] = (string)$typeName; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | list($nsName, $nsUri) = explode('=', $config['ns']); |
||
| 81 | |||
| 82 | $dom = new DOMDocument('1.0','UTF-8'); |
||
| 83 | $schema = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'schema'); |
||
| 84 | $schema->setAttribute('elementFormDefault', 'qualified'); |
||
| 85 | $schema->setAttribute('targetNamespace', $nsUri); |
||
| 86 | $schema->setAttribute('xmlns:gml', 'http://www.opengis.net/gml/3.2'); |
||
| 87 | $schema->setAttribute('xmlns:' . $nsName, $nsUri); |
||
| 88 | |||
| 89 | $complexType = $dom->createElement('complexType'); |
||
| 90 | $complexType->setAttribute('name', $nsName . ':' . $config['feature_type_name']); |
||
| 91 | |||
| 92 | $complexContent = $dom->createElement('complexContent'); |
||
| 93 | |||
| 94 | $extension = $dom->createElement('extension'); |
||
| 95 | $extension->setAttribute('base', 'gml:AbstractFeatureType'); |
||
| 96 | |||
| 97 | $sequence = $dom->createElement('sequence'); |
||
| 98 | |||
| 99 | foreach ($propertyMap as $fieldName => $propertyName) { |
||
| 100 | $element = $dom->createElement('element'); |
||
| 101 | $element->setAttribute('name', $propertyName); |
||
| 102 | $element->setAttribute('type', $this->config()->type_map[$model::config()->db[$fieldName]]); |
||
| 103 | $sequence->appendChild($element); |
||
| 104 | } |
||
| 105 | |||
| 106 | $element = $dom->createElement('element'); |
||
| 107 | $element->setAttribute('name', $config['geometry_field']); |
||
| 108 | $element->setAttribute('type', 'gml:GeometryPropertyType'); |
||
| 109 | $sequence->appendChild($element); |
||
| 110 | |||
| 111 | $extension->appendChild($sequence); |
||
| 112 | |||
| 113 | $complexContent->appendChild($extension); |
||
| 114 | |||
| 115 | $complexType->appendChild($complexContent); |
||
| 116 | |||
| 117 | $schema->appendChild($complexType); |
||
| 118 | |||
| 119 | $dom->appendChild($schema); |
||
| 120 | |||
| 121 | $response = $this->getResponse(); |
||
| 122 | $response->addHeader('content-type', 'text/xml; charset=utf-8'); |
||
| 123 | $response->setBody($dom->saveXML()); |
||
| 124 | |||
| 125 | return $response; |
||
| 126 | } |
||
| 254 |