1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 00:32:42 +01:00

Use getPhobjectClassConstant() to access class constants

Summary: Ref T9494. Depends on D14216. Remove 10 copies of this code.

Test Plan: Ran `arc unit --everything`, browsed Config > Modules, clicked around Herald / etc.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9494

Differential Revision: https://secure.phabricator.com/D14217
This commit is contained in:
epriestley 2015-10-01 16:56:21 -07:00
parent c95fcb8970
commit e431ab2189
10 changed files with 12 additions and 196 deletions

View file

@ -28,35 +28,7 @@ abstract class DrydockLogType extends Phobject {
}
final public function getLogTypeConstant() {
$class = new ReflectionClass($this);
$const = $class->getConstant('LOGCONST');
if ($const === false) {
throw new Exception(
pht(
'"%s" class "%s" must define a "%s" property.',
__CLASS__,
get_class($this),
'LOGCONST'));
}
$limit = self::getLogTypeConstantByteLimit();
if (!is_string($const) || (strlen($const) > $limit)) {
throw new Exception(
pht(
'"%s" class "%s" has an invalid "%s" property. Field constants '.
'must be strings and no more than %s bytes in length.',
__CLASS__,
get_class($this),
'LOGCONST',
new PhutilNumber($limit)));
}
return $const;
}
final private static function getLogTypeConstantByteLimit() {
return 64;
return $this->getPhobjectClassConstant('LOGCONST', 64);
}
final public static function getAllLogTypes() {

View file

@ -43,35 +43,7 @@ abstract class HarbormasterArtifact extends Phobject {
}
final public function getArtifactConstant() {
$class = new ReflectionClass($this);
$const = $class->getConstant('ARTIFACTCONST');
if ($const === false) {
throw new Exception(
pht(
'"%s" class "%s" must define a "%s" property.',
__CLASS__,
get_class($this),
'ARTIFACTCONST'));
}
$limit = self::getArtifactConstantByteLimit();
if (!is_string($const) || (strlen($const) > $limit)) {
throw new Exception(
pht(
'"%s" class "%s" has an invalid "%s" property. Action constants '.
'must be strings and no more than %s bytes in length.',
__CLASS__,
get_class($this),
'ARTIFACTCONST',
new PhutilNumber($limit)));
}
return $const;
}
final public static function getArtifactConstantByteLimit() {
return 32;
return $this->getPhobjectClassConstant('ARTIFACTCONST', 32);
}
final public static function getAllArtifactTypes() {

View file

@ -14,19 +14,7 @@ abstract class HarbormasterBuildStepGroup extends Phobject {
}
final public function getGroupKey() {
$class = new ReflectionClass($this);
$const = $class->getConstant('GROUPKEY');
if ($const === false) {
throw new Exception(
pht(
'"%s" class "%s" must define a "%s" property.',
__CLASS__,
get_class($this),
'GROUPKEY'));
}
return $const;
return $this->getPhobjectClassConstant('GROUPKEY');
}
final public static function getAllGroups() {

View file

@ -122,35 +122,7 @@ abstract class HeraldAction extends Phobject {
}
final public function getActionConstant() {
$class = new ReflectionClass($this);
$const = $class->getConstant('ACTIONCONST');
if ($const === false) {
throw new Exception(
pht(
'"%s" class "%s" must define a "%s" property.',
__CLASS__,
get_class($this),
'ACTIONCONST'));
}
$limit = self::getActionConstantByteLimit();
if (!is_string($const) || (strlen($const) > $limit)) {
throw new Exception(
pht(
'"%s" class "%s" has an invalid "%s" property. Action constants '.
'must be strings and no more than %s bytes in length.',
__CLASS__,
get_class($this),
'ACTIONCONST',
new PhutilNumber($limit)));
}
return $const;
}
final public static function getActionConstantByteLimit() {
return 64;
return $this->getPhobjectClassConstant('ACTIONCONST', 64);
}
final public static function getAllActions() {

View file

@ -3,19 +3,7 @@
abstract class HeraldActionGroup extends HeraldGroup {
final public function getGroupKey() {
$class = new ReflectionClass($this);
$const = $class->getConstant('ACTIONGROUPKEY');
if ($const === false) {
throw new Exception(
pht(
'"%s" class "%s" must define a "%s" property.',
__CLASS__,
get_class($this),
'ACTIONGROUPKEY'));
}
return $const;
return $this->getPhobjectClassConstant('ACTIONGROUPKEY');
}
final public static function getAllActionGroups() {

View file

@ -169,31 +169,9 @@ abstract class HeraldField extends Phobject {
}
final public function getFieldConstant() {
$class = new ReflectionClass($this);
$const = $class->getConstant('FIELDCONST');
if ($const === false) {
throw new Exception(
pht(
'"%s" class "%s" must define a "%s" property.',
__CLASS__,
get_class($this),
'FIELDCONST'));
}
$limit = self::getFieldConstantByteLimit();
if (!is_string($const) || (strlen($const) > $limit)) {
throw new Exception(
pht(
'"%s" class "%s" has an invalid "%s" property. Field constants '.
'must be strings and no more than %s bytes in length.',
__CLASS__,
get_class($this),
'FIELDCONST',
new PhutilNumber($limit)));
}
return $const;
return $this->getPhobjectClassConstant(
'FIELDCONST',
self::getFieldConstantByteLimit());
}
final public static function getFieldConstantByteLimit() {

View file

@ -3,19 +3,7 @@
abstract class HeraldFieldGroup extends HeraldGroup {
final public function getGroupKey() {
$class = new ReflectionClass($this);
$const = $class->getConstant('FIELDGROUPKEY');
if ($const === false) {
throw new Exception(
pht(
'"%s" class "%s" must define a "%s" property.',
__CLASS__,
get_class($this),
'FIELDGROUPKEY'));
}
return $const;
return $this->getPhobjectClassConstant('FIELDGROUPKEY');
}
final public static function getAllFieldGroups() {

View file

@ -3,17 +3,7 @@
abstract class PhabricatorPHIDType extends Phobject {
final public function getTypeConstant() {
$class = new ReflectionClass($this);
$const = $class->getConstant('TYPECONST');
if ($const === false) {
throw new Exception(
pht(
'%s class "%s" must define a %s property.',
__CLASS__,
get_class($this),
'TYPECONST'));
}
$const = $this->getPhobjectClassConstant('TYPECONST');
if (!is_string($const) || !preg_match('/^[A-Z]{4}$/', $const)) {
throw new Exception(

View file

@ -15,29 +15,7 @@ abstract class PhabricatorPolicyCapability extends Phobject {
* @return string Globally unique capability key.
*/
final public function getCapabilityKey() {
$class = new ReflectionClass($this);
$const = $class->getConstant('CAPABILITY');
if ($const === false) {
throw new Exception(
pht(
'%s class "%s" must define a %s property.',
__CLASS__,
get_class($this),
'CAPABILITY'));
}
if (!is_string($const)) {
throw new Exception(
pht(
'%s class "%s" has an invalid %s property. '.
'Capability constants must be a string.',
__CLASS__,
get_class($this),
'CAPABILITY'));
}
return $const;
return $this->getPhobjectClassConstant('CAPABILITY');
}

View file

@ -12,17 +12,7 @@
abstract class PhabricatorEdgeType extends Phobject {
final public function getEdgeConstant() {
$class = new ReflectionClass($this);
$const = $class->getConstant('EDGECONST');
if ($const === false) {
throw new Exception(
pht(
'%s class "%s" must define an %s property.',
__CLASS__,
get_class($this),
'EDGECONST'));
}
$const = $this->getPhobjectClassConstant('EDGECONST');
if (!is_int($const) || ($const <= 0)) {
throw new Exception(