@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Minor tidying of `DivinerAtom` and `DivinerAtomRef`

Summary: Self-explanatory.

Test Plan: Eyeball it.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D11592

+55 -55
+25 -25
src/applications/diviner/atom/DivinerAtom.php
··· 2 2 3 3 final class DivinerAtom { 4 4 5 - const TYPE_FILE = 'file'; 6 5 const TYPE_ARTICLE = 'article'; 7 - const TYPE_METHOD = 'method'; 8 6 const TYPE_CLASS = 'class'; 7 + const TYPE_FILE = 'file'; 9 8 const TYPE_FUNCTION = 'function'; 10 9 const TYPE_INTERFACE = 'interface'; 10 + const TYPE_METHOD = 'method'; 11 11 12 12 private $type; 13 13 private $name; ··· 95 95 96 96 public function getDocblockText() { 97 97 if ($this->docblockText === null) { 98 - throw new Exception('Call setDocblockRaw() before getDocblockText()!'); 98 + throw new Exception( 99 + pht('Call %s before %s!', 'setDocblockRaw()', 'getDocblockText()')); 99 100 } 100 101 return $this->docblockText; 101 102 } 102 103 103 104 public function getDocblockMeta() { 104 105 if ($this->docblockMeta === null) { 105 - throw new Exception('Call setDocblockRaw() before getDocblockMeta()!'); 106 + throw new Exception( 107 + pht('Call %s before %s!', 'setDocblockRaw()', 'getDocblockMeta()')); 106 108 } 107 109 return $this->docblockMeta; 108 110 } ··· 248 250 249 251 public function setParentHash($parent_hash) { 250 252 if ($this->parentHash) { 251 - throw new Exception('Atom already has a parent!'); 253 + throw new Exception(pht('Atom already has a parent!')); 252 254 } 253 255 $this->parentHash = $parent_hash; 254 256 return $this; ··· 260 262 261 263 public function setParent(DivinerAtom $atom) { 262 264 if ($this->parentHash) { 263 - throw new Exception('Parent hash has already been computed!'); 265 + throw new Exception(pht('Parent hash has already been computed!')); 264 266 } 265 267 $this->parent = $atom; 266 268 return $this; ··· 275 277 276 278 public function addChild(DivinerAtom $atom) { 277 279 if ($this->childHashes) { 278 - throw new Exception('Child hashes have already been computed!'); 280 + throw new Exception(pht('Child hashes have already been computed!')); 279 281 } 280 282 281 283 $atom->setParent($this); ··· 293 295 $parts[] = null; 294 296 return implode('/', $parts); 295 297 } 296 - 297 298 298 299 public function toDictionary() { 299 300 // NOTE: If you change this format, bump the format version in 300 - // getAtomSerializationVersion(). 301 - 301 + // @{method:getAtomSerializationVersion}. 302 302 return array( 303 303 'book' => $this->getBook(), 304 304 'type' => $this->getType(), ··· 385 385 386 386 public static function getThisAtomIsNotDocumentedString($type) { 387 387 switch ($type) { 388 + case self::TYPE_ARTICLE: 389 + return pht('This article is not documented.'); 390 + case self::TYPE_CLASS: 391 + return pht('This class is not documented.'); 388 392 case self::TYPE_FILE: 389 393 return pht('This file is not documented.'); 390 394 case self::TYPE_FUNCTION: 391 395 return pht('This function is not documented.'); 392 - case self::TYPE_CLASS: 393 - return pht('This class is not documented.'); 394 - case self::TYPE_ARTICLE: 395 - return pht('This article is not documented.'); 396 + case self::TYPE_INTERFACE: 397 + return pht('This interface is not documented.'); 396 398 case self::TYPE_METHOD: 397 399 return pht('This method is not documented.'); 398 - case self::TYPE_INTERFACE: 399 - return pht('This interface is not documented.'); 400 400 default: 401 401 phlog("Need translation for '{$type}'."); 402 402 return pht('This %s is not documented.', $type); ··· 405 405 406 406 public static function getAllTypes() { 407 407 return array( 408 + self::TYPE_ARTICLE, 409 + self::TYPE_CLASS, 408 410 self::TYPE_FILE, 409 411 self::TYPE_FUNCTION, 410 - self::TYPE_CLASS, 411 - self::TYPE_ARTICLE, 412 + self::TYPE_INTERFACE, 412 413 self::TYPE_METHOD, 413 - self::TYPE_INTERFACE, 414 414 ); 415 415 } 416 416 417 417 public static function getAtomTypeNameString($type) { 418 418 switch ($type) { 419 + case self::TYPE_ARTICLE: 420 + return pht('Article'); 421 + case self::TYPE_CLASS: 422 + return pht('Class'); 419 423 case self::TYPE_FILE: 420 424 return pht('File'); 421 425 case self::TYPE_FUNCTION: 422 426 return pht('Function'); 423 - case self::TYPE_CLASS: 424 - return pht('Class'); 425 - case self::TYPE_ARTICLE: 426 - return pht('Article'); 427 - case self::TYPE_METHOD: 428 - return pht('Method'); 429 427 case self::TYPE_INTERFACE: 430 428 return pht('Interface'); 429 + case self::TYPE_METHOD: 430 + return pht('Method'); 431 431 default: 432 432 phlog("Need translation for '{$type}'."); 433 433 return ucwords($type);
+30 -30
src/applications/diviner/atom/DivinerAtomRef.php
··· 43 43 44 44 public function setName($name) { 45 45 $normal_name = self::normalizeString($name); 46 - if (preg_match('/^@[0-9]+\z/', $normal_name)) { 46 + if (preg_match('/^@\d+\z/', $normal_name)) { 47 47 throw new Exception( 48 - "Atom names must not be in the form '/@\d+/'. This pattern is ". 49 - "reserved for disambiguating atoms with similar names."); 48 + pht( 49 + "Atom names must not be in the form '%s'. This pattern is ". 50 + "reserved for disambiguating atoms with similar names.", 51 + '/@\d+/')); 50 52 } 51 53 $this->name = $normal_name; 52 54 return $this; ··· 120 122 'type' => $this->getType(), 121 123 'name' => $this->getName(), 122 124 'group' => $this->getGroup(), 123 - 'index' => $this->getIndex(), 124 125 'summary' => $this->getSummary(), 126 + 'index' => $this->getIndex(), 125 127 'title' => $this->getTitle(), 126 128 ); 127 129 } ··· 139 141 } 140 142 141 143 public static function newFromDictionary(array $dict) { 142 - $obj = new DivinerAtomRef(); 143 - $obj->setBook(idx($dict, 'book')); 144 - $obj->setContext(idx($dict, 'context')); 145 - $obj->setType(idx($dict, 'type')); 146 - $obj->setName(idx($dict, 'name')); 147 - $obj->group = idx($dict, 'group'); 148 - $obj->index = idx($dict, 'index'); 149 - $obj->summary = idx($dict, 'summary'); 150 - $obj->title = idx($dict, 'title'); 151 - 152 - return $obj; 144 + return id(new DivinerAtomRef()) 145 + ->setBook(idx($dict, 'book')) 146 + ->setContext(idx($dict, 'context')) 147 + ->setType(idx($dict, 'type')) 148 + ->setName(idx($dict, 'name')) 149 + ->setGroup(idx($dict, 'group')) 150 + ->setSummary(idx($dict, 'summary')) 151 + ->setIndex(idx($dict, 'index')) 152 + ->setTitle(idx($dict, 'title')); 153 153 } 154 154 155 155 public static function normalizeString($str) { 156 156 // These characters create problems on the filesystem or in URIs. Replace 157 - // them with non-problematic appoximations (instead of simply removing them) 158 - // to keep the URIs fairly useful and avoid unnecessary collisions. These 159 - // approximations are selected based on some domain knowledge of common 160 - // languages: where a character is used as a delimiter, it is more helpful 161 - // to replace it with a "." or a ":" or similar, while it's better if 162 - // operator overloads read as, e.g., "operator_div". 157 + // them with non-problematic approximations (instead of simply removing 158 + // them) to keep the URIs fairly useful and avoid unnecessary collisions. 159 + // These approximations are selected based on some domain knowledge of 160 + // common languages: where a character is used as a delimiter, it is more 161 + // helpful to replace it with a "." or a ":" or similar, while it's better 162 + // if operator overloads read as, e.g., "operator_div". 163 163 164 164 $map = array( 165 165 // Hopefully not used anywhere by anything. 166 - '#' => '.', 166 + '#' => '.', 167 167 168 168 // Used in Ruby methods. 169 - '?' => 'Q', 169 + '?' => 'Q', 170 170 171 171 // Used in PHP namespaces. 172 - '\\' => '.', 172 + '\\' => '.', 173 173 174 174 // Used in "operator +" in C++. 175 - '+' => 'plus', 175 + '+' => 'plus', 176 176 177 177 // Used in "operator %" in C++. 178 - '%' => 'mod', 178 + '%' => 'mod', 179 179 180 180 // Used in "operator /" in C++. 181 - '/' => 'div', 181 + '/' => 'div', 182 182 ); 183 183 $str = str_replace(array_keys($map), array_values($map), $str); 184 184 ··· 190 190 191 191 // Replace specific problematic names with alternative names. 192 192 $alternates = array( 193 - '.' => 'dot', 194 - '..' => 'dotdot', 195 - '' => 'null', 193 + '.' => 'dot', 194 + '..' => 'dotdot', 195 + '' => 'null', 196 196 ); 197 197 198 198 return idx($alternates, $str, $str);