Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpcbf deletes return type declaration of function #1202

Closed
Flimm opened this issue Oct 18, 2017 · 1 comment · Fixed by #1319
Closed

phpcbf deletes return type declaration of function #1202

Flimm opened this issue Oct 18, 2017 · 1 comment · Fixed by #1319

Comments

@Flimm
Copy link

Flimm commented Oct 18, 2017

I have a file, hello.php, with the following contents:

<?php

function hi(): array
{
    return [];
}

If I run phpcs against it, I got notified that it is violating WordPress.WhiteSpace.ControlStructureSpacing.OpenBraceNotSameLine:

$ vendor/bin/phpcs -s hello.php
FILE: hello.php
-------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------------------------
 3 | ERROR | [x] Opening brace should be on the same line as the declaration (WordPress.WhiteSpace.ControlStructureSpacing.OpenBraceNotSameLine)
-------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------------------

So far so good. If I run phpcbf, it corrects it badly:

$ vendor/bin/phpcbf hello.php

PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE                                                  FIXED  REMAINING
----------------------------------------------------------------------
hello.php                                             1      0
----------------------------------------------------------------------
A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE
----------------------------------------------------------------------

The result is:

<?php

function hi() {
    return [];
}

As you can see, phpcbf has corrected the issue with the opening curly brace, but it has deleted the declared return type of the function hi. It should still have : array before the opening curly brace.

Here are my version numbers:

  • PHPCS: 3.1.0
  • WPCS: 0.13.1
  • PHP: 7.1.8
@jrfnl
Copy link
Member

jrfnl commented Oct 21, 2017

Related to #1101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants