0

有没有一种格式化长三元运算符行的好方法?比方说:

$order = new Order($this->isProfessionalChildCollaborator($this->getUser()) ? $this->getUser()->getParent() : $this->getUser());

根据 PSR 中定义的每行 120 个字符,这太长了。我应该这样做:

$order = new Order(
    $this->isProfessionalChildCollaborator($this->getUser()) ?
    $this->getUser()->getParent() :
    $this->getUser()
);

还是有其他最佳实践?

4

1 回答 1

1

PSR 中对此没有任何规则,但我更喜欢 这种风格,描述于

$documentProcessingIndicatorId = $object->isProcessingDocument()
    ? $object->getDocumentProcessingIndicatorId()
    : null;
于 2020-05-20T08:56:16.493 回答