| Conditions | 79 |
| Paths | 6648 |
| Total Lines | 317 |
| Code Lines | 222 |
| 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 |
||
| 173 | function schemaStartElement($parser, $name, $attrs) {
|
||
| 174 | |||
| 175 | // position in the total number of elements, starting from 0 |
||
| 176 | $pos = $this->position++; |
||
| 177 | $depth = $this->depth++; |
||
| 178 | // set self as current value for this depth |
||
| 179 | $this->depth_array[$depth] = $pos; |
||
| 180 | $this->message[$pos] = array('cdata' => '');
|
||
| 181 | if ($depth > 0) {
|
||
| 182 | $this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]]; |
||
| 183 | } else {
|
||
| 184 | $this->defaultNamespace[$pos] = false; |
||
| 185 | } |
||
| 186 | |||
| 187 | // get element prefix |
||
| 188 | if($prefix = $this->getPrefix($name)){
|
||
| 189 | // get unqualified name |
||
| 190 | $name = $this->getLocalPart($name); |
||
| 191 | } else {
|
||
| 192 | $prefix = ''; |
||
| 193 | } |
||
| 194 | |||
| 195 | // loop thru attributes, expanding, and registering namespace declarations |
||
| 196 | if(count($attrs) > 0){
|
||
| 197 | foreach($attrs as $k => $v){
|
||
| 198 | // if ns declarations, add to class level array of valid namespaces |
||
| 199 | if(preg_match('/^xmlns/',$k)){
|
||
| 200 | //$this->xdebug("$k: $v");
|
||
| 201 | //$this->xdebug('ns_prefix: '.$this->getPrefix($k));
|
||
| 202 | if($ns_prefix = substr(strrchr($k,':'),1)){
|
||
| 203 | //$this->xdebug("Add namespace[$ns_prefix] = $v");
|
||
| 204 | $this->namespaces[$ns_prefix] = $v; |
||
| 205 | } else {
|
||
| 206 | $this->defaultNamespace[$pos] = $v; |
||
| 207 | if (! $this->getPrefixFromNamespace($v)) {
|
||
| 208 | $this->namespaces['ns'.(count($this->namespaces)+1)] = $v; |
||
| 209 | } |
||
| 210 | } |
||
| 211 | if($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema'){
|
||
| 212 | $this->XMLSchemaVersion = $v; |
||
| 213 | $this->namespaces['xsi'] = $v.'-instance'; |
||
| 214 | } |
||
| 215 | } |
||
| 216 | } |
||
| 217 | foreach($attrs as $k => $v){
|
||
| 218 | // expand each attribute |
||
| 219 | $k = strpos($k,':') ? $this->expandQname($k) : $k; |
||
| 220 | $v = strpos($v,':') ? $this->expandQname($v) : $v; |
||
| 221 | $eAttrs[$k] = $v; |
||
| 222 | } |
||
| 223 | $attrs = $eAttrs; |
||
| 224 | } else {
|
||
| 225 | $attrs = array(); |
||
| 226 | } |
||
| 227 | // find status, register data |
||
| 228 | switch($name){
|
||
| 229 | case 'all': // (optional) compositor content for a complexType |
||
| 230 | case 'choice': |
||
| 231 | case 'group': |
||
| 232 | case 'sequence': |
||
| 233 | //$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement");
|
||
| 234 | $this->complexTypes[$this->currentComplexType]['compositor'] = $name; |
||
| 235 | //if($name == 'all' || $name == 'sequence'){
|
||
| 236 | // $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; |
||
| 237 | //} |
||
| 238 | break; |
||
| 239 | case 'attribute': // complexType attribute |
||
| 240 | //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']);
|
||
| 241 | $this->xdebug("parsing attribute:");
|
||
| 242 | $this->appendDebug($this->varDump($attrs)); |
||
| 243 | if (!isset($attrs['form'])) {
|
||
| 244 | // TODO: handle globals |
||
| 245 | $attrs['form'] = $this->schemaInfo['attributeFormDefault']; |
||
| 246 | } |
||
| 247 | if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
|
||
| 248 | $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
||
| 249 | if (!strpos($v, ':')) {
|
||
| 250 | // no namespace in arrayType attribute value... |
||
| 251 | if ($this->defaultNamespace[$pos]) {
|
||
| 252 | // ...so use the default |
||
| 253 | $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
||
| 254 | } |
||
| 255 | } |
||
| 256 | } |
||
| 257 | if(isset($attrs['name'])){
|
||
| 258 | $this->attributes[$attrs['name']] = $attrs; |
||
| 259 | $aname = $attrs['name']; |
||
| 260 | } elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType'){
|
||
| 261 | if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
|
||
| 262 | $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
||
| 263 | } else {
|
||
| 264 | $aname = ''; |
||
| 265 | } |
||
| 266 | } elseif(isset($attrs['ref'])){
|
||
| 267 | $aname = $attrs['ref']; |
||
| 268 | $this->attributes[$attrs['ref']] = $attrs; |
||
| 269 | } |
||
| 270 | |||
| 271 | if($this->currentComplexType){ // This should *always* be
|
||
| 272 | $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs; |
||
| 273 | } |
||
| 274 | // arrayType attribute |
||
| 275 | if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType'){
|
||
| 276 | $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
||
| 277 | $prefix = $this->getPrefix($aname); |
||
| 278 | if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])){
|
||
| 279 | $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
||
| 280 | } else {
|
||
| 281 | $v = ''; |
||
| 282 | } |
||
| 283 | if(strpos($v,'[,]')){
|
||
| 284 | $this->complexTypes[$this->currentComplexType]['multidimensional'] = true; |
||
| 285 | } |
||
| 286 | $v = substr($v,0,strpos($v,'[')); // clip the [] |
||
| 287 | if(!strpos($v,':') && isset($this->typemap[$this->XMLSchemaVersion][$v])){
|
||
| 288 | $v = $this->XMLSchemaVersion.':'.$v; |
||
| 289 | } |
||
| 290 | $this->complexTypes[$this->currentComplexType]['arrayType'] = $v; |
||
| 291 | } |
||
| 292 | break; |
||
| 293 | case 'complexContent': // (optional) content for a complexType |
||
| 294 | $this->xdebug("do nothing for element $name");
|
||
| 295 | break; |
||
| 296 | case 'complexType': |
||
| 297 | array_push($this->complexTypeStack, $this->currentComplexType); |
||
| 298 | if(isset($attrs['name'])){
|
||
| 299 | // TODO: what is the scope of named complexTypes that appear |
||
| 300 | // nested within other c complexTypes? |
||
| 301 | $this->xdebug('processing named complexType '.$attrs['name']);
|
||
| 302 | //$this->currentElement = false; |
||
| 303 | $this->currentComplexType = $attrs['name']; |
||
| 304 | $this->complexTypes[$this->currentComplexType] = $attrs; |
||
| 305 | $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType'; |
||
| 306 | // This is for constructs like |
||
| 307 | // <complexType name="ListOfString" base="soap:Array"> |
||
| 308 | // <sequence> |
||
| 309 | // <element name="string" type="xsd:string" |
||
| 310 | // minOccurs="0" maxOccurs="unbounded" /> |
||
| 311 | // </sequence> |
||
| 312 | // </complexType> |
||
| 313 | if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){
|
||
| 314 | $this->xdebug('complexType is unusual array');
|
||
| 315 | $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
||
| 316 | } else {
|
||
| 317 | $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; |
||
| 318 | } |
||
| 319 | } else {
|
||
| 320 | $name = $this->CreateTypeName($this->currentElement); |
||
| 321 | $this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name);
|
||
| 322 | $this->currentComplexType = $name; |
||
| 323 | //$this->currentElement = false; |
||
| 324 | $this->complexTypes[$this->currentComplexType] = $attrs; |
||
| 325 | $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType'; |
||
| 326 | // This is for constructs like |
||
| 327 | // <complexType name="ListOfString" base="soap:Array"> |
||
| 328 | // <sequence> |
||
| 329 | // <element name="string" type="xsd:string" |
||
| 330 | // minOccurs="0" maxOccurs="unbounded" /> |
||
| 331 | // </sequence> |
||
| 332 | // </complexType> |
||
| 333 | if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){
|
||
| 334 | $this->xdebug('complexType is unusual array');
|
||
| 335 | $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
||
| 336 | } else {
|
||
| 337 | $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; |
||
| 338 | } |
||
| 339 | } |
||
| 340 | $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false'; |
||
| 341 | break; |
||
| 342 | case 'element': |
||
| 343 | array_push($this->elementStack, $this->currentElement); |
||
| 344 | if (!isset($attrs['form'])) {
|
||
| 345 | if ($this->currentComplexType) {
|
||
| 346 | $attrs['form'] = $this->schemaInfo['elementFormDefault']; |
||
| 347 | } else {
|
||
| 348 | // global |
||
| 349 | $attrs['form'] = 'qualified'; |
||
| 350 | } |
||
| 351 | } |
||
| 352 | if(isset($attrs['type'])){
|
||
| 353 | $this->xdebug("processing typed element ".$attrs['name']." of type ".$attrs['type']);
|
||
| 354 | if (! $this->getPrefix($attrs['type'])) {
|
||
| 355 | if ($this->defaultNamespace[$pos]) {
|
||
| 356 | $attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type']; |
||
| 357 | $this->xdebug('used default namespace to make type ' . $attrs['type']);
|
||
| 358 | } |
||
| 359 | } |
||
| 360 | // This is for constructs like |
||
| 361 | // <complexType name="ListOfString" base="soap:Array"> |
||
| 362 | // <sequence> |
||
| 363 | // <element name="string" type="xsd:string" |
||
| 364 | // minOccurs="0" maxOccurs="unbounded" /> |
||
| 365 | // </sequence> |
||
| 366 | // </complexType> |
||
| 367 | if ($this->currentComplexType && $this->complexTypes[$this->currentComplexType]['phpType'] == 'array') {
|
||
| 368 | $this->xdebug('arrayType for unusual array is ' . $attrs['type']);
|
||
| 369 | $this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type']; |
||
| 370 | } |
||
| 371 | $this->currentElement = $attrs['name']; |
||
| 372 | $ename = $attrs['name']; |
||
| 373 | } elseif(isset($attrs['ref'])){
|
||
| 374 | $this->xdebug("processing element as ref to ".$attrs['ref']);
|
||
| 375 | $this->currentElement = "ref to ".$attrs['ref']; |
||
| 376 | $ename = $this->getLocalPart($attrs['ref']); |
||
| 377 | } else {
|
||
| 378 | $type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']); |
||
| 379 | $this->xdebug("processing untyped element " . $attrs['name'] . ' type ' . $type);
|
||
| 380 | $this->currentElement = $attrs['name']; |
||
| 381 | $attrs['type'] = $this->schemaTargetNamespace . ':' . $type; |
||
| 382 | $ename = $attrs['name']; |
||
| 383 | } |
||
| 384 | if (isset($ename) && $this->currentComplexType) {
|
||
| 385 | $this->xdebug("add element $ename to complexType $this->currentComplexType");
|
||
| 386 | $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs; |
||
| 387 | } elseif (!isset($attrs['ref'])) {
|
||
| 388 | $this->xdebug("add element $ename to elements array");
|
||
| 389 | $this->elements[ $attrs['name'] ] = $attrs; |
||
| 390 | $this->elements[ $attrs['name'] ]['typeClass'] = 'element'; |
||
| 391 | } |
||
| 392 | break; |
||
| 393 | case 'enumeration': // restriction value list member |
||
| 394 | $this->xdebug('enumeration ' . $attrs['value']);
|
||
| 395 | if ($this->currentSimpleType) {
|
||
| 396 | $this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value']; |
||
| 397 | } elseif ($this->currentComplexType) {
|
||
| 398 | $this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value']; |
||
| 399 | } |
||
| 400 | break; |
||
| 401 | case 'extension': // simpleContent or complexContent type extension |
||
| 402 | $this->xdebug('extension ' . $attrs['base']);
|
||
| 403 | if ($this->currentComplexType) {
|
||
| 404 | $ns = $this->getPrefix($attrs['base']); |
||
| 405 | if ($ns == '') {
|
||
| 406 | $this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base']; |
||
| 407 | } else {
|
||
| 408 | $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base']; |
||
| 409 | } |
||
| 410 | } else {
|
||
| 411 | $this->xdebug('no current complexType to set extensionBase');
|
||
| 412 | } |
||
| 413 | break; |
||
| 414 | case 'import': |
||
| 415 | if (isset($attrs['schemaLocation'])) {
|
||
| 416 | $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']);
|
||
| 417 | $this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
|
||
| 418 | } else {
|
||
| 419 | $this->xdebug('import namespace ' . $attrs['namespace']);
|
||
| 420 | $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
|
||
| 421 | if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
|
||
| 422 | $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace']; |
||
| 423 | } |
||
| 424 | } |
||
| 425 | break; |
||
| 426 | case 'include': |
||
| 427 | if (isset($attrs['schemaLocation'])) {
|
||
| 428 | $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']);
|
||
| 429 | $this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
|
||
| 430 | } else {
|
||
| 431 | $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute');
|
||
| 432 | } |
||
| 433 | break; |
||
| 434 | case 'list': // simpleType value list |
||
| 435 | $this->xdebug("do nothing for element $name");
|
||
| 436 | break; |
||
| 437 | case 'restriction': // simpleType, simpleContent or complexContent value restriction |
||
| 438 | $this->xdebug('restriction ' . $attrs['base']);
|
||
| 439 | if($this->currentSimpleType){
|
||
| 440 | $this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base']; |
||
| 441 | } elseif($this->currentComplexType){
|
||
| 442 | $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base']; |
||
| 443 | if(strstr($attrs['base'],':') == ':Array'){
|
||
| 444 | $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
||
| 445 | } |
||
| 446 | } |
||
| 447 | break; |
||
| 448 | case 'schema': |
||
| 449 | $this->schemaInfo = $attrs; |
||
| 450 | $this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix); |
||
| 451 | if (isset($attrs['targetNamespace'])) {
|
||
| 452 | $this->schemaTargetNamespace = $attrs['targetNamespace']; |
||
| 453 | } |
||
| 454 | if (!isset($attrs['elementFormDefault'])) {
|
||
| 455 | $this->schemaInfo['elementFormDefault'] = 'unqualified'; |
||
| 456 | } |
||
| 457 | if (!isset($attrs['attributeFormDefault'])) {
|
||
| 458 | $this->schemaInfo['attributeFormDefault'] = 'unqualified'; |
||
| 459 | } |
||
| 460 | break; |
||
| 461 | case 'simpleContent': // (optional) content for a complexType |
||
| 462 | if ($this->currentComplexType) { // This should *always* be
|
||
| 463 | $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true'; |
||
| 464 | } else {
|
||
| 465 | $this->xdebug("do nothing for element $name because there is no current complexType");
|
||
| 466 | } |
||
| 467 | break; |
||
| 468 | case 'simpleType': |
||
| 469 | array_push($this->simpleTypeStack, $this->currentSimpleType); |
||
| 470 | if(isset($attrs['name'])){
|
||
| 471 | $this->xdebug("processing simpleType for name " . $attrs['name']);
|
||
| 472 | $this->currentSimpleType = $attrs['name']; |
||
| 473 | $this->simpleTypes[ $attrs['name'] ] = $attrs; |
||
| 474 | $this->simpleTypes[ $attrs['name'] ]['typeClass'] = 'simpleType'; |
||
| 475 | $this->simpleTypes[ $attrs['name'] ]['phpType'] = 'scalar'; |
||
| 476 | } else {
|
||
| 477 | $name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement); |
||
| 478 | $this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name);
|
||
| 479 | $this->currentSimpleType = $name; |
||
| 480 | //$this->currentElement = false; |
||
| 481 | $this->simpleTypes[$this->currentSimpleType] = $attrs; |
||
| 482 | $this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar'; |
||
| 483 | } |
||
| 484 | break; |
||
| 485 | case 'union': // simpleType type list |
||
| 486 | $this->xdebug("do nothing for element $name");
|
||
| 487 | break; |
||
| 488 | default: |
||
| 489 | $this->xdebug("do not have any logic to process element $name");
|
||
| 490 | } |
||
| 970 | ?> |