Php-cs-fixer: [Meta] PHP 7 features

Created on 31 Mar 2015  Â·  18Comments  Â·  Source: FriendsOfPHP/PHP-CS-Fixer

We should add test cases to relevant fixers for those new features:

  • [x] new operators (coalesce, spaceship) #1064
  • [x] [Return Type Declarations](https://wiki.php.net/rfc/return_types)
  • [x] [Anonymous Class Support](https://wiki.php.net/rfc/anonymous_classes): #1806, #1881, #1894, #1989, ...
  • [x] [Group Use Declarations](https://wiki.php.net/rfc/group_use_declarations): ordered_use, unused_use etc.., and maybe we should add a new transformer for the braces (I'm not sure); #1989, #2235
  • [ ] [Uniform Variable Syntax](https://wiki.php.net/rfc/uniform_variable_syntax): there are some new token sequences which may break some fixers
  • [x] [Scalar Type Hints](https://wiki.php.net/rfc/scalar_type_hints_v5): I guess they are unproblematic because they are not so different to existing type hints
  • [x] Semi-reserved keywords #1970

7.1 extracted: https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/2090

All 18 comments

Nice list !

(PHP 7.1)
iterable

The new_with_braces fixer is also broken with anonymous classes.

could you send a fix for it @GrahamCampbell ?

The new_with_braces fixer is also broken with anonymous classes.

addressed in https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/1989

<?php
function arraysSum(array ...$arrays): INT
{
}

Is valid on PHP7 but HHVM cannot handle it (https://3v4l.org/7VTKn).

------ old idea below, now no longer considered -------------

The INT return type hint casing is not fixed atm by the fixer because it parsed as T_STRING.
I would like to suggest to create a transformer for;

  • T_STRING used as return hint
  • content int, float, bool, string, true, false, null (http://php.net/manual/en/reserved.other-reserved-words.php)
  • transform to CT_RETURN_TYPE
  • add it to Token::getKeywords (https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/1.11/Symfony/CS/Tokenizer/Token.php#L259)

like to hear what people think!

we already have a transformer for dealing with array as array language construction or typehinting

:+1: for CT for return typehints

@SpacePossum in this case function foo(Bar $b, int $c) : string {}
all Bar, int and string are strings. as they are consistent I'm not sure should we really change them

On second thought I think we can indeed do without those

To me it looks like most issues with PHP7 support are solved now. Are there any plans to release a new version? Is there anything critical open? If yes: Is there any way to help?

At least 3 things are to be done, one of them is this Meta ticket, then Meta for 7.1 if possible.
Could you help with it please ?

Group Use Declarations: ordered_use, unused_use etc.., and maybe we should add a new transformer for the braces (I'm not sure); #1989

Seems to be fixed (at least the issue is closed).

Anonymous Class Support: #1806, #1881, #1894, #1989, ...

These all seem to be merged/closed too.

Uniform Variable Syntax: there are some new token sequences which may break some fixers

I'm in a bit of a loss of what needs to be done here.

In regards to PHP 7.1: IMHO it would be great to have a running version for PHP 7.0 first. One thing at a time.

In regards to PHP 7.1: IMHO it would be great to have a running version for PHP 7.0 first. One thing at a time.

I don't think it matters which parts get implemented first. Call it all 7.x.

@pascal-hofmann , the PRs you refer to are the PRs that claim to fix the change introduced by language.
so a list of changes is a TODO list, not a list of PRs. like a issue and list of PRs that fixes it.

Eg for Anonymous Class Support we figure out 4 fixers that has to be fixed and they were fixed, but we still need to check other fixers and maybe update them as well, in the end extending integration test for 7.0 (https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/tests/Fixtures/Integration/misc/PHP7.test)
maybe it's enough to add it to integration test and all fixers for that syntax are adjusted, maybe no, needs to be checked.

Also, I agree it's nice to have 7.0 done first, but if one want to work on something from 7.1 it's also great, so @GrahamCampbell , contribute ;)

so @GrahamCampbell , contribute ;)

Haha, yeh. As soon as I have a free moment, I will. Got so much on right now.

I had a look into the ordered_use fixer and Group use declarations. It definitely needs some work. I added two test cases. See #2234.

For Group use declarations the multiple_use fixer could be adjusted as well to make it single use imports.

I think this one is resolved on 2.0 line. Closing for that.
Thank you all for hard work !

Uniform Variable Syntax is not touched by us, I'm not sure how to deal with it. I don't think we support that that syntax already in some special case. And in the end, the syntax after all is the same, just with different meaning.

Please, help with solving #2090 ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bilge picture Bilge  Â·  3Comments

vitek-rostislav picture vitek-rostislav  Â·  3Comments

kcloze picture kcloze  Â·  3Comments

datenmeister picture datenmeister  Â·  3Comments

amitbisht511 picture amitbisht511  Â·  3Comments