Skip to content

Arrow function not tokenized correctly when using null in union type #3316

@simPod

Description

@simPod

Describe the bug

phpcs shoots:

PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket: Space before opening parenthesis of function call prohibited
Squiz.Arrays.ArrayDeclaration.IndexNoNewline: Each index in a multi-line array must be on a new line

when types are declared as union types. array|null triggers Squiz.Arrays.ArrayDeclaration.IndexNoNewline. ?array is fine.

Code sample

<?php declare(strict_types=1); return [ 'this is fine' => static fn (?DateTimeImmutable $value) : ?array => $value === null ? null : [], 'this shoots false positives' => static fn (DateTimeImmutable|null $value) : array|null => $value === null ? null : [], ];

Custom ruleset

doctrine/coding-standard v9

To reproduce

 9 | ERROR | [x] Space before opening parenthesis of function call prohibited | | (PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket) 9 | ERROR | [x] Each index in a multi-line array must be on a new line (Squiz.Arrays.ArrayDeclaration.IndexNoNewline) 

Expected behavior

No errors.

Versions (please complete the following information):

  • OS: [MacOS]
  • PHP: [8.0]
  • PHPCS: [master]
  • Standard: [Doctrine]

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