Use assert_instances_of() in Differential

Summary: NOTE: This is not produced by a script so there might be errors. Please review carefully.

Test Plan: Browse around Differential.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran

Differential Revision: https://secure.phabricator.com/D2103
This commit is contained in:
vrana
2012-04-04 13:13:08 -07:00
parent 01767c482d
commit 582fc847f2
27 changed files with 64 additions and 7 deletions

View File

@@ -258,7 +258,7 @@ final class PhabricatorAuditCommentEditor {
array $other_comments, array $other_comments,
array $inline_comments) { array $inline_comments) {
assert_instances_of($other_comments, 'PhabricatorAuditComment'); assert_instances_of($other_comments, 'PhabricatorAuditComment');
assert_instances_of($inline_comments, 'PhabricatorAuditInlineComment'); assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
$commit = $this->commit; $commit = $this->commit;
@@ -350,7 +350,7 @@ final class PhabricatorAuditCommentEditor {
PhabricatorObjectHandle $handle, PhabricatorObjectHandle $handle,
PhabricatorMailReplyHandler $reply_handler, PhabricatorMailReplyHandler $reply_handler,
array $inline_comments) { array $inline_comments) {
assert_instances_of($inline_comments, 'PhabricatorAuditInlineComment'); assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
$commit = $this->commit; $commit = $this->commit;
$user = $this->user; $user = $this->user;

View File

@@ -344,6 +344,7 @@ final class DifferentialRevisionListController extends DifferentialController {
array $handles, array $handles,
PhutilURI $uri, PhutilURI $uri,
array $params) { array $params) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
switch ($control) { switch ($control) {
case 'subscriber': case 'subscriber':
case 'phid': case 'phid':
@@ -422,6 +423,8 @@ final class DifferentialRevisionListController extends DifferentialController {
} }
private function buildViews($filter, $user_phid, array $revisions) { private function buildViews($filter, $user_phid, array $revisions) {
assert_instances_of($revisions, 'DifferentialRevision');
$user = $this->getRequest()->getUser(); $user = $this->getRequest()->getUser();
$template = id(new DifferentialRevisionListView()) $template = id(new DifferentialRevisionListView())

View File

@@ -546,6 +546,8 @@ final class DifferentialRevisionViewController extends DifferentialController {
} }
private function loadInlineComments(array $comments, array &$changesets) { private function loadInlineComments(array $comments, array &$changesets) {
assert_instances_of($comments, 'DifferentialComment');
assert_instances_of($changesets, 'DifferentialChangeset');
$inline_comments = array(); $inline_comments = array();
@@ -585,7 +587,12 @@ final class DifferentialRevisionViewController extends DifferentialController {
return $inline_comments; return $inline_comments;
} }
private function loadChangesetsAndVsMap(array $diffs, $diff_vs, $target) { private function loadChangesetsAndVsMap(
array $diffs,
$diff_vs,
DifferentialDiff $target) {
assert_instances_of($diffs, 'DifferentialDiff');
$load_ids = array(); $load_ids = array();
if ($diff_vs) { if ($diff_vs) {
$load_ids[] = $diff_vs; $load_ids[] = $diff_vs;
@@ -695,6 +702,7 @@ final class DifferentialRevisionViewController extends DifferentialController {
DifferentialDiff $target, DifferentialDiff $target,
PhabricatorRepositoryArcanistProject $arc_project, PhabricatorRepositoryArcanistProject $arc_project,
array $visible_changesets) { array $visible_changesets) {
assert_instances_of($visible_changesets, 'DifferentialChangeset');
$engine = PhabricatorSyntaxHighlighter::newEngine(); $engine = PhabricatorSyntaxHighlighter::newEngine();
@@ -768,6 +776,8 @@ final class DifferentialRevisionViewController extends DifferentialController {
} }
private function renderOtherRevisions(array $revisions) { private function renderOtherRevisions(array $revisions) {
assert_instances_of($revisions, 'DifferentialRevision');
$view = id(new DifferentialRevisionListView()) $view = id(new DifferentialRevisionListView())
->setRevisions($revisions) ->setRevisions($revisions)
->setFields(DifferentialRevisionListView::getDefaultFields()) ->setFields(DifferentialRevisionListView::getDefaultFields())

View File

@@ -761,6 +761,7 @@ final class DifferentialRevisionEditor {
DifferentialRevision $revision, DifferentialRevision $revision,
DifferentialDiff $diff, DifferentialDiff $diff,
array $changesets) { array $changesets) {
assert_instances_of($changesets, 'DifferentialChangeset');
$project = $diff->loadArcanistProject(); $project = $diff->loadArcanistProject();
if (!$project) { if (!$project) {

View File

@@ -29,6 +29,7 @@ abstract class DifferentialFieldSelector {
abstract public function getFieldSpecifications(); abstract public function getFieldSpecifications();
public function sortFieldsForRevisionList(array $fields) { public function sortFieldsForRevisionList(array $fields) {
assert_instances_of($fields, 'DifferentialFieldSpecification');
return $fields; return $fields;
} }

View File

@@ -8,5 +8,7 @@
phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phabricator', 'infrastructure/env');
phutil_require_module('phutil', 'utils');
phutil_require_source('DifferentialFieldSelector.php'); phutil_require_source('DifferentialFieldSelector.php');

View File

@@ -62,6 +62,8 @@ final class DifferentialDefaultFieldSelector
} }
public function sortFieldsForRevisionList(array $fields) { public function sortFieldsForRevisionList(array $fields) {
assert_instances_of($fields, 'DifferentialFieldSpecification');
$map = array(); $map = array();
foreach ($fields as $field) { foreach ($fields as $field) {
$map[get_class($field)] = $field; $map[get_class($field)] = $field;

View File

@@ -741,6 +741,7 @@ abstract class DifferentialFieldSpecification {
* @task context * @task context
*/ */
final public function setHandles(array $handles) { final public function setHandles(array $handles) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
$this->handles = $handles; $this->handles = $handles;
return $this; return $this;
} }

View File

@@ -343,6 +343,7 @@ EOTEXT;
} }
public function setInlineComments(array $inline_comments) { public function setInlineComments(array $inline_comments) {
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
$this->inlineComments = $inline_comments; $this->inlineComments = $inline_comments;
return $this; return $this;
} }
@@ -388,6 +389,7 @@ EOTEXT;
} }
protected function renderHandleList(array $handles, array $phids) { protected function renderHandleList(array $handles, array $phids) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
$names = array(); $names = array();
foreach ($phids as $phid) { foreach ($phids as $phid) {
$names[] = $handles[$phid]->getName(); $names[] = $handles[$phid]->getName();

View File

@@ -35,6 +35,8 @@ final class DifferentialCommentMail extends DifferentialMail {
DifferentialComment $comment, DifferentialComment $comment,
array $changesets, array $changesets,
array $inline_comments) { array $inline_comments) {
assert_instances_of($changesets, 'DifferentialChangeset');
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
$this->setRevision($revision); $this->setRevision($revision);
$this->setActorHandle($actor); $this->setActorHandle($actor);

View File

@@ -33,6 +33,7 @@ abstract class DifferentialReviewRequestMail extends DifferentialMail {
DifferentialRevision $revision, DifferentialRevision $revision,
PhabricatorObjectHandle $actor, PhabricatorObjectHandle $actor,
array $changesets) { array $changesets) {
assert_instances_of($changesets, 'DifferentialChangeset');
$this->setRevision($revision); $this->setRevision($revision);
$this->setActorHandle($actor); $this->setActorHandle($actor);

View File

@@ -169,6 +169,7 @@ final class DifferentialChangesetParser {
} }
public function setHandles(array $handles) { public function setHandles(array $handles) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
$this->handles = $handles; $this->handles = $handles;
return $this; return $this;
} }
@@ -1173,6 +1174,9 @@ final class DifferentialChangesetParser {
$feedback_mask, $feedback_mask,
array $old_comments, array $old_comments,
array $new_comments) { array $new_comments) {
foreach (array_merge($old_comments, $new_comments) as $comments) {
assert_instances_of($comments, 'PhabricatorInlineCommentInterface');
}
$context_not_available = null; $context_not_available = null;
if ($this->missingOld || $this->missingNew) { if ($this->missingOld || $this->missingNew) {

View File

@@ -750,6 +750,7 @@ final class DifferentialRevisionQuery {
} }
private function loadRelationships($conn_r, array $revisions) { private function loadRelationships($conn_r, array $revisions) {
assert_instances_of($revisions, 'DifferentialRevision');
$relationships = queryfx_all( $relationships = queryfx_all(
$conn_r, $conn_r,
'SELECT * FROM %T WHERE revisionID in (%Ld) ORDER BY sequence', 'SELECT * FROM %T WHERE revisionID in (%Ld) ORDER BY sequence',
@@ -766,6 +767,7 @@ final class DifferentialRevisionQuery {
} }
private function loadCommitPHIDs($conn_r, array $revisions) { private function loadCommitPHIDs($conn_r, array $revisions) {
assert_instances_of($revisions, 'DifferentialRevision');
$commit_phids = queryfx_all( $commit_phids = queryfx_all(
$conn_r, $conn_r,
'SELECT * FROM %T WHERE revisionID IN (%Ld)', 'SELECT * FROM %T WHERE revisionID IN (%Ld)',
@@ -780,6 +782,8 @@ final class DifferentialRevisionQuery {
} }
private function loadDiffIDs($conn_r, array $revisions) { private function loadDiffIDs($conn_r, array $revisions) {
assert_instances_of($revisions, 'DifferentialRevision');
$diff_table = new DifferentialDiff(); $diff_table = new DifferentialDiff();
$diff_ids = queryfx_all( $diff_ids = queryfx_all(
@@ -798,6 +802,8 @@ final class DifferentialRevisionQuery {
} }
private function loadActiveDiffs($conn_r, array $revisions) { private function loadActiveDiffs($conn_r, array $revisions) {
assert_instances_of($revisions, 'DifferentialRevision');
$diff_table = new DifferentialDiff(); $diff_table = new DifferentialDiff();
$load_ids = array(); $load_ids = array();

View File

@@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@ final class DifferentialAuxiliaryField extends DifferentialDAO {
public static function loadFromStorage( public static function loadFromStorage(
DifferentialRevision $revision, DifferentialRevision $revision,
array $aux_fields) { array $aux_fields) {
assert_instances_of($aux_fields, 'DifferentialFieldSpecification');
$storage_keys = array_filter(mpull($aux_fields, 'getStorageKey')); $storage_keys = array_filter(mpull($aux_fields, 'getStorageKey'));
$field_data = array(); $field_data = array();

View File

@@ -58,6 +58,7 @@ final class DifferentialChangeset extends DifferentialDAO {
} }
public function attachHunks(array $hunks) { public function attachHunks(array $hunks) {
assert_instances_of($hunks, 'DifferentialHunk');
$this->hunks = $hunks; $this->hunks = $hunks;
return $this; return $this;
} }

View File

@@ -55,6 +55,7 @@ final class DifferentialDiff extends DifferentialDAO {
} }
public function attachChangesets(array $changesets) { public function attachChangesets(array $changesets) {
assert_instances_of($changesets, 'DifferentialChangeset');
$this->changesets = $changesets; $this->changesets = $changesets;
return $this; return $this;
} }
@@ -107,6 +108,7 @@ final class DifferentialDiff extends DifferentialDAO {
} }
public static function newFromRawChanges(array $changes) { public static function newFromRawChanges(array $changes) {
assert_instances_of($changes, 'ArcanistDiffChange');
$diff = new DifferentialDiff(); $diff = new DifferentialDiff();
$lines = 0; $lines = 0;

View File

@@ -42,6 +42,7 @@ final class DifferentialInlineCommentView extends AphrontView {
} }
public function setHandles(array $handles) { public function setHandles(array $handles) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
$this->handles = $handles; $this->handles = $handles;
return $this; return $this;
} }

View File

@@ -11,6 +11,7 @@ phutil_require_module('phabricator', 'infrastructure/javelin/markup');
phutil_require_module('phabricator', 'view/base'); phutil_require_module('phabricator', 'view/base');
phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('DifferentialInlineCommentView.php'); phutil_require_source('DifferentialInlineCommentView.php');

View File

@@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ final class DifferentialPrimaryPaneView extends AphrontView {
} }
public function setLineWidthFromChangesets(array $changesets) { public function setLineWidthFromChangesets(array $changesets) {
assert_instances_of($changesets, 'DifferentialChangeset');
if (empty($changesets)) { if (empty($changesets)) {
return; return;
} }

View File

@@ -9,6 +9,7 @@
phutil_require_module('phabricator', 'view/base'); phutil_require_module('phabricator', 'view/base');
phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('DifferentialPrimaryPaneView.php'); phutil_require_source('DifferentialPrimaryPaneView.php');

View File

@@ -35,6 +35,7 @@ final class DifferentialRevisionCommentView extends AphrontView {
} }
public function setHandles(array $handles) { public function setHandles(array $handles) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
$this->handles = $handles; $this->handles = $handles;
return $this; return $this;
} }
@@ -50,11 +51,13 @@ final class DifferentialRevisionCommentView extends AphrontView {
} }
public function setInlineComments(array $inline_comments) { public function setInlineComments(array $inline_comments) {
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
$this->inlines = $inline_comments; $this->inlines = $inline_comments;
return $this; return $this;
} }
public function setChangesets(array $changesets) { public function setChangesets(array $changesets) {
assert_instances_of($changesets, 'DifferentialChangeset');
// Ship these in sorted by getSortKey() and keyed by ID... or else! // Ship these in sorted by getSortKey() and keyed by ID... or else!
$this->changesets = $changesets; $this->changesets = $changesets;
return $this; return $this;

View File

@@ -27,21 +27,25 @@ final class DifferentialRevisionCommentListView extends AphrontView {
private $versusDiffID; private $versusDiffID;
public function setComments(array $comments) { public function setComments(array $comments) {
assert_instances_of($comments, 'DifferentialComment');
$this->comments = $comments; $this->comments = $comments;
return $this; return $this;
} }
public function setInlineComments(array $inline_comments) { public function setInlineComments(array $inline_comments) {
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
$this->inlines = $inline_comments; $this->inlines = $inline_comments;
return $this; return $this;
} }
public function setHandles(array $handles) { public function setHandles(array $handles) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
$this->handles = $handles; $this->handles = $handles;
return $this; return $this;
} }
public function setChangesets(array $changesets) { public function setChangesets(array $changesets) {
assert_instances_of($changesets, 'DifferentialChangeset');
$this->changesets = $changesets; $this->changesets = $changesets;
return $this; return $this;
} }

View File

@@ -28,11 +28,13 @@ final class DifferentialRevisionListView extends AphrontView {
private $fields; private $fields;
public function setFields(array $fields) { public function setFields(array $fields) {
assert_instances_of($fields, 'DifferentialFieldSpecification');
$this->fields = $fields; $this->fields = $fields;
return $this; return $this;
} }
public function setRevisions(array $revisions) { public function setRevisions(array $revisions) {
assert_instances_of($revisions, 'DifferentialRevision');
$this->revisions = $revisions; $this->revisions = $revisions;
return $this; return $this;
} }
@@ -48,6 +50,7 @@ final class DifferentialRevisionListView extends AphrontView {
} }
public function setHandles(array $handles) { public function setHandles(array $handles) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
$this->handles = $handles; $this->handles = $handles;
return $this; return $this;
} }

View File

@@ -25,14 +25,17 @@ final class DifferentialRevisionStatsView extends AphrontView {
private $user; private $user;
public function setRevisions(array $revisions) { public function setRevisions(array $revisions) {
assert_instances_of($revisions, 'DifferentialRevision');
$this->revisions = $revisions; $this->revisions = $revisions;
return $this; return $this;
} }
public function setComments(array $comments) { public function setComments(array $comments) {
assert_instances_of($comments, 'DifferentialComment');
$this->comments = $comments; $this->comments = $comments;
return $this; return $this;
} }
public function setUser($user) { public function setUser($user) {
$this->user = $user; $this->user = $user;
return $this; return $this;

View File

@@ -56,7 +56,7 @@ final class DiffusionCommentView extends AphrontView {
} }
public function setInlineComments(array $inline_comments) { public function setInlineComments(array $inline_comments) {
assert_instances_of($inline_comments, 'PhabricatorAuditInlineComment'); assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
$this->inlineComments = $inline_comments; $this->inlineComments = $inline_comments;
return $this; return $this;
} }

View File

@@ -35,7 +35,7 @@ final class DiffusionCommentListView extends AphrontView {
} }
public function setInlineComments(array $inline_comments) { public function setInlineComments(array $inline_comments) {
assert_instances_of($inline_comments, 'PhabricatorAuditInlineComment'); assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
$this->inlineComments = $inline_comments; $this->inlineComments = $inline_comments;
return $this; return $this;
} }

View File

@@ -61,6 +61,7 @@ guidelines, you probably don't need to read this super thoroughly.
- Prefer class constants over defines. - Prefer class constants over defines.
- Avoid naked class properties; instead, define accessors. - Avoid naked class properties; instead, define accessors.
- Use exceptions for error conditions. - Use exceptions for error conditions.
- Use type hints, use `assert_instances_of()` for arrays holding objects.
= Examples = = Examples =