Conditions | 116 |
Paths | > 20000 |
Total Lines | 361 |
Code Lines | 219 |
Lines | 132 |
Ratio | 36.57 % |
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 |
||
351 | public function parseLdmlTree($ldmlTree, &$data) |
||
352 | { |
||
353 | |||
354 | if (isset($ldmlTree->identity)) { |
||
355 | $data['locale']['language'] = $ldmlTree->identity->language->getAttribute('type'); |
||
356 | View Code Duplication | if (isset($ldmlTree->identity->territory)) { |
|
357 | $data['locale']['territory'] = $ldmlTree->identity->territory->getAttribute('type'); |
||
358 | } |
||
359 | View Code Duplication | if (isset($ldmlTree->identity->script)) { |
|
360 | $data['locale']['script'] = $ldmlTree->identity->script->getAttribute('type'); |
||
361 | } |
||
362 | View Code Duplication | if (isset($ldmlTree->identity->variant)) { |
|
363 | $data['locale']['variant'] = $ldmlTree->identity->variant->getAttribute('type'); |
||
364 | } |
||
365 | } |
||
366 | |||
367 | if (isset($ldmlTree->localeDisplayNames)) { |
||
368 | $ldn = $ldmlTree->localeDisplayNames; |
||
369 | |||
370 | View Code Duplication | if (isset($ldn->languages)) { |
|
371 | $data['displayNames']['languages'] = isset($data['displayNames']['languages']) ? $data['displayNames']['languages'] : array(); |
||
372 | $this->getTypeList($ldn->languages, $data['displayNames']['languages']); |
||
373 | } |
||
374 | |||
375 | View Code Duplication | if (isset($ldn->scripts)) { |
|
376 | $data['displayNames']['scripts'] = isset($data['displayNames']['scripts']) ? $data['displayNames']['scripts'] : array(); |
||
377 | $this->getTypeList($ldn->scripts, $data['displayNames']['scripts']); |
||
378 | } |
||
379 | |||
380 | View Code Duplication | if (isset($ldn->territories)) { |
|
381 | $data['displayNames']['territories'] = isset($data['displayNames']['territories']) ? $data['displayNames']['territories'] : array(); |
||
382 | $this->getTypeList($ldn->territories, $data['displayNames']['territories']); |
||
383 | } |
||
384 | |||
385 | View Code Duplication | if (isset($ldn->variants)) { |
|
386 | $data['displayNames']['variants'] = isset($data['displayNames']['variants']) ? $data['displayNames']['variants'] : array(); |
||
387 | $this->getTypeList($ldn->variants, $data['displayNames']['variants']); |
||
388 | } |
||
389 | |||
390 | View Code Duplication | if (isset($ldn->keys)) { |
|
391 | $data['displayNames']['keys'] = isset($data['displayNames']['keys']) ? $data['displayNames']['keys'] : array(); |
||
392 | $this->getTypeList($ldn->keys, $data['displayNames']['keys']); |
||
393 | } |
||
394 | |||
395 | /* |
||
396 | // not needed right now |
||
397 | if(isset($ldn->types)) { |
||
398 | } |
||
399 | */ |
||
400 | |||
401 | View Code Duplication | if (isset($ldn->measurementSystemNames)) { |
|
402 | $data['displayNames']['measurementSystemNames'] = isset($data['displayNames']['measurementSystemNames']) ? $data['displayNames']['measurementSystemNames'] : array(); |
||
403 | $this->getTypeList($ldn->measurementSystemNames, $data['displayNames']['measurementSystemNames']); |
||
404 | } |
||
405 | } |
||
406 | |||
407 | if (isset($ldmlTree->layout->orientation)) { |
||
408 | $ori = $ldmlTree->layout->orientation; |
||
409 | |||
410 | $data['layout']['orientation']['lines'] = $ori->getAttribute('lines', $data['layout']['orientation']['lines']); |
||
411 | $data['layout']['orientation']['characters'] = $ori->getAttribute('characters', $data['layout']['orientation']['characters']); |
||
412 | } |
||
413 | |||
414 | if (isset($ldmlTree->delimiters)) { |
||
415 | $delims = $ldmlTree->delimiters; |
||
416 | |||
417 | if (isset($delims->quotationStart)) { |
||
418 | $data['delimiters']['quotationStart'] = $this->unescape($delims->quotationStart->getValue()); |
||
419 | } |
||
420 | if (isset($delims->quotationEnd)) { |
||
421 | $data['delimiters']['quotationEnd'] = $this->unescape($delims->quotationEnd->getValue()); |
||
422 | } |
||
423 | if (isset($delims->alternateQuotationStart)) { |
||
424 | $data['delimiters']['alternateQuotationStart'] = $this->unescape($delims->alternateQuotationStart->getValue()); |
||
425 | } |
||
426 | if (isset($delims->alternateQuotationEnd)) { |
||
427 | $data['delimiters']['alternateQuotationEnd'] = $this->unescape($delims->alternateQuotationEnd->getValue()); |
||
428 | } |
||
429 | } |
||
430 | |||
431 | if (isset($ldmlTree->dates)) { |
||
432 | $dates = $ldmlTree->dates; |
||
433 | |||
434 | if (isset($dates->calendars)) { |
||
435 | $cals = $dates->calendars; |
||
436 | |||
437 | foreach ($cals as $calendar) { |
||
438 | if ($calendar->getName() == 'default') { |
||
439 | $data['calendars']['default'] = $calendar->getAttribute('choice'); |
||
440 | } elseif ($calendar->getName() == 'calendar') { |
||
441 | $calendarName = $calendar->getAttribute('type'); |
||
442 | |||
443 | if (!isset($data['calendars'][$calendarName])) { |
||
444 | $data['calendars'][$calendarName] = array(); |
||
445 | } |
||
446 | |||
447 | if (isset($calendar->months)) { |
||
448 | $this->getCalendarWidth($calendar->months, 'month', $data['calendars'][$calendarName]); |
||
449 | } |
||
450 | |||
451 | if (isset($calendar->days)) { |
||
452 | $this->getCalendarWidth($calendar->days, 'day', $data['calendars'][$calendarName]); |
||
453 | } |
||
454 | |||
455 | if (isset($calendar->quarters)) { |
||
456 | $this->getCalendarWidth($calendar->quarters, 'quarter', $data['calendars'][$calendarName]); |
||
457 | } |
||
458 | |||
459 | View Code Duplication | if (isset($calendar->am)) { |
|
460 | $data['calendars'][$calendarName]['am'] = $this->unescape($calendar->am->getValue()); |
||
461 | } |
||
462 | View Code Duplication | if (isset($calendar->pm)) { |
|
463 | $data['calendars'][$calendarName]['pm'] = $this->unescape($calendar->pm->getValue()); |
||
464 | } |
||
465 | |||
466 | if (isset($calendar->eras)) { |
||
467 | View Code Duplication | if (isset($calendar->eras->eraNames)) { |
|
468 | foreach ($this->getChildsOrAlias($calendar->eras->eraNames) as $era) { |
||
469 | $data['calendars'][$calendarName]['eras']['wide'][$era->getAttribute('type')] = $this->unescape($era->getValue()); |
||
470 | } |
||
471 | } |
||
472 | View Code Duplication | if (isset($calendar->eras->eraAbbr)) { |
|
473 | foreach ($this->getChildsOrAlias($calendar->eras->eraAbbr) as $era) { |
||
474 | $data['calendars'][$calendarName]['eras']['abbreviated'][$era->getAttribute('type')] = $this->unescape($era->getValue()); |
||
475 | } |
||
476 | } |
||
477 | View Code Duplication | if (isset($calendar->eras->eraNarrow)) { |
|
478 | foreach ($this->getChildsOrAlias($calendar->eras->eraNarrow) as $era) { |
||
479 | $data['calendars'][$calendarName]['eras']['narrow'][$era->getAttribute('type')] = $this->unescape($era->getValue()); |
||
480 | } |
||
481 | } |
||
482 | } |
||
483 | |||
484 | if (isset($calendar->dateFormats)) { |
||
485 | $this->getDateOrTimeFormats($calendar->dateFormats, 'dateFormat', $data['calendars'][$calendarName]); |
||
486 | } |
||
487 | if (isset($calendar->timeFormats)) { |
||
488 | $this->getDateOrTimeFormats($calendar->timeFormats, 'timeFormat', $data['calendars'][$calendarName]); |
||
489 | } |
||
490 | |||
491 | if (isset($calendar->dateTimeFormats)) { |
||
492 | $dtf = $calendar->dateTimeFormats; |
||
493 | $data['calendars'][$calendarName]['dateTimeFormats']['default'] = isset($dtf->default) ? $dtf->default->getAttribute('choice') : '__default'; |
||
494 | |||
495 | $dtfItems = $this->getChildsOrAlias($dtf); |
||
496 | foreach ($dtfItems as $item) { |
||
497 | if ($item->getName() == 'dateTimeFormatLength') { |
||
498 | if (isset($item->dateTimeFormat->pattern)) { |
||
499 | $data['calendars'][$calendarName]['dateTimeFormats']['formats'][$item->getAttribute('type', '__default')] = $this->unescape($item->dateTimeFormat->pattern->getValue(), true); |
||
500 | } else { |
||
501 | throw new AgaviException('unknown child content in dateTimeFormatLength tag'); |
||
502 | } |
||
503 | } elseif ($item->getName() == 'availableFormats') { |
||
504 | View Code Duplication | foreach ($item as $dateFormatItem) { |
|
505 | if ($dateFormatItem->getName() != 'dateFormatItem') { |
||
506 | throw new AgaviException('unknown childtag "' . $dateFormatItem->getName() . '" in availableFormats tag'); |
||
507 | } |
||
508 | $data['calendars'][$calendarName]['dateTimeFormats']['availableFormats'][$dateFormatItem->getAttribute('id')] = $this->unescape($dateFormatItem->getValue(), true); |
||
509 | } |
||
510 | } elseif ($item->getName() == 'appendItems') { |
||
511 | View Code Duplication | foreach ($item as $appendItem) { |
|
512 | if ($appendItem->getName() != 'appendItem') { |
||
513 | throw new AgaviException('unknown childtag "' . $appendItem->getName() . '" in appendItems tag'); |
||
514 | } |
||
515 | $data['calendars'][$calendarName]['dateTimeFormats']['appendItems'][$appendItem->getAttribute('request')] = $this->unescape($appendItem->getValue(), true); |
||
516 | } |
||
517 | } elseif ($item->getName() != 'default') { |
||
518 | throw new AgaviException('unknown childtag "' . $item->getName() . '" in dateTimeFormats tag'); |
||
519 | } |
||
520 | } |
||
521 | } |
||
522 | |||
523 | if (isset($calendar->fields)) { |
||
524 | foreach ($this->getChildsOrAlias($calendar->fields) as $field) { |
||
525 | $type = $field->getAttribute('type'); |
||
526 | if (isset($field->displayName)) { |
||
527 | $data['calendars'][$calendarName]['fields'][$type]['displayName'] = $this->unescape($field->displayName->getValue()); |
||
528 | } |
||
529 | if (isset($field->relative)) { |
||
530 | foreach ($field as $relative) { |
||
531 | if ($relative->getName() == 'relative') { |
||
532 | $data['calendars'][$calendarName]['fields'][$type]['relatives'][$relative->getAttribute('type')] = $this->unescape($relative->getValue()); |
||
533 | } |
||
534 | } |
||
535 | } |
||
536 | } |
||
537 | } |
||
538 | } else { |
||
539 | throw new AgaviException('unknown childtag "' . $calendar->getName() . '" in calendars tag'); |
||
540 | } |
||
541 | } |
||
542 | } |
||
543 | |||
544 | if (isset($dates->timeZoneNames)) { |
||
545 | $tzn = $dates->timeZoneNames; |
||
546 | if (isset($tzn->hourFormat)) { |
||
547 | $data['timeZoneNames']['hourFormat'] = $this->unescape($tzn->hourFormat->getValue()); |
||
548 | } |
||
549 | if (isset($tzn->hoursFormat)) { |
||
550 | $data['timeZoneNames']['hoursFormat'] = $this->unescape($tzn->hoursFormat->getValue()); |
||
551 | } |
||
552 | if (isset($tzn->gmtFormat)) { |
||
553 | $data['timeZoneNames']['gmtFormat'] = $this->unescape($tzn->gmtFormat->getValue()); |
||
554 | } |
||
555 | if (isset($tzn->regionFormat)) { |
||
556 | $data['timeZoneNames']['regionFormat'] = $this->unescape($tzn->regionFormat->getValue()); |
||
557 | } |
||
558 | if (isset($tzn->fallbackFormat)) { |
||
559 | $data['timeZoneNames']['fallbackFormat'] = $this->unescape($tzn->fallbackFormat->getValue()); |
||
560 | } |
||
561 | if (isset($tzn->abbreviationFallback)) { |
||
562 | $data['timeZoneNames']['abbreviationFallback'] = $tzn->abbreviationFallback->getAttribute('choice'); |
||
563 | } |
||
564 | if (isset($tzn->singleCountries)) { |
||
565 | $data['timeZoneNames']['singleCountries'] = explode(' ', $tzn->singleCountries->getAttribute('list')); |
||
566 | } |
||
567 | |||
568 | foreach ($tzn as $zone) { |
||
569 | $zoneName = $zone->getAttribute('type'); |
||
570 | if ($zone->getName() == 'zone') { |
||
571 | if (isset($zone->long->generic)) { |
||
572 | $data['timeZoneNames']['zones'][$zoneName]['long']['generic'] = $this->unescape($zone->long->generic->getValue()); |
||
573 | } |
||
574 | View Code Duplication | if (isset($zone->long->standard)) { |
|
575 | $data['timeZoneNames']['zones'][$zoneName]['long']['standard'] = $this->unescape($zone->long->standard->getValue()); |
||
576 | } |
||
577 | if (isset($zone->long->daylight)) { |
||
578 | $data['timeZoneNames']['zones'][$zoneName]['long']['daylight'] = $this->unescape($zone->long->daylight->getValue()); |
||
579 | } |
||
580 | View Code Duplication | if (isset($zone->short->generic)) { |
|
581 | $data['timeZoneNames']['zones'][$zoneName]['short']['generic'] = $this->unescape($zone->short->generic->getValue()); |
||
582 | } |
||
583 | View Code Duplication | if (isset($zone->short->standard)) { |
|
584 | $data['timeZoneNames']['zones'][$zoneName]['short']['standard'] = $this->unescape($zone->short->standard->getValue()); |
||
585 | } |
||
586 | View Code Duplication | if (isset($zone->short->daylight)) { |
|
587 | $data['timeZoneNames']['zones'][$zoneName]['short']['daylight'] = $this->unescape($zone->short->daylight->getValue()); |
||
588 | } |
||
589 | if (isset($zone->exemplarCity)) { |
||
590 | $data['timeZoneNames']['zones'][$zoneName]['exemplarCity'] = $this->unescape($zone->exemplarCity->getValue()); |
||
591 | } |
||
592 | } |
||
593 | } |
||
594 | } |
||
595 | } |
||
596 | |||
597 | if (isset($ldmlTree->numbers)) { |
||
598 | $nums = $ldmlTree->numbers; |
||
599 | if (!isset($data['numbers'])) { |
||
600 | $data['numbers'] = array(); |
||
601 | } |
||
602 | |||
603 | if (isset($nums->symbols)) { |
||
604 | $syms = $nums->symbols; |
||
605 | View Code Duplication | if (isset($syms->decimal)) { |
|
606 | $data['numbers']['symbols']['decimal'] = $this->unescape($syms->decimal->getValue()); |
||
607 | } |
||
608 | View Code Duplication | if (isset($syms->group)) { |
|
609 | $data['numbers']['symbols']['group'] = $this->unescape($syms->group->getValue()); |
||
610 | } |
||
611 | View Code Duplication | if (isset($syms->list)) { |
|
612 | $data['numbers']['symbols']['list'] = $this->unescape($syms->list->getValue()); |
||
613 | } |
||
614 | View Code Duplication | if (isset($syms->percentSign)) { |
|
615 | $data['numbers']['symbols']['percentSign'] = $this->unescape($syms->percentSign->getValue()); |
||
616 | } |
||
617 | View Code Duplication | if (isset($syms->nativeZeroDigit)) { |
|
618 | $data['numbers']['symbols']['nativeZeroDigit'] = $this->unescape($syms->nativeZeroDigit->getValue()); |
||
619 | } |
||
620 | View Code Duplication | if (isset($syms->patternDigit)) { |
|
621 | $data['numbers']['symbols']['patternDigit'] = $this->unescape($syms->patternDigit->getValue()); |
||
622 | } |
||
623 | View Code Duplication | if (isset($syms->plusSign)) { |
|
624 | $data['numbers']['symbols']['plusSign'] = $this->unescape($syms->plusSign->getValue()); |
||
625 | } |
||
626 | View Code Duplication | if (isset($syms->minusSign)) { |
|
627 | $data['numbers']['symbols']['minusSign'] = $this->unescape($syms->minusSign->getValue()); |
||
628 | } |
||
629 | View Code Duplication | if (isset($syms->exponential)) { |
|
630 | $data['numbers']['symbols']['exponential'] = $this->unescape($syms->exponential->getValue()); |
||
631 | } |
||
632 | View Code Duplication | if (isset($syms->perMille)) { |
|
633 | $data['numbers']['symbols']['perMille'] = $this->unescape($syms->perMille->getValue()); |
||
634 | } |
||
635 | View Code Duplication | if (isset($syms->infinity)) { |
|
636 | $data['numbers']['symbols']['infinity'] = $this->unescape($syms->infinity->getValue()); |
||
637 | } |
||
638 | View Code Duplication | if (isset($syms->nan)) { |
|
639 | $data['numbers']['symbols']['nan'] = $this->unescape($syms->nan->getValue()); |
||
640 | } |
||
641 | } |
||
642 | if (isset($nums->decimalFormats)) { |
||
643 | $this->getNumberFormats($nums->decimalFormats, 'decimalFormat', $data['numbers']); |
||
644 | } |
||
645 | if (isset($nums->scientificFormats)) { |
||
646 | $this->getNumberFormats($nums->scientificFormats, 'scientificFormat', $data['numbers']); |
||
647 | } |
||
648 | if (isset($nums->percentFormats)) { |
||
649 | $this->getNumberFormats($nums->percentFormats, 'percentFormat', $data['numbers']); |
||
650 | } |
||
651 | if (isset($nums->currencyFormats)) { |
||
652 | $cf = $nums->currencyFormats; |
||
653 | |||
654 | foreach ($this->getChildsOrAlias($cf) as $itemLength) { |
||
655 | if ($itemLength->getName() == 'default') { |
||
656 | $data['numbers']['currencyFormats']['default'] = $itemLength->getAttribute('choice'); |
||
657 | } elseif ($itemLength->getName() == 'currencyFormatLength') { |
||
658 | $itemLengthName = $itemLength->getAttribute('type', '__default'); |
||
659 | |||
660 | foreach ($this->getChildsOrAlias($itemLength) as $itemFormat) { |
||
661 | if ($itemFormat->getName() == 'currencyFormat') { |
||
662 | if (isset($itemFormat->pattern)) { |
||
663 | $data['numbers']['currencyFormats'][$itemLengthName] = $this->unescape($itemFormat->pattern->getValue()); |
||
664 | } |
||
665 | } else { |
||
666 | throw new AgaviException('unknown childtag "' . $itemFormat->getName() . '" in currencyFormatLength tag'); |
||
667 | } |
||
668 | } |
||
669 | } elseif ($itemLength->getName() == 'currencySpacing') { |
||
670 | View Code Duplication | if (isset($itemLength->beforeCurrency->currencyMatch)) { |
|
671 | $data['numbers']['currencySpacing']['beforeCurrency']['currencyMatch'] = $this->unescape($itemLength->beforeCurrency->currencyMatch->getValue()); |
||
672 | } |
||
673 | View Code Duplication | if (isset($itemLength->beforeCurrency->surroundingMatch)) { |
|
674 | $data['numbers']['currencySpacing']['beforeCurrency']['surroundingMatch'] = $this->unescape($itemLength->beforeCurrency->surroundingMatch->getValue()); |
||
675 | } |
||
676 | View Code Duplication | if (isset($itemLength->beforeCurrency->insertBetween)) { |
|
677 | $data['numbers']['currencySpacing']['beforeCurrency']['insertBetween'] = $this->unescape($itemLength->beforeCurrency->insertBetween->getValue()); |
||
678 | } |
||
679 | View Code Duplication | if (isset($itemLength->afterCurrency->currencyMatch)) { |
|
680 | $data['numbers']['currencySpacing']['afterCurrency']['currencyMatch'] = $this->unescape($itemLength->afterCurrency->currencyMatch->getValue()); |
||
681 | } |
||
682 | View Code Duplication | if (isset($itemLength->afterCurrency->surroundingMatch)) { |
|
683 | $data['numbers']['currencySpacing']['afterCurrency']['surroundingMatch'] = $this->unescape($itemLength->afterCurrency->surroundingMatch->getValue()); |
||
684 | } |
||
685 | View Code Duplication | if (isset($itemLength->afterCurrency->insertBetween)) { |
|
686 | $data['numbers']['currencySpacing']['afterCurrency']['insertBetween'] = $this->unescape($itemLength->afterCurrency->insertBetween->getValue()); |
||
687 | } |
||
688 | } else { |
||
689 | throw new AgaviException('unknown childtag "' . $itemLength->getName() . '" in currencyFormats tag'); |
||
690 | } |
||
691 | } |
||
692 | } |
||
693 | if (isset($nums->currencies)) { |
||
694 | foreach ($nums->currencies as $currency) { |
||
695 | $name = $currency->getAttribute('type'); |
||
696 | if (isset($currency->displayName)) { |
||
697 | $data['numbers']['currencies'][$name]['displayName'] = $this->unescape($currency->displayName->getValue()); |
||
698 | } |
||
699 | if (isset($currency->symbol)) { |
||
700 | $symbolValue = $this->unescape($currency->symbol->getValue()); |
||
701 | if ($currency->symbol->getAttribute('choice') == 'true') { |
||
702 | $symbolValue = explode('|', $symbolValue); |
||
703 | } |
||
704 | $data['numbers']['currencies'][$name]['symbol'] = $symbolValue; |
||
705 | } |
||
706 | } |
||
707 | } |
||
708 | } |
||
709 | |||
710 | return $data; |
||
711 | } |
||
712 | |||
1038 |