Changeset View
Changeset View
Standalone View
Standalone View
src/applications/fact/chart/PhabricatorChartFunctionArgument.php
<?php | <?php | ||||
final class PhabricatorChartFunctionArgument | final class PhabricatorChartFunctionArgument | ||||
extends Phobject { | extends Phobject { | ||||
private $name; | private $name; | ||||
private $type; | private $type; | ||||
private $isSourceFunction; | private $isSourceFunction; | ||||
private $functionType; | |||||
public function setName($name) { | public function setName($name) { | ||||
$this->name = $name; | $this->name = $name; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getName() { | public function getName() { | ||||
return $this->name; | return $this->name; | ||||
Show All 27 Lines | public function setIsSourceFunction($is_source_function) { | ||||
$this->isSourceFunction = $is_source_function; | $this->isSourceFunction = $is_source_function; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getIsSourceFunction() { | public function getIsSourceFunction() { | ||||
return $this->isSourceFunction; | return $this->isSourceFunction; | ||||
} | } | ||||
public function setFunctionType($function_type) { | |||||
$this->functionType = $function_type; | |||||
return $this; | |||||
} | |||||
public function getFunctionType() { | |||||
return $this->functionType; | |||||
} | |||||
public function newValue($value) { | public function newValue($value) { | ||||
switch ($this->getType()) { | switch ($this->getType()) { | ||||
case 'fact-key': | case 'fact-key': | ||||
if (!is_string($value)) { | if (!is_string($value)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Value for "fact-key" argument must be a string, got %s.', | 'Value for "fact-key" argument must be a string, got %s.', | ||||
phutil_describe_type($value))); | phutil_describe_type($value))); | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | switch ($this->getType()) { | ||||
if (!isset($functions[$function_name])) { | if (!isset($functions[$function_name])) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Function "%s" is unknown. Valid functions are: %s', | 'Function "%s" is unknown. Valid functions are: %s', | ||||
$function_name, | $function_name, | ||||
implode(', ', array_keys($functions)))); | implode(', ', array_keys($functions)))); | ||||
} | } | ||||
return id(clone $functions[$function_name]) | $function = id(clone $functions[$function_name]) | ||||
->setArguments($value); | ->setArguments($value); | ||||
switch ($this->getFunctionType()) { | |||||
case 'impulse': | |||||
if (!$function->isImpulseFunction()) { | |||||
throw new Exception( | |||||
pht( | |||||
'Function must be an impulse function, but "%s" is not '. | |||||
'an impulse function.', | |||||
$function_name)); | |||||
} | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
return $function; | |||||
case 'number': | case 'number': | ||||
if (!is_float($value) && !is_int($value)) { | if (!is_float($value) && !is_int($value)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Value for "number" argument must be an integer or double, '. | 'Value for "number" argument must be an integer or double, '. | ||||
'got %s.', | 'got %s.', | ||||
phutil_describe_type($value))); | phutil_describe_type($value))); | ||||
} | } | ||||
return $value; | return $value; | ||||
} | } | ||||
throw new PhutilMethodNotImplementedException(); | throw new PhutilMethodNotImplementedException(); | ||||
} | } | ||||
} | } |