Remove product literal strings in "pht()", part 25
[phabricator.git] / src / applications / releeph / field / specification / ReleephDiffSizeFieldSpecification.php
blob20c8d5e226bee007a51cc37d0bfdfcc30122622a
1 <?php
3 final class ReleephDiffSizeFieldSpecification
4 extends ReleephFieldSpecification {
6 const LINES_WEIGHT = 1;
7 const PATHS_WEIGHT = 30;
8 const MAX_POINTS = 1000;
10 public function getFieldKey() {
11 return 'commit:size';
14 public function getName() {
15 return pht('Size');
18 public function renderPropertyViewValue(array $handles) {
19 $requested_object = $this->getObject()->getRequestedObject();
20 if (!($requested_object instanceof DifferentialRevision)) {
21 return null;
23 $diff_rev = $requested_object;
25 $diffs = id(new DifferentialDiff())->loadAllWhere(
26 'revisionID = %d AND creationMethod != %s',
27 $diff_rev->getID(),
28 'commit');
30 $all_changesets = array();
31 $most_recent_changesets = null;
32 foreach ($diffs as $diff) {
33 $changesets = id(new DifferentialChangeset())->loadAllWhere(
34 'diffID = %d',
35 $diff->getID());
36 $all_changesets += $changesets;
37 $most_recent_changesets = $changesets;
40 // The score is based on all changesets for all versions of this diff
41 $all_changes = $this->countLinesAndPaths($all_changesets);
42 $points =
43 self::LINES_WEIGHT * $all_changes['code']['lines'] +
44 self::PATHS_WEIGHT * count($all_changes['code']['paths']);
46 // The blurb is just based on the most recent version of the diff
47 $mr_changes = $this->countLinesAndPaths($most_recent_changesets);
49 $test_tag = '';
50 if ($mr_changes['tests']['paths']) {
51 Javelin::initBehavior('phabricator-tooltips');
52 require_celerity_resource('aphront-tooltip-css');
54 $test_blurb = pht(
55 "%d line(s) and %d path(s) contain changes to test code:\n",
56 $mr_changes['tests']['lines'],
57 count($mr_changes['tests']['paths']));
58 foreach ($mr_changes['tests']['paths'] as $mr_test_path) {
59 $test_blurb .= sprintf("%s\n", $mr_test_path);
62 $test_tag = javelin_tag(
63 'span',
64 array(
65 'sigil' => 'has-tooltip',
66 'meta' => array(
67 'tip' => $test_blurb,
68 'align' => 'E',
69 'size' => 'auto',
71 'style' => '',
73 ' + tests');
76 $blurb = hsprintf('%s%s.',
77 pht(
78 '%d line(s) and %d path(s) over %d diff(s)',
79 $mr_changes['code']['lines'],
80 $mr_changes['code']['paths'],
81 count($diffs)),
82 $test_tag);
84 return id(new AphrontProgressBarView())
85 ->setValue($points)
86 ->setMax(self::MAX_POINTS)
87 ->setCaption($blurb)
88 ->render();
91 private function countLinesAndPaths(array $changesets) {
92 assert_instances_of($changesets, 'DifferentialChangeset');
93 $lines = 0;
94 $paths_touched = array();
95 $test_lines = 0;
96 $test_paths_touched = array();
98 foreach ($changesets as $ch) {
99 if ($this->getReleephProject()->isTestFile($ch->getFilename())) {
100 $test_lines += $ch->getAddLines() + $ch->getDelLines();
101 $test_paths_touched[] = $ch->getFilename();
102 } else {
103 $lines += $ch->getAddLines() + $ch->getDelLines();
104 $paths_touched[] = $ch->getFilename();
107 return array(
108 'code' => array(
109 'lines' => $lines,
110 'paths' => array_unique($paths_touched),
112 'tests' => array(
113 'lines' => $test_lines,
114 'paths' => array_unique($test_paths_touched),