| Total Complexity | 97 |
| Total Lines | 586 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like InheritableNameAttributesTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use InheritableNameAttributesTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 36 | trait InheritableNameAttributesTrait |
||
| 37 | { |
||
| 38 | public static $attributes = [ |
||
| 39 | 'and', |
||
| 40 | 'delimiter-precedes-et-al', |
||
| 41 | 'delimiter-precedes-last', |
||
| 42 | 'et-al-min', |
||
| 43 | 'et-al-use-first', |
||
| 44 | 'et-al-use-last', |
||
| 45 | 'et-al-subsequent-min', |
||
| 46 | 'et-al-subsequent-use-first', |
||
| 47 | 'initialize', |
||
| 48 | 'initialize-with', |
||
| 49 | 'name-as-sort-order', |
||
| 50 | 'sort-separator', |
||
| 51 | 'name-form', |
||
| 52 | 'form', |
||
| 53 | 'name-delimiter', |
||
| 54 | 'delimiter' |
||
| 55 | ]; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var bool |
||
| 59 | */ |
||
| 60 | protected $attributesInitialized = false; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Specifies the delimiter between the second to last and last name of the names in a name variable. Allowed values |
||
| 64 | * are “text” (selects the “and” term, e.g. “Doe, Johnson and Smith”) and “symbol” (selects the ampersand, |
||
| 65 | * e.g. “Doe, Johnson & Smith”). |
||
| 66 | * |
||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | private $and; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Determines when the name delimiter or a space is used between a truncated name list and the “et-al” |
||
| 73 | * (or “and others”) term in case of et-al abbreviation. Allowed values: |
||
| 74 | * - “contextual” - (default), name delimiter is only used for name lists truncated to two or more names |
||
| 75 | * - 1 name: “J. Doe et al.” |
||
| 76 | * - 2 names: “J. Doe, S. Smith, et al.” |
||
| 77 | * - “after-inverted-name” - name delimiter is only used if the preceding name is inverted as a result of the |
||
| 78 | * - name-as-sort-order attribute. E.g. with name-as-sort-order set to “first”: |
||
| 79 | * - “Doe, J., et al.” |
||
| 80 | * - “Doe, J., S. Smith et al.” |
||
| 81 | * - “always” - name delimiter is always used |
||
| 82 | * - 1 name: “J. Doe, et al.” |
||
| 83 | * - 2 names: “J. Doe, S. Smith, et al.” |
||
| 84 | * - “never” - name delimiter is never used |
||
| 85 | * - 1 name: “J. Doe et al.” |
||
| 86 | * - 2 names: “J. Doe, S. Smith et al.” |
||
| 87 | * |
||
| 88 | * @var string |
||
| 89 | */ |
||
| 90 | private $delimiterPrecedesEtAl; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Determines when the name delimiter is used to separate the second to last and the last name in name lists (if |
||
| 94 | * and is not set, the name delimiter is always used, regardless of the value of delimiter-precedes-last). Allowed |
||
| 95 | * values: |
||
| 96 | * |
||
| 97 | * - “contextual” - (default), name delimiter is only used for name lists with three or more names |
||
| 98 | * - 2 names: “J. Doe and T. Williams” |
||
| 99 | * - 3 names: “J. Doe, S. Smith, and T. Williams” |
||
| 100 | * - “after-inverted-name” - name delimiter is only used if the preceding name is inverted as a result of the |
||
| 101 | * name-as-sort-order attribute. E.g. with name-as-sort-order set to “first”: |
||
| 102 | * - “Doe, J., and T. Williams” |
||
| 103 | * - “Doe, J., S. Smith and T. Williams” |
||
| 104 | * - “always” - name delimiter is always used |
||
| 105 | * - 2 names: “J. Doe, and T. Williams” |
||
| 106 | * - 3 names: “J. Doe, S. Smith, and T. Williams” |
||
| 107 | * - “never” - name delimiter is never used |
||
| 108 | * - 2 names: “J. Doe and T. Williams” |
||
| 109 | * - 3 names: “J. Doe, S. Smith and T. Williams” |
||
| 110 | * |
||
| 111 | * @var string |
||
| 112 | */ |
||
| 113 | private $delimiterPrecedesLast; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Use of etAlMin (et-al-min attribute) and etAlUseFirst (et-al-use-first attribute) enables et-al abbreviation. If |
||
| 117 | * the number of names in a name variable matches or exceeds the number set on etAlMin, the rendered name list is |
||
| 118 | * truncated after reaching the number of names set on etAlUseFirst. |
||
| 119 | * |
||
| 120 | * @var int |
||
| 121 | */ |
||
| 122 | private $etAlMin; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Use of etAlMin (et-al-min attribute) and etAlUseFirst (et-al-use-first attribute) enables et-al abbreviation. If |
||
| 126 | * the number of names in a name variable matches or exceeds the number set on etAlMin, the rendered name list is |
||
| 127 | * truncated after reaching the number of names set on etAlUseFirst. |
||
| 128 | * |
||
| 129 | * @var int |
||
| 130 | */ |
||
| 131 | private $etAlUseFirst; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * When set to “true” (the default is “false”), name lists truncated by et-al abbreviation are followed by the name |
||
| 135 | * delimiter, the ellipsis character, and the last name of the original name list. This is only possible when the |
||
| 136 | * original name list has at least two more names than the truncated name list (for this the value of |
||
| 137 | * et-al-use-first/et-al-subsequent-min must be at least 2 less than the value of |
||
| 138 | * et-al-min/et-al-subsequent-use-first). |
||
| 139 | * |
||
| 140 | * @var bool |
||
| 141 | */ |
||
| 142 | private $etAlUseLast = false; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * If used, the values of these attributes (et-al-subsequent-min and et-al-subsequent-use-first) replace those of |
||
| 146 | * respectively et-al-min and et-al-use-first for subsequent cites (cites referencing earlier cited items). |
||
| 147 | * |
||
| 148 | * @var int |
||
| 149 | */ |
||
| 150 | private $etAlSubsequentMin; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * If used, the values of these attributes (et-al-subsequent-min and et-al-subsequent-use-first) replace those of |
||
| 154 | * respectively et-al-min and et-al-use-first for subsequent cites (cites referencing earlier cited items). |
||
| 155 | * |
||
| 156 | * @var int |
||
| 157 | */ |
||
| 158 | private $etAlSubsequentUseFirst; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * When set to “false” (the default is “true”), given names are no longer initialized when “initialize-with” is set. |
||
| 162 | * However, the value of “initialize-with” is still added after initials present in the full name (e.g. with |
||
| 163 | * initialize set to “false”, and initialize-with set to ”.”, “James T Kirk” becomes “James T. Kirk”). |
||
| 164 | * |
||
| 165 | * @var bool |
||
| 166 | */ |
||
| 167 | private $initialize = true; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * When set, given names are converted to initials. The attribute value is added after each initial (”.” results |
||
| 171 | * in “J.J. Doe”). For compound given names (e.g. “Jean-Luc”), hyphenation of the initials can be controlled with |
||
| 172 | * the global initialize-with-hyphen option |
||
| 173 | * |
||
| 174 | * @var string |
||
| 175 | */ |
||
| 176 | private $initializeWith = false; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Specifies that names should be displayed with the given name following the family name (e.g. “John Doe” becomes |
||
| 180 | * “Doe, John”). The attribute has two possible values: |
||
| 181 | * - “first” - attribute only has an effect on the first name of each name variable |
||
| 182 | * - “all” - attribute has an effect on all names |
||
| 183 | * Note that even when name-as-sort-order changes the name-part order, the display order is not necessarily the same |
||
| 184 | * as the sorting order for names containing particles and suffixes (see Name-part order). Also, name-as-sort-order |
||
| 185 | * only affects names written in the latin or Cyrillic alphabets. Names written in other alphabets (e.g. Asian |
||
| 186 | * scripts) are always displayed with the family name preceding the given name. |
||
| 187 | * |
||
| 188 | * @var string |
||
| 189 | */ |
||
| 190 | private $nameAsSortOrder = ""; |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Sets the delimiter for name-parts that have switched positions as a result of name-as-sort-order. The default |
||
| 194 | * value is ”, ” (“Doe, John”). As is the case for name-as-sort-order, this attribute only affects names written in |
||
| 195 | * the latin or Cyrillic alphabets. |
||
| 196 | * |
||
| 197 | * @var string |
||
| 198 | */ |
||
| 199 | private $sortSeparator = ", "; |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Specifies whether all the name-parts of personal names should be displayed (value “long”, the default), or only |
||
| 203 | * the family name and the non-dropping-particle (value “short”). A third value, “count”, returns the total number |
||
| 204 | * of names that would otherwise be rendered by the use of the cs:names element (taking into account the effects of |
||
| 205 | * et-al abbreviation and editor/translator collapsing), which allows for advanced sorting. |
||
| 206 | * |
||
| 207 | * @var string |
||
| 208 | */ |
||
| 209 | private $form; |
||
| 210 | |||
| 211 | private $nameForm = "long"; |
||
| 212 | |||
| 213 | private $nameDelimiter = ", "; |
||
| 214 | |||
| 215 | public function isDescendantOfMacro() |
||
| 226 | } |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @param SimpleXMLElement $node |
||
| 230 | */ |
||
| 231 | public function initInheritableNameAttributes(SimpleXMLElement $node) |
||
| 382 | } |
||
| 383 | |||
| 384 | /** |
||
| 385 | * @return string |
||
| 386 | */ |
||
| 387 | public function getAnd() |
||
| 388 | { |
||
| 389 | return $this->and; |
||
| 390 | } |
||
| 391 | |||
| 392 | /** |
||
| 393 | * @param string $and |
||
| 394 | */ |
||
| 395 | public function setAnd($and) |
||
| 396 | { |
||
| 397 | $this->and = $and; |
||
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @return string |
||
| 402 | */ |
||
| 403 | public function getDelimiterPrecedesEtAl() |
||
| 404 | { |
||
| 405 | return $this->delimiterPrecedesEtAl; |
||
| 406 | } |
||
| 407 | |||
| 408 | /** |
||
| 409 | * @param string $delimiterPrecedesEtAl |
||
| 410 | */ |
||
| 411 | public function setDelimiterPrecedesEtAl($delimiterPrecedesEtAl) |
||
| 412 | { |
||
| 413 | $this->delimiterPrecedesEtAl = $delimiterPrecedesEtAl; |
||
| 414 | } |
||
| 415 | |||
| 416 | /** |
||
| 417 | * @return string |
||
| 418 | */ |
||
| 419 | public function getDelimiterPrecedesLast() |
||
| 420 | { |
||
| 421 | return $this->delimiterPrecedesLast; |
||
| 422 | } |
||
| 423 | |||
| 424 | /** |
||
| 425 | * @param string $delimiterPrecedesLast |
||
| 426 | */ |
||
| 427 | public function setDelimiterPrecedesLast($delimiterPrecedesLast) |
||
| 428 | { |
||
| 429 | $this->delimiterPrecedesLast = $delimiterPrecedesLast; |
||
| 430 | } |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @return int |
||
| 434 | */ |
||
| 435 | public function getEtAlMin() |
||
| 436 | { |
||
| 437 | return $this->etAlMin; |
||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * @param int $etAlMin |
||
| 442 | */ |
||
| 443 | public function setEtAlMin($etAlMin) |
||
| 444 | { |
||
| 445 | $this->etAlMin = $etAlMin; |
||
| 446 | } |
||
| 447 | |||
| 448 | /** |
||
| 449 | * @return int |
||
| 450 | */ |
||
| 451 | public function getEtAlUseFirst() |
||
| 452 | { |
||
| 453 | return $this->etAlUseFirst; |
||
| 454 | } |
||
| 455 | |||
| 456 | /** |
||
| 457 | * @param int $etAlUseFirst |
||
| 458 | */ |
||
| 459 | public function setEtAlUseFirst($etAlUseFirst) |
||
| 460 | { |
||
| 461 | $this->etAlUseFirst = $etAlUseFirst; |
||
| 462 | } |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @return bool |
||
| 466 | */ |
||
| 467 | public function getEtAlUseLast() |
||
| 468 | { |
||
| 469 | return $this->etAlUseLast; |
||
| 470 | } |
||
| 471 | |||
| 472 | /** |
||
| 473 | * @param bool $etAlUseLast |
||
| 474 | */ |
||
| 475 | public function setEtAlUseLast($etAlUseLast) |
||
| 476 | { |
||
| 477 | $this->etAlUseLast = $etAlUseLast; |
||
| 478 | } |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @return int |
||
| 482 | */ |
||
| 483 | public function getEtAlSubsequentMin() |
||
| 484 | { |
||
| 485 | return $this->etAlSubsequentMin; |
||
| 486 | } |
||
| 487 | |||
| 488 | /** |
||
| 489 | * @param int $etAlSubsequentMin |
||
| 490 | */ |
||
| 491 | public function setEtAlSubsequentMin($etAlSubsequentMin) |
||
| 492 | { |
||
| 493 | $this->etAlSubsequentMin = $etAlSubsequentMin; |
||
| 494 | } |
||
| 495 | |||
| 496 | /** |
||
| 497 | * @return int |
||
| 498 | */ |
||
| 499 | public function getEtAlSubsequentUseFirst() |
||
| 500 | { |
||
| 501 | return $this->etAlSubsequentUseFirst; |
||
| 502 | } |
||
| 503 | |||
| 504 | /** |
||
| 505 | * @param int $etAlSubsequentUseFirst |
||
| 506 | */ |
||
| 507 | public function setEtAlSubsequentUseFirst($etAlSubsequentUseFirst) |
||
| 508 | { |
||
| 509 | $this->etAlSubsequentUseFirst = $etAlSubsequentUseFirst; |
||
| 510 | } |
||
| 511 | |||
| 512 | /** |
||
| 513 | * @return bool |
||
| 514 | */ |
||
| 515 | public function getInitialize() |
||
| 516 | { |
||
| 517 | return $this->initialize; |
||
| 518 | } |
||
| 519 | |||
| 520 | /** |
||
| 521 | * @param bool $initialize |
||
| 522 | */ |
||
| 523 | public function setInitialize($initialize) |
||
| 524 | { |
||
| 525 | $this->initialize = $initialize; |
||
| 526 | } |
||
| 527 | |||
| 528 | /** |
||
| 529 | * @return string |
||
| 530 | */ |
||
| 531 | public function getInitializeWith() |
||
| 532 | { |
||
| 533 | return $this->initializeWith; |
||
| 534 | } |
||
| 535 | |||
| 536 | /** |
||
| 537 | * @param string $initializeWith |
||
| 538 | */ |
||
| 539 | public function setInitializeWith($initializeWith) |
||
| 540 | { |
||
| 541 | $this->initializeWith = $initializeWith; |
||
| 542 | } |
||
| 543 | |||
| 544 | /** |
||
| 545 | * @return string |
||
| 546 | */ |
||
| 547 | public function getNameAsSortOrder() |
||
| 548 | { |
||
| 549 | return $this->nameAsSortOrder; |
||
| 550 | } |
||
| 551 | |||
| 552 | /** |
||
| 553 | * @param string $nameAsSortOrder |
||
| 554 | */ |
||
| 555 | public function setNameAsSortOrder($nameAsSortOrder) |
||
| 556 | { |
||
| 557 | $this->nameAsSortOrder = $nameAsSortOrder; |
||
| 558 | } |
||
| 559 | |||
| 560 | /** |
||
| 561 | * @return string |
||
| 562 | */ |
||
| 563 | public function getSortSeparator() |
||
| 564 | { |
||
| 565 | return $this->sortSeparator; |
||
| 566 | } |
||
| 567 | |||
| 568 | /** |
||
| 569 | * @param string $sortSeparator |
||
| 570 | */ |
||
| 571 | public function setSortSeparator($sortSeparator) |
||
| 572 | { |
||
| 573 | $this->sortSeparator = $sortSeparator; |
||
| 574 | } |
||
| 575 | |||
| 576 | /** |
||
| 577 | * @return mixed |
||
| 578 | */ |
||
| 579 | public function getForm() |
||
| 580 | { |
||
| 581 | return $this->form; |
||
| 582 | } |
||
| 583 | |||
| 584 | /** |
||
| 585 | * @param mixed $form |
||
| 586 | */ |
||
| 587 | public function setForm($form) |
||
| 588 | { |
||
| 589 | $this->form = $form; |
||
| 590 | } |
||
| 591 | |||
| 592 | /** |
||
| 593 | * @return string |
||
| 594 | */ |
||
| 595 | public function getNameForm() |
||
| 596 | { |
||
| 597 | return $this->nameForm; |
||
| 598 | } |
||
| 599 | |||
| 600 | /** |
||
| 601 | * @param string $nameForm |
||
| 602 | */ |
||
| 603 | public function setNameForm($nameForm) |
||
| 604 | { |
||
| 605 | $this->nameForm = $nameForm; |
||
| 606 | } |
||
| 607 | |||
| 608 | /** |
||
| 609 | * @return string |
||
| 610 | */ |
||
| 611 | public function getNameDelimiter() |
||
| 614 | } |
||
| 615 | |||
| 616 | /** |
||
| 617 | * @param string $nameDelimiter |
||
| 618 | */ |
||
| 619 | public function setNameDelimiter($nameDelimiter) |
||
| 620 | { |
||
| 621 | $this->nameDelimiter = $nameDelimiter; |
||
| 622 | } |
||
| 623 | } |
||
| 624 |