[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/releeph/field/specification/ -> ReleephDiffChurnFieldSpecification.php (source)

   1  <?php
   2  
   3  final class ReleephDiffChurnFieldSpecification
   4    extends ReleephFieldSpecification {
   5  
   6    const REJECTIONS_WEIGHT =  30;
   7    const COMMENTS_WEIGHT   =   7;
   8    const UPDATES_WEIGHT    =  10;
   9    const MAX_POINTS        = 100;
  10  
  11    public function getFieldKey() {
  12      return 'churn';
  13    }
  14  
  15    public function getName() {
  16      return 'Churn';
  17    }
  18  
  19    public function renderPropertyViewValue(array $handles) {
  20      $requested_object = $this->getObject()->getRequestedObject();
  21      if (!($requested_object instanceof DifferentialRevision)) {
  22        return null;
  23      }
  24      $diff_rev = $requested_object;
  25  
  26      $xactions = id(new DifferentialTransactionQuery())
  27        ->setViewer($this->getViewer())
  28        ->withObjectPHIDs(array($diff_rev->getPHID()))
  29        ->execute();
  30  
  31      $rejections = 0;
  32      $comments = 0;
  33      $updates = 0;
  34      foreach ($xactions as $xaction) {
  35        switch ($xaction->getTransactionType()) {
  36          case PhabricatorTransactions::TYPE_COMMENT:
  37            $comments++;
  38            break;
  39          case DifferentialTransaction::TYPE_UPDATE:
  40            $updates++;
  41            break;
  42          case DifferentialTransaction::TYPE_ACTION:
  43            switch ($xaction->getNewValue()) {
  44              case DifferentialAction::ACTION_REJECT:
  45                $rejections++;
  46                break;
  47            }
  48            break;
  49        }
  50      }
  51  
  52      $points =
  53        self::REJECTIONS_WEIGHT * $rejections +
  54        self::COMMENTS_WEIGHT * $comments +
  55        self::UPDATES_WEIGHT * $updates;
  56  
  57      if ($points === 0) {
  58        $points = 0.15 * self::MAX_POINTS;
  59        $blurb = 'Silent diff';
  60      } else {
  61        $parts = array();
  62        if ($rejections) {
  63          $parts[] = pht('%d rejection(s)', $rejections);
  64        }
  65        if ($comments) {
  66          $parts[] = pht('%d comment(s)', $comments);
  67        }
  68        if ($updates) {
  69          $parts[] = pht('%d update(s)', $updates);
  70        }
  71  
  72        if (count($parts) === 0) {
  73          $blurb = '';
  74        } else if (count($parts) === 1) {
  75          $blurb = head($parts);
  76        } else {
  77          $last = array_pop($parts);
  78          $blurb = implode(', ', $parts).' and '.$last;
  79        }
  80      }
  81  
  82      return id(new AphrontProgressBarView())
  83        ->setValue($points)
  84        ->setMax(self::MAX_POINTS)
  85        ->setCaption($blurb)
  86        ->render();
  87    }
  88  
  89  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1