hoaproject / Devtools

The Hoa\Devtools library.
https://hoa-project.net/
6 stars 6 forks source link

php-cs-fixer #11

Closed Hywan closed 9 years ago

Hywan commented 9 years ago

This PR introduces:

I let you take a look at the API documentation explaining the fixers.

Fix https://github.com/hoaproject/Websocket/pull/25. Fix https://github.com/hoaproject/Central/issues/13.

Hywan commented 9 years ago

We must define how block works. Here is my proposal:

{
    a single statement;
}

{

    more;
    than;
    one;
    statement;

}

No newline after and before { and } if we have a single statement. Newlines if we have more than one statement. Concrete example:

if (true === $foo) {
    doSomething();
} else {

    $a++;
    $b = str_replace(…, …, …);

}

Now, how to treat the special case of the return statement? Does it count as a statement? The rule is: If we have 0 or 1 statement and a return, we do not add any newline. If we have more than 1 statement and a return, we add newline and an empty line before the return. Like this:

{

    a single statement;
    return;

}

{

    a statement;
    another statement;

    return;

}

Thoughts?

Update: break, continue and exit have the same rule as return.

Hywan commented 9 years ago

/cc @hoaproject/hoackers

Hywan commented 9 years ago

Example of a PR: https://github.com/hoaproject/Websocket/pull/34. Need to retouch manually for the block and return family. Everything else is pretty much perfect (sometimes we have to fix some stuff manually, nothing horrible).

Metalaka commented 9 years ago

Looks good but I think you inverted the @throws tag name normalization, according to phpdoc.org and php-cs-fixer:phpdoc_params [symfony] @throw doesn't exist.

Hywan commented 9 years ago

@Metalaka ;-) :+1:

Hywan commented 9 years ago

What about newlines in blocks? I am still not sure what to do…

Hywan commented 9 years ago

I propose to not add newlines with the block contains one or more statements.

Hywan commented 9 years ago

Done. PR is ready to be applied. I would like all @hoaproject/hoackers to review this result: https://github.com/hoaproject/Websocket/pull/34/files please :-). Report everything on this link, no this page.

Thanks!