kubawerlos / php-cs-fixer-custom-fixers

A set of custom fixers for PHP CS Fixer
MIT License
211 stars 19 forks source link

PromotedConstructorPropertyFixer suggestions #917

Open zanderwar opened 1 year ago

zanderwar commented 1 year ago

If the existing class property has a doc block, then the positioning of it when it gets moved to the __constructor is a little whack

Adding the following to the bottom of updateParameterSignature resulted in perfect positioning

foreach ($tokensToInsert as $key => $token) {
    if ($token->isGivenKind(\T_DOC_COMMENT)) {
        $tokensToInsert[$key] = new Token([\T_DOC_COMMENT, PHP_EOL.'    '.preg_replace('/^/m', '    ', $token->getContent())]);
    }
}

$this->tokensToInsert[$propertyStartIndex] = $tokensToInsert;

A few additional options would be nice:

Currently you only put 1 whitespace in front of the promoted property which doesn't follow standards I believe.

kubawerlos commented 12 months ago

Hi @zanderwar,

it seems like a good improvement, would you like to raise the PR? Do we need and option for keep_class_property_docblocks or should it always work as it is true?

Currently you only put 1 whitespace in front of the promoted property which doesn't follow standards I believe.

I don't understand, how is it breaking standards? It keeps the padding for what was before.

windaishi commented 10 months ago

I think the problem is that the current fixer works like this:

image

I'd like to either remove the docblock or convert it to @param ones.

I currently see no case on why we should keep the doc comment