phpstan / phpdoc-parser

Next-gen phpDoc parser with support for intersection types and generics
MIT License
1.31k stars 62 forks source link

Allowing whitespace between `array` and its "shape" #201

Closed rhertogh closed 1 year ago

rhertogh commented 1 year ago

Hi, I would like to propose to allow whitespaces between array, object and list and the opening brace for its "shape". E.g.:

<?php

/**
 * @return array { // <- space before opening brace
 *     int,
 *     array { // <- space before opening brace
 *         string,
 *     }
 * }
 */
function test() {
    return [1, ['test']];
}

It would behave more closely to https://www.php-fig.org/psr/psr-12/ where there is (almost) always a space before the {.

Above code sample works in Psalm: https://psalm.dev/r/c9ff4aa0f0

But does not work in PHPStan: https://phpstan.org/r/7f034238-2d9a-4e58-a7b7-ea850c9e6b1b

ondrejmirtes commented 1 year ago

Hi, I disagree with this, for two reasons:

1) It's been years since we introduced this syntax and it's been fine, no one asked for this. You can just type array{ without the space and it works. 2) It would be a BC break. Meaning what currently gets accepted as a description would suddenly cause a parse error.

rhertogh commented 1 year ago

@ondrejmirtes And if we only allow it if it's directly followed by a new line? I don't think that would brake backwards compatibility would it? The reason to implement it is that in my opinion people are used to the PSR format of a leading space before the opening brace and write it as such (which currently won't work).

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.