我在获取此函数的返回类型时遇到问题,因为我在开关中有混合类型。我用过混合的,它爆炸了。我使用了string|bool和几种类型的联合类型。
* @param $value
* @param string $type
public function __construct(string $type, $value)
{
$this->type = $type;
$this->value = $value;
}
我已经尝试了所有方法,但没有通过 CI/CD 管道 (AWS)
public function getValue(bool $typed = false)
{
if (false === $typed) {
return $this->value;
}
switch ($this->type) {
case 'boolean':
return (bool) $this->value;
case 'datetime':
if (empty($this->value)) {
return null;
}
return new \DateTime($this->value);
case 'option_tags':
return json_decode($this->value);
default:
return $this->value;
}
}
错误 以下是错误
Method App\Model\Resources::getValue() has no return typehint specified.
Parameter #1 $time of class DateTime constructor expects string, string|true given.
Parameter #1 $json of function json_decode expects string, bool|string given.