@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.

Lift core of "HeraldConditionResult" to "HeraldTranscriptResult"

Summary: Ref T13586. Lift the behavioral core of "HeraldConditionResult" into a new abstract base "HeraldTranscriptResult", with the intent to introduce a "HeraldRuleResult".

Test Plan:
- Ran Herald rules, reviewed transcripts.
- This change should have no behavioral effect.

Maniphest Tasks: T13586

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

+93 -78
+3 -1
src/__phutil_library_map__.php
··· 1662 1662 'HeraldTranscriptListController' => 'applications/herald/controller/HeraldTranscriptListController.php', 1663 1663 'HeraldTranscriptPHIDType' => 'applications/herald/phid/HeraldTranscriptPHIDType.php', 1664 1664 'HeraldTranscriptQuery' => 'applications/herald/query/HeraldTranscriptQuery.php', 1665 + 'HeraldTranscriptResult' => 'applications/herald/storage/transcript/HeraldTranscriptResult.php', 1665 1666 'HeraldTranscriptSearchEngine' => 'applications/herald/query/HeraldTranscriptSearchEngine.php', 1666 1667 'HeraldTranscriptTestCase' => 'applications/herald/storage/__tests__/HeraldTranscriptTestCase.php', 1667 1668 'HeraldUtilityActionGroup' => 'applications/herald/action/HeraldUtilityActionGroup.php', ··· 7794 7795 'HarbormasterBuildableAdapterInterface', 7795 7796 ), 7796 7797 'HeraldCondition' => 'HeraldDAO', 7797 - 'HeraldConditionResult' => 'Phobject', 7798 + 'HeraldConditionResult' => 'HeraldTranscriptResult', 7798 7799 'HeraldConditionTranscript' => 'Phobject', 7799 7800 'HeraldContentSourceField' => 'HeraldField', 7800 7801 'HeraldController' => 'PhabricatorController', ··· 7905 7906 'HeraldTranscriptListController' => 'HeraldController', 7906 7907 'HeraldTranscriptPHIDType' => 'PhabricatorPHIDType', 7907 7908 'HeraldTranscriptQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 7909 + 'HeraldTranscriptResult' => 'Phobject', 7908 7910 'HeraldTranscriptSearchEngine' => 'PhabricatorApplicationSearchEngine', 7909 7911 'HeraldTranscriptTestCase' => 'PhabricatorTestCase', 7910 7912 'HeraldUtilityActionGroup' => 'HeraldActionGroup',
+6 -75
src/applications/herald/storage/transcript/HeraldConditionResult.php
··· 1 1 <?php 2 2 3 3 final class HeraldConditionResult 4 - extends Phobject { 4 + extends HeraldTranscriptResult { 5 5 6 6 const RESULT_MATCHED = 'matched'; 7 7 const RESULT_FAILED = 'failed'; ··· 10 10 const RESULT_EXCEPTION = 'exception'; 11 11 const RESULT_UNKNOWN = 'unknown'; 12 12 13 - private $resultCode; 14 - private $resultData = array(); 15 - 16 - public function toMap() { 17 - return array( 18 - 'code' => $this->getResultCode(), 19 - 'data' => $this->getResultData(), 20 - ); 21 - } 22 - 23 - public static function newFromMap(array $map) { 24 - $result_code = idx($map, 'code'); 25 - $result = self::newFromResultCode($result_code); 26 - 27 - $result_data = idx($map, 'data', array()); 28 - $result->setResultData($result_data); 29 - 30 - return $result; 31 - } 32 - 33 13 public static function newFromResultCode($result_code) { 34 - $map = self::getResultSpecification($result_code); 35 - 36 - $result = new self(); 37 - $result->resultCode = $result_code; 38 - 39 - return $result; 40 - } 41 - 42 - public function getResultCode() { 43 - return $this->resultCode; 44 - } 45 - 46 - private function getResultData() { 47 - return $this->resultData; 14 + return id(new self())->setResultCode($result_code); 48 15 } 49 16 50 - public function getIconIcon() { 51 - return $this->getSpecificationProperty('icon'); 52 - } 53 - 54 - public function getIconColor() { 55 - return $this->getSpecificationProperty('color.icon'); 17 + public static function newFromResultMap(array $map) { 18 + return id(new self())->loadFromResultMap($map); 56 19 } 57 20 58 21 public function getIsMatch() { 59 22 return ($this->getSpecificationProperty('match') === true); 60 23 } 61 24 62 - public function getName() { 63 - return $this->getSpecificationProperty('name'); 64 - } 65 - 66 25 public function newDetailsView() { 67 - switch ($this->resultCode) { 26 + switch ($this->getResultCode()) { 68 27 case self::RESULT_OBJECT_STATE: 69 28 $reason = $this->getDataProperty('reason'); 70 29 $details = HeraldStateReasons::getExplanation($reason); ··· 105 64 return $details; 106 65 } 107 66 108 - public function setResultData(array $result_data) { 109 - $this->resultData = $result_data; 110 - return $this; 111 - } 112 - 113 - private function getDataProperty($key) { 114 - $data = $this->getResultData(); 115 - return idx($data, $key); 116 - } 117 - 118 - private function getSpecificationProperty($key) { 119 - $map = self::getResultSpecification($this->resultCode); 120 - return $map[$key]; 121 - } 122 - 123 - private static function getResultSpecification($result_code) { 124 - $map = self::getResultSpecificationMap(); 125 - 126 - if (!isset($map[$result_code])) { 127 - throw new Exception( 128 - pht( 129 - 'Condition result "%s" is unknown.', 130 - $result_code)); 131 - } 132 - 133 - return $map[$result_code]; 134 - } 135 - 136 - private static function getResultSpecificationMap() { 67 + protected function newResultSpecificationMap() { 137 68 return array( 138 69 self::RESULT_MATCHED => array( 139 70 'match' => true,
+2 -2
src/applications/herald/storage/transcript/HeraldConditionTranscript.php
··· 65 65 } 66 66 67 67 public function setResult(HeraldConditionResult $result) { 68 - $this->resultMap = $result->toMap(); 68 + $this->resultMap = $result->newResultMap(); 69 69 return $this; 70 70 } 71 71 ··· 73 73 $map = $this->resultMap; 74 74 75 75 if (is_array($map)) { 76 - $result = HeraldConditionResult::newFromMap($map); 76 + $result = HeraldConditionResult::newFromResultMap($map); 77 77 } else { 78 78 $legacy_result = $this->result; 79 79
+82
src/applications/herald/storage/transcript/HeraldTranscriptResult.php
··· 1 + <?php 2 + 3 + abstract class HeraldTranscriptResult 4 + extends Phobject { 5 + 6 + private $resultCode; 7 + private $resultData = array(); 8 + 9 + final protected function setResultCode($result_code) { 10 + $this->resultCode = $result_code; 11 + return $this; 12 + } 13 + 14 + final protected function loadFromResultMap(array $map) { 15 + $result_code = idx($map, 'code'); 16 + $result_data = idx($map, 'data', array()); 17 + 18 + $this 19 + ->setResultCode($result_code) 20 + ->setResultData($result_data); 21 + 22 + return $this; 23 + } 24 + 25 + final public function getResultCode() { 26 + return $this->resultCode; 27 + } 28 + 29 + final protected function getResultData() { 30 + return $this->resultData; 31 + } 32 + 33 + final public function setResultData(array $result_data) { 34 + $this->resultData = $result_data; 35 + return $this; 36 + } 37 + 38 + final public function getIconIcon() { 39 + return $this->getSpecificationProperty('icon'); 40 + } 41 + 42 + final public function getIconColor() { 43 + return $this->getSpecificationProperty('color.icon'); 44 + } 45 + 46 + final public function getName() { 47 + return $this->getSpecificationProperty('name'); 48 + } 49 + 50 + final protected function getDataProperty($key) { 51 + $data = $this->getResultData(); 52 + return idx($data, $key); 53 + } 54 + 55 + final public function newResultMap() { 56 + return array( 57 + 'code' => $this->getResultCode(), 58 + 'data' => $this->getResultData(), 59 + ); 60 + } 61 + 62 + final protected function getSpecificationProperty($key) { 63 + $map = $this->getResultSpecification($this->getResultCode()); 64 + return $map[$key]; 65 + } 66 + 67 + final protected function getResultSpecification($result_code) { 68 + $map = $this->newResultSpecificationMap(); 69 + 70 + if (!isset($map[$result_code])) { 71 + throw new Exception( 72 + pht( 73 + 'Result code "%s" is unknown.', 74 + $result_code)); 75 + } 76 + 77 + return $map[$result_code]; 78 + } 79 + 80 + abstract protected function newResultSpecificationMap(); 81 + 82 + }