@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 `DivinerAtomizer` classes

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/D11599

+24 -20
+3 -3
src/applications/diviner/atomizer/DivinerAtomizer.php
··· 10 10 private $atomContext; 11 11 12 12 /** 13 - * If you make a significant change to an atomizer, you can bump this 14 - * version to drop all the old atom caches. 13 + * If you make a significant change to an atomizer, you can bump this version 14 + * to drop all the old atom caches. 15 15 */ 16 16 public static function getAtomizerVersion() { 17 17 return 1; ··· 22 22 $this->atomContext = $context; 23 23 $atoms = $this->executeAtomize($file_name, $file_data); 24 24 25 - // Promote the "@group" special to a property. If there's no "@group" on 25 + // Promote the `@group` special to a property. If there's no `@group` on 26 26 // an atom but the file it's in matches a group pattern, associate it with 27 27 // the right group. 28 28 foreach ($atoms as $atom) {
+21 -17
src/applications/diviner/atomizer/DivinerPHPAtomizer.php
··· 6 6 return parent::newAtom($type)->setLanguage('php'); 7 7 } 8 8 9 - 10 9 protected function executeAtomize($file_name, $file_data) { 11 10 $future = xhpast_get_parser_future($file_data); 12 11 $tree = XHPASTTree::newFromDataAndResolvedExecFuture( ··· 14 13 $future->resolve()); 15 14 16 15 $atoms = array(); 17 - 18 16 $root = $tree->getRootNode(); 19 17 20 18 $func_decl = $root->selectDescendantsOfType('n_FUNCTION_DECLARATION'); 21 19 foreach ($func_decl as $func) { 22 - 23 20 $name = $func->getChildByIndex(2); 24 21 25 22 // Don't atomize closures ··· 33 30 ->setFile($file_name); 34 31 35 32 $this->findAtomDocblock($atom, $func); 36 - 37 33 $this->parseParams($atom, $func); 38 34 $this->parseReturnType($atom, $func); 39 35 ··· 46 42 ); 47 43 foreach ($class_types as $atom_type => $node_type) { 48 44 $class_decls = $root->selectDescendantsOfType($node_type); 45 + 49 46 foreach ($class_decls as $class) { 50 47 $name = $class->getChildByIndex(1, 'n_CLASS_NAME'); 51 48 ··· 54 51 ->setFile($file_name) 55 52 ->setLine($class->getLineNumber()); 56 53 57 - // This parses "final" and "abstract". 54 + // This parses `final` and `abstract`. 58 55 $attributes = $class->getChildByIndex(0, 'n_CLASS_ATTRIBUTES'); 59 56 foreach ($attributes->selectDescendantsOfType('n_STRING') as $attr) { 60 57 $atom->setProperty($attr->getConcreteString(), true); 61 58 } 62 59 63 - // If this exists, it is n_EXTENDS_LIST. 60 + // If this exists, it is `n_EXTENDS_LIST`. 64 61 $extends = $class->getChildByIndex(2); 65 62 $extends_class = $extends->selectDescendantsOfType('n_CLASS_NAME'); 66 63 foreach ($extends_class as $parent_class) { ··· 70 67 $parent_class->getConcreteString())); 71 68 } 72 69 73 - // If this exists, it is n_IMPLEMENTS_LIST. 70 + // If this exists, it is `n_IMPLEMENTS_LIST`. 74 71 $implements = $class->getChildByIndex(3); 75 72 $iface_names = $implements->selectDescendantsOfType('n_CLASS_NAME'); 76 73 foreach ($iface_names as $iface_name) { ··· 193 190 $atom->setProperty('parameters', $param_spec); 194 191 } 195 192 196 - 197 193 private function findAtomDocblock(DivinerAtom $atom, XHPASTNode $node) { 198 194 $token = $node->getDocblockToken(); 199 195 if ($token) { ··· 218 214 pht( 219 215 'Atom "%s" is preceded by a comment containing "@%s", but the '. 220 216 'comment is not a documentation comment. Documentation '. 221 - 'comments must begin with "/**", followed by a newline. Did '. 217 + 'comments must begin with "%s", followed by a newline. Did '. 222 218 'you mean to use a documentation comment? (As the comment is '. 223 219 'not a documentation comment, it will be ignored.)', 224 220 $atom->getName(), 225 - $matches[1])); 221 + $matches[1], 222 + '/**')); 226 223 } 227 224 } 228 225 } ··· 234 231 235 232 protected function parseParamDoc(DivinerAtom $atom, $doc, $name) { 236 233 $dict = array(); 237 - $split = preg_split('/\s+/', trim($doc), $limit = 2); 234 + $split = preg_split('/\s+/', trim($doc), 2); 238 235 if (!empty($split[0])) { 239 236 $dict['doctype'] = $split[0]; 240 237 } ··· 242 239 if (!empty($split[1])) { 243 240 $docs = $split[1]; 244 241 245 - // If the parameter is documented like "@param int $num Blah blah ..", 242 + // If the parameter is documented like `@param int $num Blah blah ..`, 246 243 // get rid of the `$num` part (which Diviner considers optional). If it 247 244 // is present and different from the declared name, raise a warning. 248 245 $matches = null; ··· 276 273 $return = idx($metadata, 'returns'); 277 274 if ($return) { 278 275 $atom->addWarning( 279 - pht('Documentation uses `@returns`, but should use `@return`.')); 276 + pht( 277 + 'Documentation uses `%s`, but should use `%s`.', 278 + '@returns', 279 + '@return')); 280 280 } 281 281 } 282 282 ··· 288 288 289 289 if ($return) { 290 290 $atom->addWarning( 291 - 'Method __construct() has explicitly documented @return. The '. 292 - '__construct() method always returns $this. Diviner documents '. 293 - 'this implicitly.'); 291 + pht( 292 + 'Method %s has explicitly documented %s. The %s method always '. 293 + 'returns %s. Diviner documents this implicitly.', 294 + '__construct()', 295 + '@return', 296 + '__construct()', 297 + '$this')); 294 298 } 295 299 } else if ($return) { 296 - $split = preg_split('/(?<!,)\s+/', trim($return), $limit = 2); 300 + $split = preg_split('/(?<!,)\s+/', trim($return), 2); 297 301 if (!empty($split[0])) { 298 302 $type = $split[0]; 299 303 }