1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

Simplify the implementation of PhabricatorPHIDType subclasses

Summary: Instead of implementing the `getTypeConstant` method in all subclasses of `PhabricatorPHIDType`, provide a `final` implementation in the base class which uses reflection. See D9837 for a similar implementation.

Test Plan: Ran `arc unit`.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin, hach-que

Differential Revision: https://secure.phabricator.com/D9985
This commit is contained in:
Joshua Spence 2014-07-22 00:38:23 +10:00
parent 37106c1b31
commit 254542237a
66 changed files with 32 additions and 281 deletions

View file

@ -4,10 +4,6 @@ final class PhabricatorAuthPHIDTypeAuthFactor extends PhabricatorPHIDType {
const TYPECONST = 'AFTR';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Auth Factor');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorCalendarPHIDTypeEvent extends PhabricatorPHIDType {
const TYPECONST = 'CEVT';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Event');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorConfigPHIDTypeConfig extends PhabricatorPHIDType {
const TYPECONST = 'CONF';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Config');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorConpherencePHIDTypeThread extends PhabricatorPHIDType {
const TYPECONST = 'CONP';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Conpherence Thread');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorCountdownPHIDTypeCountdown extends PhabricatorPHIDType {
const TYPECONST = 'CDWN';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Countdown');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorDashboardPHIDTypeDashboard extends PhabricatorPHIDType {
const TYPECONST = 'DSHB';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Dashboard');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorDashboardPHIDTypePanel extends PhabricatorPHIDType {
const TYPECONST = 'DSHP';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Panel');
}

View file

@ -4,10 +4,6 @@ final class DifferentialPHIDTypeDiff extends PhabricatorPHIDType {
const TYPECONST = 'DIFF';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Differential Diff');
}

View file

@ -4,10 +4,6 @@ final class DifferentialPHIDTypeRevision extends PhabricatorPHIDType {
const TYPECONST = 'DREV';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Revision');
}

View file

@ -4,10 +4,6 @@ final class DivinerPHIDTypeAtom extends PhabricatorPHIDType {
const TYPECONST = 'ATOM';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Atom');
}

View file

@ -4,10 +4,6 @@ final class DivinerPHIDTypeBook extends PhabricatorPHIDType {
const TYPECONST = 'BOOK';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Book');
}

View file

@ -4,10 +4,6 @@ final class DrydockPHIDTypeBlueprint extends PhabricatorPHIDType {
const TYPECONST = 'DRYB';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Blueprint');
}

View file

@ -4,10 +4,6 @@ final class DrydockPHIDTypeLease extends PhabricatorPHIDType {
const TYPECONST = 'DRYL';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Drydock Lease');
}

View file

@ -4,10 +4,6 @@ final class DrydockPHIDTypeResource extends PhabricatorPHIDType {
const TYPECONST = 'DRYR';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Drydock Resource');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorFilePHIDTypeFile extends PhabricatorPHIDType {
const TYPECONST = 'FILE';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('File');
}

View file

@ -4,10 +4,6 @@ final class HarbormasterPHIDTypeBuild extends PhabricatorPHIDType {
const TYPECONST = 'HMBD';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Build');
}

View file

@ -4,10 +4,6 @@ final class HarbormasterPHIDTypeBuildItem extends PhabricatorPHIDType {
const TYPECONST = 'HMBI';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Build Item');
}

View file

@ -4,10 +4,6 @@ final class HarbormasterPHIDTypeBuildLog extends PhabricatorPHIDType {
const TYPECONST = 'HMCL';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Build Log');
}

View file

@ -4,10 +4,6 @@ final class HarbormasterPHIDTypeBuildPlan extends PhabricatorPHIDType {
const TYPECONST = 'HMCP';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Build Plan');
}

View file

@ -4,10 +4,6 @@ final class HarbormasterPHIDTypeBuildStep extends PhabricatorPHIDType {
const TYPECONST = 'HMCS';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Build Step');
}

View file

@ -4,10 +4,6 @@ final class HarbormasterPHIDTypeBuildTarget extends PhabricatorPHIDType {
const TYPECONST = 'HMBT';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Build Target');
}

View file

@ -4,10 +4,6 @@ final class HarbormasterPHIDTypeBuildable extends PhabricatorPHIDType {
const TYPECONST = 'HMBB';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Buildable');
}

View file

@ -4,10 +4,6 @@ final class HeraldPHIDTypeRule extends PhabricatorPHIDType {
const TYPECONST = 'HRUL';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Herald Rule');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorLegalpadPHIDTypeDocument extends PhabricatorPHIDType {
const TYPECONST = 'LEGD';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Legalpad Document');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorMacroPHIDTypeMacro extends PhabricatorPHIDType {
const TYPECONST = 'MCRO';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Image Macro');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorMailingListPHIDTypeList extends PhabricatorPHIDType {
const TYPECONST = 'MLST';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Mailing List');
}

View file

@ -4,10 +4,6 @@ final class ManiphestPHIDTypeTask extends PhabricatorPHIDType {
const TYPECONST = 'TASK';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Task');
}

View file

@ -5,10 +5,6 @@ final class PhabricatorApplicationPHIDTypeApplication
const TYPECONST = 'APPS';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Application');
}

View file

@ -1,14 +1,9 @@
<?php
final class NuancePHIDTypeItem
extends PhabricatorPHIDType {
final class NuancePHIDTypeItem extends PhabricatorPHIDType {
const TYPECONST = 'NUAI';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Item');
}

View file

@ -5,10 +5,6 @@ final class NuancePHIDTypeQueue
const TYPECONST = 'NUAQ';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Queue');
}

View file

@ -1,14 +1,9 @@
<?php
final class NuancePHIDTypeRequestor
extends PhabricatorPHIDType {
final class NuancePHIDTypeRequestor extends PhabricatorPHIDType {
const TYPECONST = 'NUAR';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Requestor');
}

View file

@ -1,14 +1,9 @@
<?php
final class NuancePHIDTypeSource
extends PhabricatorPHIDType {
final class NuancePHIDTypeSource extends PhabricatorPHIDType {
const TYPECONST = 'NUAS';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Source');
}

View file

@ -5,10 +5,6 @@ final class PhabricatorOAuthServerPHIDTypeClient
const TYPECONST = 'OASC';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('OAuth Application');
}

View file

@ -5,10 +5,6 @@ final class PhabricatorOAuthServerPHIDTypeClientAuthorization
const TYPECONST = 'OASA';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('OAuth Authorization');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorOwnersPHIDTypePackage extends PhabricatorPHIDType {
const TYPECONST = 'OPKG';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Owners Package');
}

View file

@ -4,10 +4,6 @@ final class PassphrasePHIDTypeCredential extends PhabricatorPHIDType {
const TYPECONST = 'CDTL';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Credential');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorPastePHIDTypePaste extends PhabricatorPHIDType {
const TYPECONST = 'PSTE';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Paste');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorPeoplePHIDTypeExternal extends PhabricatorPHIDType {
const TYPECONST = 'XUSR';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('External Account');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorPeoplePHIDTypeUser extends PhabricatorPHIDType {
const TYPECONST = 'USER';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('User');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorPhamePHIDTypeBlog extends PhabricatorPHIDType {
const TYPECONST = 'BLOG';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Phame Blog');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorPhamePHIDTypePost extends PhabricatorPHIDType {
const TYPECONST = 'POST';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Phame Post');
}

View file

@ -2,7 +2,28 @@
abstract class PhabricatorPHIDType {
abstract public function getTypeConstant();
final public function getTypeConstant() {
$class = new ReflectionClass($this);
$const = $class->getConstant('TYPECONST');
if ($const === false) {
throw new Exception(
pht(
'PHIDType class "%s" must define an TYPECONST property.',
get_class($this)));
}
if (!is_string($const) || !preg_match('/^[A-Z]{4}$/', $const)) {
throw new Exception(
pht(
'PHIDType class "%s" has an invalid TYPECONST property. PHID '.
'constants must be a four character uppercase string.',
get_class($this)));
}
return $const;
}
abstract public function getTypeName();
public function newObject() {

View file

@ -4,10 +4,6 @@ final class PhluxPHIDTypeVariable extends PhabricatorPHIDType {
const TYPECONST = 'PVAR';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Variable');
}

View file

@ -4,10 +4,6 @@ final class PholioPHIDTypeImage extends PhabricatorPHIDType {
const TYPECONST = 'PIMG';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Image');
}

View file

@ -4,10 +4,6 @@ final class PholioPHIDTypeMock extends PhabricatorPHIDType {
const TYPECONST = 'MOCK';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Mock');
}

View file

@ -1,14 +1,9 @@
<?php
final class PhragmentPHIDTypeFragment
extends PhabricatorPHIDType {
final class PhragmentPHIDTypeFragment extends PhabricatorPHIDType {
const TYPECONST = 'PHRF';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Fragment');
}

View file

@ -1,14 +1,9 @@
<?php
final class PhragmentPHIDTypeFragmentVersion
extends PhabricatorPHIDType {
final class PhragmentPHIDTypeFragmentVersion extends PhabricatorPHIDType {
const TYPECONST = 'PHRV';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Fragment Version');
}

View file

@ -1,14 +1,9 @@
<?php
final class PhragmentPHIDTypeSnapshot
extends PhabricatorPHIDType {
final class PhragmentPHIDTypeSnapshot extends PhabricatorPHIDType {
const TYPECONST = 'PHRS';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Snapshot');
}

View file

@ -4,10 +4,6 @@ final class PhrictionPHIDTypeDocument extends PhabricatorPHIDType {
const TYPECONST = 'WIKI';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Wiki Document');
}

View file

@ -1,14 +1,9 @@
<?php
final class PhabricatorPolicyPHIDTypePolicy
extends PhabricatorPHIDType {
final class PhabricatorPolicyPHIDTypePolicy extends PhabricatorPHIDType {
const TYPECONST = 'PLCY';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Policy');
}

View file

@ -4,10 +4,6 @@ final class PonderPHIDTypeAnswer extends PhabricatorPHIDType {
const TYPECONST = 'ANSW';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Answer');
}

View file

@ -4,10 +4,6 @@ final class PonderPHIDTypeQuestion extends PhabricatorPHIDType {
const TYPECONST = 'QUES';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Question');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorProjectPHIDTypeColumn extends PhabricatorPHIDType {
const TYPECONST = 'PCOL';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Project Column');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorProjectPHIDTypeProject extends PhabricatorPHIDType {
const TYPECONST = 'PROJ';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Project');
}

View file

@ -4,10 +4,6 @@ final class ReleephPHIDTypeBranch extends PhabricatorPHIDType {
const TYPECONST = 'REBR';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Releeph Branch');
}

View file

@ -4,10 +4,6 @@ final class ReleephPHIDTypeProduct extends PhabricatorPHIDType {
const TYPECONST = 'REPR';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Releeph Product');
}

View file

@ -4,10 +4,6 @@ final class ReleephPHIDTypeRequest extends PhabricatorPHIDType {
const TYPECONST = 'RERQ';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Releeph Request');
}

View file

@ -5,10 +5,6 @@ final class PhabricatorRepositoryPHIDTypeArcanistProject
const TYPECONST = 'APRJ';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Arcanist Project');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorRepositoryPHIDTypeCommit extends PhabricatorPHIDType {
const TYPECONST = 'CMIT';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Commit');
}

View file

@ -1,14 +1,9 @@
<?php
final class PhabricatorRepositoryPHIDTypeMirror
extends PhabricatorPHIDType {
final class PhabricatorRepositoryPHIDTypeMirror extends PhabricatorPHIDType {
const TYPECONST = 'RMIR';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Repository Mirror');
}

View file

@ -1,14 +1,9 @@
<?php
final class PhabricatorRepositoryPHIDTypePushEvent
extends PhabricatorPHIDType {
final class PhabricatorRepositoryPHIDTypePushEvent extends PhabricatorPHIDType {
const TYPECONST = 'PSHE';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Push Event');
}

View file

@ -1,14 +1,9 @@
<?php
final class PhabricatorRepositoryPHIDTypePushLog
extends PhabricatorPHIDType {
final class PhabricatorRepositoryPHIDTypePushLog extends PhabricatorPHIDType {
const TYPECONST = 'PSHL';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Push Log');
}

View file

@ -5,10 +5,6 @@ final class PhabricatorRepositoryPHIDTypeRepository
const TYPECONST = 'REPO';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Repository');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorSlowvotePHIDTypePoll extends PhabricatorPHIDType {
const TYPECONST = 'POLL';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Slowvote Poll');
}

View file

@ -4,10 +4,6 @@ final class PhabricatorTokenPHIDTypeToken extends PhabricatorPHIDType {
const TYPECONST = 'TOKN';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Token');
}

View file

@ -5,10 +5,6 @@ final class PhabricatorApplicationTransactionPHIDTypeTransaction
const TYPECONST = 'XACT';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Transaction');
}