Php-cs-fixer: phpdoc_to_comment bug?

Created on 28 Jan 2016  Â·  31Comments  Â·  Source: FriendsOfPHP/PHP-CS-Fixer

using 2.x

/**
 * @var Foo
 */
$foo = createFoo();

should this really be treated as not phpdocblock ?

kinbug

All 31 comments

In these sorts of cases, I think we should actually delete the entire thing rather than converting it to a normal comment.

Why you should consider it as invalid docblock then ?
It gives one great typehinting information.

@keradus I have a similar issue .. I think this can be a bug.

test n°1

source:
screen shot 2016-06-10 at 10 34 03

corrected into:
screen shot 2016-06-10 at 10 34 32

test n°2

source:
screen shot 2016-06-10 at 10 37 13

corrected into:
screen shot 2016-06-10 at 10 37 34

Every time only the first one is treated as a DocBlock

Not a bug.

OK, I trust your answer ... but can you explain why? ... thanks

Because phpdoc must follow a structural block. That is not valid. You should use class constants if you want doc.

and the first one is not touched as it's recognized as file-level doc, right ?

and the first one is not touched as it's recognized as file-level doc, right ?

Ish. Our file level stuff is broken too anyway.

So, what about this doc about procedural elements ? .. I'm confused

So, what about this doc about procedural elements ? .. I'm confused

thats on phpdoc and prop. not on PSR5 (which is kind of followed here), I like phpdoc better in this case btw.

phpdoc.org is not widely used. See PSR-5.

So, as per PSR-5 the right way to document a define should be

/** This is the FOO description. */
define('FOO', 'Foo value');

right? .. but the behavior is the same

So, as per PSR-5 the right way to document a define should be

No? It says you can't put doc on those.

I'm starting to feel stupid :(

screen shot 2016-06-10 at 16 50 04

constant:

class Foo
{
    const BAR = 1;
}

it's not the same like define("foo", "bar") in global level

That's not a constant. This is a constant:

<?php

class Foo
{
    /**
     * Valid PHPDoc.
     *
     * @var string
     */
    const STUFF = 'FOO';
}

@keradus We posted at the same time. :)

;)

@GrahamCampbell
BTW, any answer for https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/1715#issuecomment-177475696 ?

It gives one great typehinting information.

Well, no, not really. The type can already be infered. It's a constant, so cannot change.

https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/1715#issue-129483212

there is no constant here ...

Meh, well, I didn't write that fixer. I don't disagree that's not useful.

On the very beginning you said to remove whole comment ...

ok got the point .. sorry and thanks for the patience.

What I think is buggy is the fact that the first define is not touched .. I already have a file-level docblock at the beginning of the file .. so what is the difference from the 1st define and the next one?

@GrahamCampbell eeh you are a !!guy ("I don't disagree that's not useful") .. just joking ;)

!!guy

we have fixer for that case; (bool) guy

back to topic, I think both the case from @keradus and all of those from the screenshots of @drAlberT are correct. Someone should tweak the fixers

On the very beginning you said to remove whole comment ...

Meh. Maybe you convinced me. ;P

It seems @drAlberT comments about define are confusing the matter, the reason the bug is was open, removing docblock from variables, is a bug.

There are not removed, but changed to a comment. You can switch off the phpdoc_to_comment fixer and it should be fine.

The case is why

/**
 * @var Foo
 */
$foo = createFoo();

is considered as invalid phpdoc...

Why is that invalid?

It seems this test https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/1.12/Symfony/CS/Tests/Fixer/Symfony/PhpdocToCommentFixerTest.php#L180 checks for this

This was converted to a comment to me

/**
 * @var Composer\Autoload\ClassLoader $loader
 */
$loader = require_once __DIR__.'/../app/autoload.php';

using v1.12.1

/**
 * @var Composer\Autoload\ClassLoader $loader
 */
$loader = require_once __DIR__.'/../app/autoload.php';

is not modified by PhpdocToCommetFixer
but this would:

/**
 * @var Composer\Autoload\ClassLoader
 */
$loader = require_once __DIR__.'/../app/autoload.php';

Then, it's the same case as my initial.

Yes, I double check, it was edited the first time I ran fixer by phpdoc_var_without_name, which removed $loader and the second time by phpdoc_to_comment

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carusogabriel picture carusogabriel  Â·  3Comments

kcloze picture kcloze  Â·  3Comments

grachevko picture grachevko  Â·  3Comments

UksusoFF picture UksusoFF  Â·  3Comments

Bilge picture Bilge  Â·  3Comments