PHP long ternary operator line and 120 char line long PSR rule

2.5k Views Asked by At

Is there a good way to format long ternary operator line ? Let's say :

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

This is too long according to 120 char per line defined in PSR. Should I do :

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

Or is there any other best practice?

1

There are 1 best solutions below

0
Yurii Hierasin On

No rules in PSR for that, but I am prefer this style, described in

$documentProcessingIndicatorId = $object->isProcessingDocument()
    ? $object->getDocumentProcessingIndicatorId()
    : null;