2

I have been receiving a PHP Code Sniffer error relating to line 7 in the code below.

Moving the next square open bracket to this line seems to introduce new errors. I'm a little unclear as to how to resolve this.

Opening parenthesis of a multi-line function call must be the last content

if ($cms_user) {
    array_push($buttons, [
        'id' => 5,
        'name' => 'Home Page'
    ]);
} elseif ($public) {
    array_push($buttons,
        [
            'id' => 3,
            'name' => 'About Us'
        ],
        [
            'id' => 11,
            'name' => 'Reflection',
        ],
        [
            'id' => 2,
            'name' => 'Contact Us',
        ]
    );
}
Suba
  • 199
  • 1
  • 2
  • 11
  • 2
    Does this answer your question? [Opening parenthesis of a multi-line function call must be the last content on the line](https://stackoverflow.com/questions/22131095/opening-parenthesis-of-a-multi-line-function-call-must-be-the-last-content-on-th) – pedrochaves Nov 25 '19 at 16:10
  • I'm afraid not, I already referenced that page. – Suba Nov 25 '19 at 16:20

1 Answers1

3

Opening parenthesis of a multi-line function call must be the last content

If you have a function that spans more than one line, then the opening paren of the function call must be the last thing on the first line. I usually do something like this:

array_push(
    $buttons,
    [
        'id' => 5,
        'name' => 'Home Page'
    ]
);
Alex Howansky
  • 50,515
  • 8
  • 78
  • 98