Skip to content

PSR2.Methods.FunctionCallSignature false positive when arrow function has array return type #2773

Closed
@jasonmm

Description

@jasonmm

This might be related to #2523.

Using the file:

<?php

declare(strict_types=1);

print_r(array_map(
    fn(string $n): array => [1, bcadd($n, '3')],
    ['1', '2', '3']
));

Produces the error:

$ phpcs --standard=PSR12 -s ./test2.php

FILE: test2.php
-------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------
 6 | ERROR | [x] Only one argument is allowed per line in a multi-line function call
   |       |     (PSR2.Methods.FunctionCallSignature.MultipleArguments)
-------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------

Time: 54ms; Memory: 6MB

This seems specific to an arrow function that has an array return type with a multiple argument function call in the body of the arrow function. Using fn(string $n): string => bcadd($n, '3') or fn(string $n): array => [$n, 3] as the arrow function produces no error from phpcs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions