mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01:00
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:
parent
01767c482d
commit
582fc847f2
27 changed files with 64 additions and 7 deletions
|
@ -258,7 +258,7 @@ final class PhabricatorAuditCommentEditor {
|
|||
array $other_comments,
|
||||
array $inline_comments) {
|
||||
assert_instances_of($other_comments, 'PhabricatorAuditComment');
|
||||
assert_instances_of($inline_comments, 'PhabricatorAuditInlineComment');
|
||||
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
|
||||
|
||||
$commit = $this->commit;
|
||||
|
||||
|
@ -350,7 +350,7 @@ final class PhabricatorAuditCommentEditor {
|
|||
PhabricatorObjectHandle $handle,
|
||||
PhabricatorMailReplyHandler $reply_handler,
|
||||
array $inline_comments) {
|
||||
assert_instances_of($inline_comments, 'PhabricatorAuditInlineComment');
|
||||
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
|
||||
|
||||
$commit = $this->commit;
|
||||
$user = $this->user;
|
||||
|
|
|
@ -344,6 +344,7 @@ final class DifferentialRevisionListController extends DifferentialController {
|
|||
array $handles,
|
||||
PhutilURI $uri,
|
||||
array $params) {
|
||||
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
||||
switch ($control) {
|
||||
case 'subscriber':
|
||||
case 'phid':
|
||||
|
@ -422,6 +423,8 @@ final class DifferentialRevisionListController extends DifferentialController {
|
|||
}
|
||||
|
||||
private function buildViews($filter, $user_phid, array $revisions) {
|
||||
assert_instances_of($revisions, 'DifferentialRevision');
|
||||
|
||||
$user = $this->getRequest()->getUser();
|
||||
|
||||
$template = id(new DifferentialRevisionListView())
|
||||
|
|
|
@ -546,6 +546,8 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||
}
|
||||
|
||||
private function loadInlineComments(array $comments, array &$changesets) {
|
||||
assert_instances_of($comments, 'DifferentialComment');
|
||||
assert_instances_of($changesets, 'DifferentialChangeset');
|
||||
|
||||
$inline_comments = array();
|
||||
|
||||
|
@ -585,7 +587,12 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||
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();
|
||||
if ($diff_vs) {
|
||||
$load_ids[] = $diff_vs;
|
||||
|
@ -695,6 +702,7 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||
DifferentialDiff $target,
|
||||
PhabricatorRepositoryArcanistProject $arc_project,
|
||||
array $visible_changesets) {
|
||||
assert_instances_of($visible_changesets, 'DifferentialChangeset');
|
||||
|
||||
$engine = PhabricatorSyntaxHighlighter::newEngine();
|
||||
|
||||
|
@ -768,6 +776,8 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||
}
|
||||
|
||||
private function renderOtherRevisions(array $revisions) {
|
||||
assert_instances_of($revisions, 'DifferentialRevision');
|
||||
|
||||
$view = id(new DifferentialRevisionListView())
|
||||
->setRevisions($revisions)
|
||||
->setFields(DifferentialRevisionListView::getDefaultFields())
|
||||
|
|
|
@ -761,6 +761,7 @@ final class DifferentialRevisionEditor {
|
|||
DifferentialRevision $revision,
|
||||
DifferentialDiff $diff,
|
||||
array $changesets) {
|
||||
assert_instances_of($changesets, 'DifferentialChangeset');
|
||||
|
||||
$project = $diff->loadArcanistProject();
|
||||
if (!$project) {
|
||||
|
|
|
@ -29,6 +29,7 @@ abstract class DifferentialFieldSelector {
|
|||
abstract public function getFieldSpecifications();
|
||||
|
||||
public function sortFieldsForRevisionList(array $fields) {
|
||||
assert_instances_of($fields, 'DifferentialFieldSpecification');
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,5 +8,7 @@
|
|||
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('DifferentialFieldSelector.php');
|
||||
|
|
|
@ -62,6 +62,8 @@ final class DifferentialDefaultFieldSelector
|
|||
}
|
||||
|
||||
public function sortFieldsForRevisionList(array $fields) {
|
||||
assert_instances_of($fields, 'DifferentialFieldSpecification');
|
||||
|
||||
$map = array();
|
||||
foreach ($fields as $field) {
|
||||
$map[get_class($field)] = $field;
|
||||
|
|
|
@ -741,6 +741,7 @@ abstract class DifferentialFieldSpecification {
|
|||
* @task context
|
||||
*/
|
||||
final public function setHandles(array $handles) {
|
||||
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
||||
$this->handles = $handles;
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -343,6 +343,7 @@ EOTEXT;
|
|||
}
|
||||
|
||||
public function setInlineComments(array $inline_comments) {
|
||||
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
|
||||
$this->inlineComments = $inline_comments;
|
||||
return $this;
|
||||
}
|
||||
|
@ -388,6 +389,7 @@ EOTEXT;
|
|||
}
|
||||
|
||||
protected function renderHandleList(array $handles, array $phids) {
|
||||
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
||||
$names = array();
|
||||
foreach ($phids as $phid) {
|
||||
$names[] = $handles[$phid]->getName();
|
||||
|
|
|
@ -35,6 +35,8 @@ final class DifferentialCommentMail extends DifferentialMail {
|
|||
DifferentialComment $comment,
|
||||
array $changesets,
|
||||
array $inline_comments) {
|
||||
assert_instances_of($changesets, 'DifferentialChangeset');
|
||||
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
|
||||
|
||||
$this->setRevision($revision);
|
||||
$this->setActorHandle($actor);
|
||||
|
|
|
@ -33,6 +33,7 @@ abstract class DifferentialReviewRequestMail extends DifferentialMail {
|
|||
DifferentialRevision $revision,
|
||||
PhabricatorObjectHandle $actor,
|
||||
array $changesets) {
|
||||
assert_instances_of($changesets, 'DifferentialChangeset');
|
||||
|
||||
$this->setRevision($revision);
|
||||
$this->setActorHandle($actor);
|
||||
|
|
|
@ -169,6 +169,7 @@ final class DifferentialChangesetParser {
|
|||
}
|
||||
|
||||
public function setHandles(array $handles) {
|
||||
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
||||
$this->handles = $handles;
|
||||
return $this;
|
||||
}
|
||||
|
@ -1173,6 +1174,9 @@ final class DifferentialChangesetParser {
|
|||
$feedback_mask,
|
||||
array $old_comments,
|
||||
array $new_comments) {
|
||||
foreach (array_merge($old_comments, $new_comments) as $comments) {
|
||||
assert_instances_of($comments, 'PhabricatorInlineCommentInterface');
|
||||
}
|
||||
|
||||
$context_not_available = null;
|
||||
if ($this->missingOld || $this->missingNew) {
|
||||
|
|
|
@ -750,6 +750,7 @@ final class DifferentialRevisionQuery {
|
|||
}
|
||||
|
||||
private function loadRelationships($conn_r, array $revisions) {
|
||||
assert_instances_of($revisions, 'DifferentialRevision');
|
||||
$relationships = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT * FROM %T WHERE revisionID in (%Ld) ORDER BY sequence',
|
||||
|
@ -766,6 +767,7 @@ final class DifferentialRevisionQuery {
|
|||
}
|
||||
|
||||
private function loadCommitPHIDs($conn_r, array $revisions) {
|
||||
assert_instances_of($revisions, 'DifferentialRevision');
|
||||
$commit_phids = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT * FROM %T WHERE revisionID IN (%Ld)',
|
||||
|
@ -780,6 +782,8 @@ final class DifferentialRevisionQuery {
|
|||
}
|
||||
|
||||
private function loadDiffIDs($conn_r, array $revisions) {
|
||||
assert_instances_of($revisions, 'DifferentialRevision');
|
||||
|
||||
$diff_table = new DifferentialDiff();
|
||||
|
||||
$diff_ids = queryfx_all(
|
||||
|
@ -798,6 +802,8 @@ final class DifferentialRevisionQuery {
|
|||
}
|
||||
|
||||
private function loadActiveDiffs($conn_r, array $revisions) {
|
||||
assert_instances_of($revisions, 'DifferentialRevision');
|
||||
|
||||
$diff_table = new DifferentialDiff();
|
||||
|
||||
$load_ids = array();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (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(
|
||||
DifferentialRevision $revision,
|
||||
array $aux_fields) {
|
||||
assert_instances_of($aux_fields, 'DifferentialFieldSpecification');
|
||||
|
||||
$storage_keys = array_filter(mpull($aux_fields, 'getStorageKey'));
|
||||
$field_data = array();
|
||||
|
|
|
@ -58,6 +58,7 @@ final class DifferentialChangeset extends DifferentialDAO {
|
|||
}
|
||||
|
||||
public function attachHunks(array $hunks) {
|
||||
assert_instances_of($hunks, 'DifferentialHunk');
|
||||
$this->hunks = $hunks;
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ final class DifferentialDiff extends DifferentialDAO {
|
|||
}
|
||||
|
||||
public function attachChangesets(array $changesets) {
|
||||
assert_instances_of($changesets, 'DifferentialChangeset');
|
||||
$this->changesets = $changesets;
|
||||
return $this;
|
||||
}
|
||||
|
@ -107,6 +108,7 @@ final class DifferentialDiff extends DifferentialDAO {
|
|||
}
|
||||
|
||||
public static function newFromRawChanges(array $changes) {
|
||||
assert_instances_of($changes, 'ArcanistDiffChange');
|
||||
$diff = new DifferentialDiff();
|
||||
|
||||
$lines = 0;
|
||||
|
|
|
@ -42,6 +42,7 @@ final class DifferentialInlineCommentView extends AphrontView {
|
|||
}
|
||||
|
||||
public function setHandles(array $handles) {
|
||||
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
||||
$this->handles = $handles;
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ phutil_require_module('phabricator', 'infrastructure/javelin/markup');
|
|||
phutil_require_module('phabricator', 'view/base');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('DifferentialInlineCommentView.php');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (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) {
|
||||
assert_instances_of($changesets, 'DifferentialChangeset');
|
||||
if (empty($changesets)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
phutil_require_module('phabricator', 'view/base');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('DifferentialPrimaryPaneView.php');
|
||||
|
|
|
@ -35,6 +35,7 @@ final class DifferentialRevisionCommentView extends AphrontView {
|
|||
}
|
||||
|
||||
public function setHandles(array $handles) {
|
||||
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
||||
$this->handles = $handles;
|
||||
return $this;
|
||||
}
|
||||
|
@ -50,11 +51,13 @@ final class DifferentialRevisionCommentView extends AphrontView {
|
|||
}
|
||||
|
||||
public function setInlineComments(array $inline_comments) {
|
||||
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
|
||||
$this->inlines = $inline_comments;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setChangesets(array $changesets) {
|
||||
assert_instances_of($changesets, 'DifferentialChangeset');
|
||||
// Ship these in sorted by getSortKey() and keyed by ID... or else!
|
||||
$this->changesets = $changesets;
|
||||
return $this;
|
||||
|
|
|
@ -27,21 +27,25 @@ final class DifferentialRevisionCommentListView extends AphrontView {
|
|||
private $versusDiffID;
|
||||
|
||||
public function setComments(array $comments) {
|
||||
assert_instances_of($comments, 'DifferentialComment');
|
||||
$this->comments = $comments;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setInlineComments(array $inline_comments) {
|
||||
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
|
||||
$this->inlines = $inline_comments;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setHandles(array $handles) {
|
||||
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
||||
$this->handles = $handles;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setChangesets(array $changesets) {
|
||||
assert_instances_of($changesets, 'DifferentialChangeset');
|
||||
$this->changesets = $changesets;
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -28,11 +28,13 @@ final class DifferentialRevisionListView extends AphrontView {
|
|||
private $fields;
|
||||
|
||||
public function setFields(array $fields) {
|
||||
assert_instances_of($fields, 'DifferentialFieldSpecification');
|
||||
$this->fields = $fields;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setRevisions(array $revisions) {
|
||||
assert_instances_of($revisions, 'DifferentialRevision');
|
||||
$this->revisions = $revisions;
|
||||
return $this;
|
||||
}
|
||||
|
@ -48,6 +50,7 @@ final class DifferentialRevisionListView extends AphrontView {
|
|||
}
|
||||
|
||||
public function setHandles(array $handles) {
|
||||
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
||||
$this->handles = $handles;
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -25,14 +25,17 @@ final class DifferentialRevisionStatsView extends AphrontView {
|
|||
private $user;
|
||||
|
||||
public function setRevisions(array $revisions) {
|
||||
assert_instances_of($revisions, 'DifferentialRevision');
|
||||
$this->revisions = $revisions;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setComments(array $comments) {
|
||||
assert_instances_of($comments, 'DifferentialComment');
|
||||
$this->comments = $comments;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setUser($user) {
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
|
|
|
@ -56,7 +56,7 @@ final class DiffusionCommentView extends AphrontView {
|
|||
}
|
||||
|
||||
public function setInlineComments(array $inline_comments) {
|
||||
assert_instances_of($inline_comments, 'PhabricatorAuditInlineComment');
|
||||
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
|
||||
$this->inlineComments = $inline_comments;
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ final class DiffusionCommentListView extends AphrontView {
|
|||
}
|
||||
|
||||
public function setInlineComments(array $inline_comments) {
|
||||
assert_instances_of($inline_comments, 'PhabricatorAuditInlineComment');
|
||||
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
|
||||
$this->inlineComments = $inline_comments;
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ guidelines, you probably don't need to read this super thoroughly.
|
|||
- Prefer class constants over defines.
|
||||
- Avoid naked class properties; instead, define accessors.
|
||||
- Use exceptions for error conditions.
|
||||
- Use type hints, use `assert_instances_of()` for arrays holding objects.
|
||||
|
||||
= Examples =
|
||||
|
||||
|
|
Loading…
Reference in a new issue