| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * citeproc-php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @link        http://github.com/seboettg/citeproc-php for the source repository | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright   Copyright (c) 2016 Sebastian Böttger. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license     https://opensource.org/licenses/MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | namespace Seboettg\CiteProc\Rendering\Name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Seboettg\CiteProc\CiteProc; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Seboettg\CiteProc\Exception\CiteProcException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Seboettg\CiteProc\Rendering\HasParent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Seboettg\CiteProc\Style\InheritableNameAttributesTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Seboettg\CiteProc\Style\Options\DemoteNonDroppingParticle; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Seboettg\CiteProc\Style\Options\SubsequentAuthorSubstituteRule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Seboettg\CiteProc\Styles\AffixesTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Seboettg\CiteProc\Styles\DelimiterTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Seboettg\CiteProc\Styles\FormattingTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Seboettg\CiteProc\Util\Factory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Seboettg\CiteProc\Util\NameHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Seboettg\CiteProc\Util\StringHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * Class Name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * The cs:name element, an optional child element of cs:names, can be used to describe the formatting of individual | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * names, and the separation of names within a name variable. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * @package Seboettg\CiteProc\Rendering\Name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * @author Sebastian Böttger <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | class Name implements HasParent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     use InheritableNameAttributesTrait, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         FormattingTrait, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         AffixesTrait, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         DelimiterTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     protected $nameParts; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * Specifies the text string used to separate names in a name variable. Default is ”, ” (e.g. “Doe, Smith”). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @var | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     private $delimiter = ", "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @var Names | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     private $parent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @var \SimpleXMLElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     private $node; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     private $etAl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * Name constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @param \SimpleXMLElement $node | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @param Names $parent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     public function __construct(\SimpleXMLElement $node, Names $parent) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $this->node = $node; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $this->parent = $parent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $this->nameParts = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         /** @var \SimpleXMLElement $child */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         foreach ($node->children() as $child) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             switch ($child->getName()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                 case "name-part": | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                     /** @var NamePart $namePart */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                     $namePart = Factory::create($child, $this); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                     $this->nameParts[$namePart->getName()] = $namePart; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         foreach ($node->attributes() as $attribute) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             switch ($attribute->getName()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                 case 'form': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                     $this->form = (string)$attribute; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $this->initFormattingAttributes($node); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $this->initAffixesAttributes($node); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $this->initDelimiterAttributes($node); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * @param array $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * @param integer|null $citationNumber | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * @return string | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     public function render($data, $citationNumber = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         if (!$this->attributesInitialized) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             $this->initInheritableNameAttributes($this->node); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         if ("text" === $this->and) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             $this->and = CiteProc::getContext()->getLocale()->filter('terms', 'and')->single; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         } elseif ('symbol' === $this->and) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             $this->and = '&'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         $resultNames = $this->handleSubsequentAuthorSubstitution($data, $citationNumber); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         if (empty($resultNames)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             return CiteProc::getContext()->getCitationItems()->getSubsequentAuthorSubstitute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         $resultNames = $this->prepareAbbreviation($resultNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         /* When set to “true” (the default is “false”), name lists truncated by et-al abbreviation are followed by | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         the name delimiter, the ellipsis character, and the last name of the original name list. This is only | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         possible when the original name list has at least two more names than the truncated name list (for this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         the value of et-al-use-first/et-al-subsequent-min must be at least 2 less than the value of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         et-al-min/et-al-subsequent-use-first). */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         if ($this->etAlUseLast) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |             $this->and = "…"; // set "and" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |             $this->etAl = null; //reset $etAl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         /* add "and" */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $this->addAnd($resultNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         $text = $this->renderDelimiterPrecedesLast($resultNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         if (empty($text)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             $text = implode($this->delimiter, $resultNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         $text = $this->appendEtAl($data, $text, $resultNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         /* A third value, “count”, returns the total number of names that would otherwise be rendered by the use of the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         cs:names element (taking into account the effects of et-al abbreviation and editor/translator collapsing), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         which allows for advanced sorting. */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         if ($this->form == 'count') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |             return (int)count($resultNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         return $text; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |      * @param \stdClass $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |      * @param int $rank | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     private function formatName($name, $rank) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         $nameObj = $this->cloneNamePOSC($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         $useInitials = $this->initialize && !is_null($this->initializeWith) && $this->initializeWith !== false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         if ($useInitials && isset($name->given)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |             $nameObj->given = StringHelper::initializeBySpaceOrHyphen($name->given, $this->initializeWith); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         $ret = $this->getNamesString($nameObj, $rank); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         return trim($ret); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      * @param \stdClass $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |      * @param int $rank | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |     private function getNamesString($name, $rank) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         $text = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         if (!isset($name->family)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |             return $text; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         $text = $this->nameOrder($name, $rank); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         //contains nbsp prefixed by normal space or followed by normal space? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         $text = htmlentities($text); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         if (strpos($text, "  ") !== false || strpos($text, "  ") !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |             $text = preg_replace("/[\s]+/", "", $text); //remove normal spaces | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |             return preg_replace("/ +/", " ", $text); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |         $text = html_entity_decode(preg_replace("/[\s]+/", " ", $text)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |         return $this->format(trim($text)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |      * @param $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |      * @return \stdClass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |     private function cloneNamePOSC($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         $nameObj = new \stdClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |         if (isset($name->family)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |             $nameObj->family = $name->family; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |         if (isset($name->given)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |             $nameObj->given = $name->given; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |         if (isset($name->{'non-dropping-particle'})) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |             $nameObj->{'non-dropping-particle'} = $name->{'non-dropping-particle'}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         if (isset($name->{'dropping-particle'})) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |             $nameObj->{'dropping-particle'} = $name->{'dropping-particle'}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |         if (isset($name->{'suffix'})) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |             $nameObj->{'suffix'} = $name->{'suffix'}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |         return $nameObj; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |      * @param $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |      * @param $text | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |      * @param $resultNames | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |     protected function appendEtAl($data, $text, $resultNames) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |         //append et al abbreviation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |         if (count($data) > 1 && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |             !empty($resultNames) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |             !empty($this->etAl) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |             !empty($this->etAlMin) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |             !empty($this->etAlUseFirst) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |         ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |             /* By default, when a name list is truncated to a single name, the name and the “et-al” (or “and others”) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |             term are separated by a space (e.g. “Doe et al.”). When a name list is truncated to two or more names, the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |             name delimiter is used (e.g. “Doe, Smith, et al.”). This behavior can be changed with the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |             delimiter-precedes-et-al attribute. */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |             switch ($this->delimiterPrecedesEtAl) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |                 case 'never': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |                     $text = $text . " " . $this->etAl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |                 case 'always': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |                     $text = $text . $this->delimiter . $this->etAl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |                 case 'contextual': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |                 default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |                     if (count($resultNames) === 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |                         $text .= " " . $this->etAl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |                         $text .= $this->delimiter . $this->etAl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |         return $text; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |      * @param $resultNames | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |     protected function prepareAbbreviation($resultNames) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         $cnt = count($resultNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |         /* Use of et-al-min and et-al-user-first enables et-al abbreviation. If the number of names in a name variable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |         matches or exceeds the number set on et-al-min, the rendered name list is truncated after reaching the number of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |         names set on et-al-use-first.  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |         if (isset($this->etAlMin) && isset($this->etAlUseFirst)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |             if ($this->etAlMin <= $cnt) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |                 if ($this->etAlUseLast && $this->etAlMin - $this->etAlUseFirst >= 2) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |                     /* et-al-use-last: When set to “true” (the default is “false”), name lists truncated by et-al | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |                     abbreviation are followed by the name delimiter, the ellipsis character, and the last name of the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |                     original name list. This is only possible when the original name list has at least two more names | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |                     than the truncated name list (for this the value of et-al-use-first/et-al-subsequent-min must be at | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |                     least 2 less than the value of et-al-min/et-al-subsequent-use-first).*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |                     $lastName = array_pop($resultNames); //remove last Element and remember in $lastName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |                 for ($i = $this->etAlUseFirst; $i < $cnt; ++$i) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |                     unset($resultNames[$i]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |                 $resultNames = array_values($resultNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |                 if (!empty($lastName)) { // append $lastName if exist | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |                     $resultNames[] = $lastName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |                 if ($this->parent->hasEtAl()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |                     $this->etAl = $this->parent->getEtAl()->render(null); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |                     return $resultNames; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |                     $this->etAl = CiteProc::getContext()->getLocale()->filter('terms', 'et-al')->single; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |                     return $resultNames; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |             return $resultNames; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |         return $resultNames; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |      * @param $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |      * @param \stdClass $preceding | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |     protected function renderSubsequentSubstitution($data, $preceding) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |         $resultNames = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |         $subsequentSubstitution = CiteProc::getContext()->getCitationItems()->getSubsequentAuthorSubstitute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |         $subsequentSubstitutionRule = CiteProc::getContext()->getCitationItems()->getSubsequentAuthorSubstituteRule(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |          * @var string $type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |          * @var \stdClass $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |         foreach ($data as $rank => $name) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |             switch ($subsequentSubstitutionRule) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |                 /* “partial-each” - when one or more rendered names in the name variable match those in the preceding | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |                 bibliographic entry, the value of subsequent-author-substitute substitutes for each matching name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |                 Matching starts with the first name, and continues up to the first mismatch. */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 341 |  | View Code Duplication |                 case SubsequentAuthorSubstituteRule::PARTIAL_EACH: | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |                     if (NameHelper::precedingHasAuthor($preceding, $name)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |                         $resultNames[] = $subsequentSubstitution; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |                         $resultNames[] = $this->formatName($name, $rank); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |                 /* “partial-first” - as “partial-each”, but substitution is limited to the first name of the name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |                 variable. */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |                 case SubsequentAuthorSubstituteRule::PARTIAL_FIRST: | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |                     if ($rank === 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |                         if ($preceding->author[0]->family === $name->family) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |                             $resultNames[] = $subsequentSubstitution; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |                         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |                             $resultNames[] = $this->formatName($name, $rank); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |                         $resultNames[] = $this->formatName($name, $rank); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |                 /* “complete-each” - requires a complete match like “complete-all”, but now the value of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |                 subsequent-author-substitute substitutes for each rendered name. */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 368 |  | View Code Duplication |                 case SubsequentAuthorSubstituteRule::COMPLETE_EACH: | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |                     if (NameHelper::identicalAuthors($preceding, $data)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |                         $resultNames[] = $subsequentSubstitution; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |                         $resultNames[] = $this->formatName($name, $rank); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |         return $resultNames; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |      * @param array $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |      * @param int $citationNumber | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  |     private function handleSubsequentAuthorSubstitution($data, $citationNumber) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  |         $hasPreceding = CiteProc::getContext()->getCitationItems()->hasKey($citationNumber - 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  |         $subsequentSubstitution = CiteProc::getContext()->getCitationItems()->getSubsequentAuthorSubstitute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |         $subsequentSubstitutionRule = CiteProc::getContext()->getCitationItems()->getSubsequentAuthorSubstituteRule(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |         $preceding = CiteProc::getContext()->getCitationItems()->get($citationNumber - 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |         if ($hasPreceding && !is_null($subsequentSubstitution) && !empty($subsequentSubstitutionRule)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |             /** @var \stdClass $preceding */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |             $identicalAuthors = NameHelper::identicalAuthors($preceding, $data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |             if ($subsequentSubstitutionRule == SubsequentAuthorSubstituteRule::COMPLETE_ALL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |                 if ($identicalAuthors) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  |                     return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |                     $resultNames = $this->getFormattedNames($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  |                 $resultNames = $this->renderSubsequentSubstitution($data, $preceding); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  |             $resultNames = $this->getFormattedNames($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  |         return $resultNames; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  |      * @param array $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  |     protected function getFormattedNames($data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  |         $resultNames = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  |         foreach ($data as $rank => $name) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  |             $resultNames[] = $this->formatName($name, $rank); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  |         return $resultNames; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  |      * @param $resultNames | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  |     protected function renderDelimiterPrecedesLastNever($resultNames) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  |         $text = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  |         if (!$this->etAlUseLast) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  |             if (count($resultNames) === 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  |                 $text = $resultNames[0]; | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 435 |  | View Code Duplication |             } else if (count($resultNames) === 2) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  |                 $text = implode(" ", $resultNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  |             } else { // >2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  |                 $lastName = array_pop($resultNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  |                 $text = implode($this->delimiter, $resultNames) . " " . $lastName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  |         return $text; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  |      * @param $resultNames | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  |     protected function renderDelimiterPrecedesLastContextual($resultNames) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  |     { | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 451 |  | View Code Duplication |         if (count($resultNames) === 1) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  |             $text = $resultNames[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  |         } else if (count($resultNames) === 2) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 454 |  |  |             $text = implode(" ", $resultNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  |             $text = implode($this->delimiter, $resultNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 |  |  |         return $text; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 |  |  |      * @param $resultNames | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 |  |  |     protected function addAnd(&$resultNames) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 |  |  |         $count = count($resultNames); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  |         if (!empty($this->and) && $count > 1 && empty($this->etAl)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  |             $new = $this->and . ' ' . end($resultNames); // add and-prefix of the last name if "and" is defined | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  |             $resultNames[count($resultNames) - 1] = $new; //set prefixed last name at the last position of $resultNames array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  |      * @param $resultNames | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  |      * @return array|string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 476 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 477 |  |  |     protected function renderDelimiterPrecedesLast($resultNames) | 
            
                                                                        
                            
            
                                    
            
            
                | 478 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 479 |  |  |         $text = ""; | 
            
                                                                        
                            
            
                                    
            
            
                | 480 |  |  |         if (!empty($this->and) && empty($this->etAl)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 481 |  |  |             switch ($this->delimiterPrecedesLast) { | 
            
                                                                        
                            
            
                                    
            
            
                | 482 |  |  |                 case 'after-inverted-name': | 
            
                                                                        
                            
            
                                    
            
            
                | 483 |  |  |                     //TODO: implement | 
            
                                                                        
                            
            
                                    
            
            
                | 484 |  |  |                     break; | 
            
                                                                        
                            
            
                                    
            
            
                | 485 |  |  |                 case 'always': | 
            
                                                                        
                            
            
                                    
            
            
                | 486 |  |  |                     $text = implode($this->delimiter, $resultNames); | 
            
                                                                        
                            
            
                                    
            
            
                | 487 |  |  |                     break; | 
            
                                                                        
                            
            
                                    
            
            
                | 488 |  |  |                 case 'never': | 
            
                                                                        
                            
            
                                    
            
            
                | 489 |  |  |                     $text = $this->renderDelimiterPrecedesLastNever($resultNames); | 
            
                                                                        
                            
            
                                    
            
            
                | 490 |  |  |                     break; | 
            
                                                                        
                            
            
                                    
            
            
                | 491 |  |  |                 case 'contextual': | 
            
                                                                        
                            
            
                                    
            
            
                | 492 |  |  |                 default: | 
            
                                                                        
                            
            
                                    
            
            
                | 493 |  |  |                     $text = $this->renderDelimiterPrecedesLastContextual($resultNames); | 
            
                                                                        
                            
            
                                    
            
            
                | 494 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 495 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 496 |  |  |         return $text; | 
            
                                                                        
                            
            
                                    
            
            
                | 497 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 498 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 499 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 500 |  |  |     private function nameOrder($data, $rank) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 501 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 502 |  |  |         $nameAsSortOrder = (($this->nameAsSortOrder === "first" && $rank === 0) || $this->nameAsSortOrder === "all"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 503 |  |  |         $demoteNonDroppingParticle = CiteProc::getContext()->getGlobalOptions()->getDemoteNonDroppingParticles(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 504 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 505 |  |  |         if ($this->form === "long" && $nameAsSortOrder && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 506 |  |  |             ((string)$demoteNonDroppingParticle === DemoteNonDroppingParticle::NEVER || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 507 |  |  |                 (string)$demoteNonDroppingParticle === DemoteNonDroppingParticle::SORT_ONLY) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 508 |  |  |         ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 509 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 510 |  |  |             // [La] [Fontaine], [Jean] [de], [III] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 511 |  |  |             NameHelper::prependParticleTo($data, "family", "non-dropping-particle"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 512 |  |  |             NameHelper::appendParticleTo($data, "given", "dropping-particle"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 513 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 514 |  |  |             list($family, $given) = $this->renderNameParts($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 515 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 516 |  |  |             $text = $family . (!empty($given) ? $this->sortSeparator . $given : ""); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 517 |  |  |             $text .= !empty($data->suffix) ? $this->sortSeparator . $data->suffix : ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 518 |  |  |         } else if ($this->form === "long" && $nameAsSortOrder && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 519 |  |  |             (is_null($demoteNonDroppingParticle) || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 520 |  |  |                 (string)$demoteNonDroppingParticle === DemoteNonDroppingParticle::DISPLAY_AND_SORT) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 521 |  |  |         ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 522 |  |  |             // [Fontaine], [Jean] [de] [La], [III] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 523 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 524 |  |  |             NameHelper::appendParticleTo($data, "given", "dropping-particle"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 525 |  |  |             NameHelper::appendParticleTo($data, "given", "non-dropping-particle"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 526 |  |  |             list($family, $given) = $this->renderNameParts($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 527 |  |  |             $text = $family; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 528 |  |  |             $text .= !empty($given) ? $this->sortSeparator . $given : ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 529 |  |  |             $text .= !empty($data->suffix) ? $this->sortSeparator . $data->suffix : ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 530 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 531 |  |  |         } else if ($this->form === "long") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 532 |  |  |             // [Jean] [de] [La] [Fontaine] [III] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 533 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 534 |  |  |             NameHelper::prependParticleTo($data, "family", "non-dropping-particle"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 535 |  |  |             NameHelper::prependParticleTo($data, "family", "dropping-particle"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 536 |  |  |             NameHelper::appendParticleTo($data, "family", "suffix"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 537 |  |  |             list($family, $given) = $this->renderNameParts($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 538 |  |  |             $text = !empty($given) ? $given . " " . $family : $family; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 539 |  |  |         } else if ($this->form === "short") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 540 |  |  |             // [La] [Fontaine] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 541 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 542 |  |  |             NameHelper::prependParticleTo($data, "family", "non-dropping-particle"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 543 |  |  |             $text = $data->family; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 544 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 545 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 546 |  |  |             throw new CiteProcException("This should not happen."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 547 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 548 |  |  |         return $text; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 549 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 550 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 551 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 552 |  |  |      * @param $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 553 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 554 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 555 |  |  |     private function renderNameParts($data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 556 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 557 |  |  |         $given = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 558 |  |  |         $family = array_key_exists("family", $this->nameParts) ? $this->nameParts["family"]->render($data) : $data->family; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 559 |  |  |         if (isset($data->given)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 560 |  |  |             $given = array_key_exists("given", $this->nameParts) ? $this->nameParts["given"]->render($data) : $data->given; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 561 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 562 |  |  |         return [$family, $given]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 563 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 564 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 565 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 566 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 567 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 568 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 569 |  |  |     public function getForm() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 570 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 571 |  |  |         return $this->form; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 572 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 573 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 574 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 575 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 576 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 577 |  |  |     public function isNameAsSortOrder() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 578 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 579 |  |  |         return $this->nameAsSortOrder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 580 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 581 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 582 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 583 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 584 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 585 |  |  |     public function getDelimiter() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 586 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 587 |  |  |         return $this->delimiter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 588 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 589 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 590 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 591 |  |  |      * @param mixed $delimiter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 592 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 593 |  |  |     public function setDelimiter($delimiter) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 594 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 595 |  |  |         $this->delimiter = $delimiter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 596 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 597 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 598 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 599 |  |  |      * @return Names | 
            
                                                                                                            
                            
            
                                    
            
            
                | 600 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 601 |  |  |     public function getParent() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 602 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 603 |  |  |         return $this->parent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 604 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 605 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 606 |  |  | } | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 607 |  |  |  | 
            
                        
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.