PSR-2 - 数组左括号是否应该在其自己的行上

PSR-2 - Should the array opening bracket be on its own line

如果我们符合 PSR-2 标准,则脱离他们对多行参数的描述:

Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line.

When the argument list is split across multiple lines, the closing parenthesis and opening brace MUST be placed together on their own line with one space between them.

这是否意味着参数的格式应如下所示:

return JsonResponse(
    Request::STATUS_OK, 
    [
        'success' => true,
        'message' => 'Example Message Here.'
    ]
)

或者在严格遵循他们的标准的情况下,以下格式是否也有效?

return JsonResponse(
    Request::STATUS_OK, [
        'success' => true,
        'message' => 'Example Message Here.'
    ]
)

如果你看一下 The PSR-2 Meta Document 它有一个关于多行参数的部分,特别是指数组和闭包:

Using one or more multi-line arguments (i.e: arrays or anonymous functions) does not constitute splitting the argument list itself, therefore Section 4.6 is not automatically enforced. Arrays and anonymous functions are able to span multiple lines.

因此,在您的情况下,即使是以下内容也是完全有效的,包括您的第一个示例完全遵循规范。

return JsonResponse(Request::STATUS_OK, [
    'success' => true,
    'message' => 'Example Message Here.'
]);

在这个层面上,它可能只是归结为个人喜好。