1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-02 09:58:24 +01:00

Replace all "attach first..." exceptions with assertAttached()

Summary:
Ref T3599
Go through everything, grep a bit, replace some bits.

Test Plan: Navigate around a bit

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran

Maniphest Tasks: T3599

Differential Revision: https://secure.phabricator.com/D6871
This commit is contained in:
Gareth Evans 2013-09-03 06:02:14 -07:00 committed by epriestley
parent 4e12a375f3
commit fcba0c74d9
22 changed files with 100 additions and 235 deletions

View file

@ -13,11 +13,11 @@ final class ConpherenceThread extends ConpherenceDAO
protected $recentParticipantPHIDs = array();
protected $mailKey;
private $participants;
private $transactions;
private $handles;
private $filePHIDs;
private $widgetData;
private $participants = self::ATTACHABLE;
private $transactions = self::ATTACHABLE;
private $handles = self::ATTACHABLE;
private $filePHIDs = self::ATTACHABLE;
private $widgetData = self::ATTACHABLE;
private $images = array();
public function getConfiguration() {
@ -47,12 +47,7 @@ final class ConpherenceThread extends ConpherenceDAO
return $this;
}
public function getParticipants() {
if ($this->participants === null) {
throw new Exception(
'You must attachParticipants first!'
);
}
return $this->participants;
return $this->assertAttached($this->participants);
}
public function getParticipant($phid) {
$participants = $this->getParticipants();
@ -69,12 +64,7 @@ final class ConpherenceThread extends ConpherenceDAO
return $this;
}
public function getHandles() {
if ($this->handles === null) {
throw new Exception(
'You must attachHandles first!'
);
}
return $this->handles;
return $this->assertAttached($this->handles);
}
public function attachTransactions(array $transactions) {
@ -83,26 +73,14 @@ final class ConpherenceThread extends ConpherenceDAO
return $this;
}
public function getTransactions() {
if ($this->transactions === null) {
throw new Exception(
'You must attachTransactions first!'
);
}
return $this->transactions;
return $this->assertAttached($this->transactions);
}
public function getTransactionsFrom($begin = 0, $amount = null) {
$length = count($this->transactions);
if ($amount === null) {
$amount === $length;
}
if ($this->transactions === null) {
throw new Exception(
'You must attachTransactions first!'
);
}
return array_slice(
$this->transactions,
$this->getTransactions(),
$length - $begin - $amount,
$amount);
}
@ -112,12 +90,7 @@ final class ConpherenceThread extends ConpherenceDAO
return $this;
}
public function getFilePHIDs() {
if ($this->filePHIDs === null) {
throw new Exception(
'You must attachFilePHIDs first!'
);
}
return $this->filePHIDs;
return $this->assertAttached($this->filePHIDs);
}
public function attachWidgetData(array $widget_data) {
@ -125,12 +98,7 @@ final class ConpherenceThread extends ConpherenceDAO
return $this;
}
public function getWidgetData() {
if ($this->widgetData === null) {
throw new Exception(
'You must attachWidgetData first!'
);
}
return $this->widgetData;
return $this->assertAttached($this->widgetData);
}
public function getDisplayData(PhabricatorUser $user) {

View file

@ -15,7 +15,7 @@ final class DifferentialChangeset extends DifferentialDAO {
protected $delLines;
private $unsavedHunks = array();
private $hunks;
private $hunks = self::ATTACHABLE;
const TABLE_CACHE = 'differential_changeset_parse_cache';
@ -40,10 +40,7 @@ final class DifferentialChangeset extends DifferentialDAO {
}
public function getHunks() {
if ($this->hunks === null) {
throw new Exception("Must load and attach hunks first!");
}
return $this->hunks;
return $this->assertAttached($this->hunks);
}
public function getDisplayFilename() {
@ -55,7 +52,7 @@ final class DifferentialChangeset extends DifferentialDAO {
}
public function addUnsavedHunk(DifferentialHunk $hunk) {
if ($this->hunks === null) {
if ($this->hunks === self::ATTACHABLE) {
$this->hunks = array();
}
$this->hunks[] = $hunk;

View file

@ -30,7 +30,7 @@ final class DifferentialDiff
protected $description;
private $unsavedChangesets = array();
private $changesets;
private $changesets = self::ATTACHABLE;
public function addUnsavedChangeset(DifferentialChangeset $changeset) {
if ($this->changesets === null) {
@ -48,10 +48,7 @@ final class DifferentialDiff
}
public function getChangesets() {
if ($this->changesets === null) {
throw new Exception("Must load and attach changesets first!");
}
return $this->changesets;
return $this->assertAttached($this->changesets);
}
public function loadChangesets() {

View file

@ -26,13 +26,13 @@ final class DifferentialRevision extends DifferentialDAO
protected $branchName;
protected $arcanistProjectPHID;
private $relationships;
private $commits;
private $activeDiff = false;
private $diffIDs;
private $hashes;
private $relationships = self::ATTACHABLE;
private $commits = self::ATTACHABLE;
private $activeDiff = self::ATTACHABLE;
private $diffIDs = self::ATTACHABLE;
private $hashes = self::ATTACHABLE;
private $reviewerStatus;
private $reviewerStatus = self::ATTACHABLE;
const RELATIONSHIP_TABLE = 'differential_relationship';
const TABLE_COMMIT = 'differential_commit';
@ -86,10 +86,7 @@ final class DifferentialRevision extends DifferentialDAO
}
public function getCommitPHIDs() {
if ($this->commits === null) {
throw new Exception("Must attach commits first!");
}
return $this->commits;
return $this->assertAttached($this->commits);
}
public function getActiveDiff() {
@ -98,10 +95,7 @@ final class DifferentialRevision extends DifferentialDAO
// It would be good to get rid of this once we make diff-attaching
// transactional.
if ($this->activeDiff === false) {
throw new Exception("Must attach active diff first!");
}
return $this->activeDiff;
return $this->assertAttached($this->activeDiff);
}
public function attachActiveDiff($diff) {
@ -110,10 +104,7 @@ final class DifferentialRevision extends DifferentialDAO
}
public function getDiffIDs() {
if ($this->diffIDs === null) {
throw new Exception("Must attach diff IDs first!");
}
return $this->diffIDs;
return $this->assertAttached($this->diffIDs);
}
public function attachDiffIDs(array $ids) {
@ -256,9 +247,7 @@ final class DifferentialRevision extends DifferentialDAO
}
private function getRelatedPHIDs($relation) {
if ($this->relationships === null) {
throw new Exception("Must load relationships!");
}
$this->assertAttached($this->relationships);
return ipull($this->getRawRelations($relation), 'objectPHID');
}
@ -304,10 +293,7 @@ final class DifferentialRevision extends DifferentialDAO
}
public function getHashes() {
if ($this->hashes === null) {
throw new Exception("Call attachHashes() before getHashes()!");
}
return $this->hashes;
return $this->assertAttached($this->hashes);
}
public function attachHashes(array $hashes) {
@ -337,12 +323,7 @@ final class DifferentialRevision extends DifferentialDAO
}
public function getReviewerStatus() {
if ($this->reviewerStatus === null) {
throw new Exception(
"Call attachReviewerStatus() before getReviewerStatus()!"
);
}
return $this->reviewerStatus;
return $this->assertAttached($this->reviewerStatus);
}
public function attachReviewerStatus(array $reviewers) {

View file

@ -10,7 +10,7 @@ final class DrydockLease extends DrydockDAO {
protected $status = DrydockLeaseStatus::STATUS_PENDING;
protected $taskID;
private $resource;
private $resource = self::ATTACHABLE;
private $releaseOnDestruction;
/**
@ -64,10 +64,7 @@ final class DrydockLease extends DrydockDAO {
}
public function getResource() {
if ($this->resource === null) {
throw new Exception("Resource is not yet loaded.");
}
return $this->resource;
return $this->assertAttached($this->resource);
}
public function attachResource(DrydockResource $resource) {

View file

@ -15,7 +15,7 @@ final class HeraldRule extends HeraldDAO
protected $configVersion = 9;
private $ruleApplied = array(); // phids for which this rule has been applied
private $ruleApplied = self::ATTACHABLE; // phids for which this rule has been applied
private $validAuthor = self::ATTACHABLE;
private $conditions;
private $actions;
@ -31,13 +31,13 @@ final class HeraldRule extends HeraldDAO
}
public function getRuleApplied($phid) {
if (idx($this->ruleApplied, $phid) === null) {
throw new Exception("Call setRuleApplied() before getRuleApplied()!");
}
return $this->ruleApplied[$phid];
return $this->assertAttachedKey($this->ruleApplied, $phid);
}
public function setRuleApplied($phid, $applied) {
if ($this->ruleApplied === self::ATTACHABLE) {
$this->ruleApplied = array();
}
$this->ruleApplied[$phid] = $applied;
return $this;
}

View file

@ -20,8 +20,8 @@ final class LegalpadDocument extends LegalpadDAO
protected $editPolicy;
protected $mailKey;
private $documentBody;
private $contributors;
private $documentBody = self::ATTACHABLE;
private $contributors = self::ATTACHABLE;
public function getConfiguration() {
return array(
@ -38,12 +38,7 @@ final class LegalpadDocument extends LegalpadDAO
}
public function getDocumentBody() {
if ($this->documentBody === null) {
throw new Exception(
'You must attachDocumentBody before you can getDocumentBody.');
}
return $this->documentBody;
return $this->assertAttached($this->documentBody);
}
public function attachDocumentBody(LegalpadDocumentBody $body) {
@ -52,12 +47,7 @@ final class LegalpadDocument extends LegalpadDAO
}
public function getContributors() {
if ($this->contributors === null) {
throw new Exception(
'You must attachContributors before you can getContributors.');
}
return $this->contributors;
return $this->assertAttached($this->contributors);
}
public function attachContributors(array $contributors) {

View file

@ -12,7 +12,7 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO
protected $name;
protected $isDisabled = 0;
private $file;
private $file = self::ATTACHABLE;
public function attachFile(PhabricatorFile $file) {
$this->file = $file;
@ -20,11 +20,7 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO
}
public function getFile() {
if (!$this->file) {
throw new Exception("Attach a file with attachFile() first!");
}
return $this->file;
return $this->assertAttached($this->file);
}
public function getConfiguration() {

View file

@ -34,7 +34,7 @@ final class ManiphestTask extends ManiphestDAO
protected $ownerOrdering;
private $auxiliaryAttributes;
private $auxiliaryAttributes = self::ATTACHABLE;
private $auxiliaryDirty = array();
public function getConfiguration() {
@ -95,16 +95,13 @@ final class ManiphestTask extends ManiphestDAO
}
public function getAuxiliaryAttribute($key, $default = null) {
if ($this->auxiliaryAttributes === null) {
throw new Exception("Attach auxiliary attributes before getting them!");
}
$this->assertAttached($this->auxiliaryAttributes);
return idx($this->auxiliaryAttributes, $key, $default);
}
public function setAuxiliaryAttribute($key, $val) {
if ($this->auxiliaryAttributes === null) {
throw new Exception("Attach auxiliary attributes before setting them!");
}
$this->assertAttached($this->auxiliaryAttributes);
$this->auxiliaryAttributes[$key] = $val;
$this->auxiliaryDirty[$key] = true;
return $this;

View file

@ -18,8 +18,8 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
protected $viewPolicy;
protected $mailKey;
private $content;
private $rawContent;
private $content = self::ATTACHABLE;
private $rawContent = self::ATTACHABLE;
public function getURI() {
return '/P'.$this->getID();
@ -70,10 +70,7 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
}
public function getContent() {
if ($this->content === null) {
throw new Exception("Call attachContent() before getContent()!");
}
return $this->content;
return $this->assertAttached($this->content);
}
public function attachContent($content) {
@ -82,10 +79,7 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
}
public function getRawContent() {
if ($this->rawContent === null) {
throw new Exception("Call attachRawContent() before getRawContent()!");
}
return $this->rawContent;
return $this->assertAttached($this->rawContent);
}
public function attachRawContent($raw_content) {

View file

@ -17,13 +17,10 @@ final class PhabricatorExternalAccount extends PhabricatorUserDAO
protected $profileImagePHID;
protected $properties = array();
private $profileImageFile;
private $profileImageFile = self::ATTACHABLE;
public function getProfileImageFile() {
if ($this->profileImageFile === null) {
throw new Exception("Call attachProfileImageFile() first!");
}
return $this->profileImageFile;
return $this->assertAttached($this->profileImageFile);
}
public function attachProfileImageFile(PhabricatorFile $file) {

View file

@ -21,8 +21,8 @@ final class PhameBlog extends PhameDAO
protected $editPolicy;
protected $joinPolicy;
private $bloggerPHIDs;
private $bloggers;
private $bloggerPHIDs = self::ATTACHABLE;
private $bloggers = self::ATTACHABLE;
static private $requestBlog;
@ -110,13 +110,7 @@ final class PhameBlog extends PhameDAO
}
public function getBloggerPHIDs() {
if ($this->bloggerPHIDs === null) {
throw new Exception(
'You must loadBloggerPHIDs before you can getBloggerPHIDs!'
);
}
return $this->bloggerPHIDs;
return $this->assertAttached($this->bloggerPHIDs);
}
public function loadBloggers() {
@ -149,13 +143,7 @@ final class PhameBlog extends PhameDAO
}
public function getBloggers() {
if ($this->bloggers === null) {
throw new Exception(
'You must loadBloggers or attachBloggers before you can getBloggers!'
);
}
return $this->bloggers;
return $this->assertAttached($this->bloggers);
}
public function getSkin() {

View file

@ -12,7 +12,7 @@ final class PhortuneAccount extends PhortuneDAO
protected $name;
protected $balanceInCents = 0;
private $memberPHIDs;
private $memberPHIDs = self::ATTACHABLE;
public function getConfiguration() {
return array(
@ -26,10 +26,7 @@ final class PhortuneAccount extends PhortuneDAO
}
public function getMemberPHIDs() {
if ($this->memberPHIDs === null) {
throw new Exception("Call attachMemberPHIDs() before getMemberPHIDs()!");
}
return $this->memberPHIDs;
return $this->assertAttached($this->memberPHIDs);
}
public function attachMemberPHIDs(array $phids) {

View file

@ -6,7 +6,7 @@ final class PhortuneCart extends PhortuneDAO {
protected $ownerPHID;
protected $metadata;
private $purchases;
private $purchases = self::ATTACHABLE;
public function getConfiguration() {
return array(
@ -33,10 +33,7 @@ final class PhortuneCart extends PhortuneDAO {
}
public function getPurchases() {
if ($this->purchases === null) {
throw new Exception("Purchases not attached to cart!");
}
return $this->purchases;
return $this->assertAttached($this->purchases);
}
}

View file

@ -22,7 +22,7 @@ final class PhortunePaymentMethod extends PhortuneDAO
protected $providerType;
protected $providerDomain;
private $account;
private $account = self::ATTACHABLE;
public function getConfiguration() {
return array(
@ -44,10 +44,7 @@ final class PhortunePaymentMethod extends PhortuneDAO
}
public function getAccount() {
if (!$this->account) {
throw new Exception("Call attachAccount() before getAccount()!");
}
return $this->account;
return $this->assertAttached($this->account);
}
public function getDescription() {

View file

@ -15,8 +15,8 @@ final class PhabricatorProject extends PhabricatorProjectDAO
protected $joinPolicy;
private $subprojectsNeedUpdate;
private $memberPHIDs;
private $sparseMembers = array();
private $memberPHIDs = self::ATTACHABLE;
private $sparseMembers = self::ATTACHABLE;
public function getCapabilities() {
return array(
@ -61,14 +61,13 @@ final class PhabricatorProject extends PhabricatorProjectDAO
}
public function isUserMember($user_phid) {
if (!isset($this->sparseMembers[$user_phid])) {
throw new Exception(
"Call setIsUserMember() before isUserMember()!");
}
return $this->sparseMembers[$user_phid];
return $this->assertAttachedKey($this->sparseMembers, $user_phid);
}
public function setIsUserMember($user_phid, $is_member) {
if ($this->sparseMembers === self::ATTACHABLE) {
$this->sparseMembers = array();
}
$this->sparseMembers[$user_phid] = $is_member;
return $this;
}
@ -100,10 +99,7 @@ final class PhabricatorProject extends PhabricatorProjectDAO
}
public function getMemberPHIDs() {
if ($this->memberPHIDs === null) {
throw new Exception("Call attachMemberPHIDs() first!");
}
return $this->memberPHIDs;
return $this->assertAttached($this->memberPHIDs);
}
public function loadMemberPHIDs() {

View file

@ -22,7 +22,7 @@ final class ReleephRequest extends ReleephDAO
protected $commitPHID;
// Pre-populated handles that we'll bulk load in ReleephBranch
private $handles;
private $handles = self::ATTACHABLE;
private $customFields = self::ATTACHABLE;
@ -148,11 +148,7 @@ final class ReleephRequest extends ReleephDAO
}
public function getHandles() {
if (!$this->handles) {
throw new Exception(
"You must call ReleephBranch::populateReleephRequestHandles() first");
}
return $this->handles;
return $this->assertAttached($this->handles);
}
public function getDetail($key, $default = null) {

View file

@ -15,7 +15,7 @@ final class PhabricatorRepositoryCommit
protected $auditStatus = PhabricatorAuditCommitStatusConstants::NONE;
protected $summary = '';
private $commitData;
private $commitData = self::ATTACHABLE;
private $audits;
private $isUnparsed;
private $repository = self::ATTACHABLE;
@ -65,10 +65,7 @@ final class PhabricatorRepositoryCommit
}
public function getCommitData() {
if (!$this->commitData) {
throw new Exception("Attach commit data with attachCommitData() first!");
}
return $this->commitData;
return $this->assertAttached($this->commitData);
}
public function attachAudits(array $audits) {

View file

@ -18,9 +18,9 @@ final class PhabricatorRepositorySymbol extends PhabricatorRepositoryDAO {
protected $pathID;
protected $lineNumber;
private $path = false;
private $arcanistProject = false;
private $repository = false;
private $path = self::ATTACHABLE;
private $arcanistProject = self::ATTACHABLE;
private $repository = self::ATTACHABLE;
public function getConfiguration() {
return array(
@ -51,10 +51,7 @@ final class PhabricatorRepositorySymbol extends PhabricatorRepositoryDAO {
}
public function getPath() {
if ($this->path === false) {
throw new Exception('Call attachPath() before getPath()!');
}
return $this->path;
return $this->assertAttached($this->path);
}
public function attachPath($path) {
@ -63,10 +60,7 @@ final class PhabricatorRepositorySymbol extends PhabricatorRepositoryDAO {
}
public function getRepository() {
if ($this->repository === false) {
throw new Exception('Call attachRepository() before getRepository()!');
}
return $this->repository;
return $this->assertAttached($this->repository);
}
public function attachRepository($repository) {
@ -75,11 +69,7 @@ final class PhabricatorRepositorySymbol extends PhabricatorRepositoryDAO {
}
public function getArcanistProject() {
if ($this->arcanistProject === false) {
throw new Exception(
'Call attachArcanistProject() before getArcanistProject()!');
}
return $this->arcanistProject;
return $this->assertAttached($this->arcanistProject);
}
public function attachArcanistProject($project) {

View file

@ -24,9 +24,9 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO
protected $method;
protected $viewPolicy;
private $options;
private $choices;
private $viewerChoices = array();
private $options = self::ATTACHABLE;
private $choices = self::ATTACHABLE;
private $viewerChoices = self::ATTACHABLE;
public function getConfiguration() {
return array(
@ -40,10 +40,7 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO
}
public function getOptions() {
if ($this->options === null) {
throw new Exception("Call attachOptions() before getOptions()!");
}
return $this->options;
return $this->assertAttached($this->options);
}
public function attachOptions(array $options) {
@ -53,10 +50,7 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO
}
public function getChoices() {
if ($this->choices === null) {
throw new Exception("Call attachChoices() before getChoices()!");
}
return $this->choices;
return $this->assertAttached($this->choices);
}
public function attachChoices(array $choices) {
@ -66,14 +60,13 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO
}
public function getViewerChoices(PhabricatorUser $viewer) {
if (idx($this->viewerChoices, $viewer->getPHID()) === null) {
throw new Exception(
"Call attachViewerChoices() before getViewerChoices()!");
}
return idx($this->viewerChoices, $viewer->getPHID());
return $this->assertAttachedKey($this->viewerChoices, $viewer->getPHID());
}
public function attachViewerChoices(PhabricatorUser $viewer, array $choices) {
if ($this->viewerChoices === self::ATTACHABLE) {
$this->viewerChoices = array();
}
assert_instances_of($choices, 'PhabricatorSlowvoteChoice');
$this->viewerChoices[$viewer->getPHID()] = $choices;
return $this;

View file

@ -7,7 +7,7 @@ final class PhabricatorTokenGiven extends PhabricatorTokenDAO
protected $objectPHID;
protected $tokenPHID;
private $object;
private $object = self::ATTACHABLE;
public function attachObject(PhabricatorTokenReceiverInterface $object) {
$this->object = $object;
@ -15,10 +15,7 @@ final class PhabricatorTokenGiven extends PhabricatorTokenDAO
}
public function getObject() {
if ($this->object === null) {
throw new Exception("Call attachObject() before getObject()!");
}
return $this->object;
return $this->assertAttached($this->object);
}
public function getCapabilities() {

View file

@ -6,7 +6,7 @@
*/
abstract class PhabricatorLiskDAO extends LiskDAO {
private $edges = array();
private $edges = self::ATTACHABLE;
private static $namespaceStack = array();
const ATTACHABLE = "<attachable>";
@ -29,11 +29,7 @@ abstract class PhabricatorLiskDAO extends LiskDAO {
* @task edges
*/
public function getEdges($type) {
$edges = idx($this->edges, $type);
if ($edges === null) {
throw new Exception("Call attachEdges() before getEdges()!");
}
return $edges;
return $this->assertAttachedKey($this->edges, $type);
}
@ -208,7 +204,6 @@ abstract class PhabricatorLiskDAO extends LiskDAO {
return $result;
}
protected function assertAttached($property) {
if ($property === self::ATTACHABLE) {
throw new PhabricatorDataNotAttachedException($this);
@ -216,4 +211,12 @@ abstract class PhabricatorLiskDAO extends LiskDAO {
return $property;
}
protected function assertAttachedKey($value, $key) {
$this->assertAttached($value);
if (!array_key_exists($key, $value)) {
throw new PhabricatorDataNotAttachedException($this);
}
return $value[$key];
}
}