vscode-phpfmt icon indicating copy to clipboard operation
vscode-phpfmt copied to clipboard

adding "public" to closure and global functions causes syntax error

Open yinsee opened this issue 2 years ago • 21 comments

Route::get('{path}', function  () {
    return redirect()->route('home');
})->where('path', '.*');

gets formatted to

Route::get('{path}', public function  () {
    return redirect()->route('home');
})->where('path', '.*');

which causes syntax error.

yinsee avatar Nov 02 '23 07:11 yinsee

similarly,


function globaltest () {
    print ''. PHP_EOL;
}

becomes

public function globaltest () {
    print ''. PHP_EOL;
}

which also gives error when this is not a class method.

yinsee avatar Nov 02 '23 07:11 yinsee

Hi, good morning. I can't reproduce with my config. Can you please share yours so I can see the transformers applied?

Thanks.

driade avatar Nov 02 '23 07:11 driade

i am using phpfmt vscode extension v1.1.24

i only have this 2 turned on in settings

  "phpfmt.smart_linebreak_after_curly": true,
  "phpfmt.visibility_order": true,

yinsee avatar Nov 02 '23 08:11 yinsee

I'm sorry I can't reproduce it. I'd suggest to remove the extension and reinstall it again, so we can be sure you've the latest version.

driade avatar Nov 02 '23 10:11 driade

same problem v1.1.27 with default settings

php -v

PHP 8.2.12 (cli) (built: Oct 24 2023 19:22:16) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.12, Copyright (c), by Zend Technologies

d-enk avatar Nov 16 '23 13:11 d-enk

May you please execute "phpfmt > Open Output", then format the file, and paste here the command executed? Something like

19:37:51.777 [INFO] Executing command: php "/Users/davidfernandez/.vscode/extensions/kokororin.vscode-phpfmt-1.1.24/node_modules/phpfmt/v2/fmt.stub.php" --indent_with_space=4 --visibility_order --smart_linebreak_after_curly "/var/folders/24/xvl5njxx7m1g94hsg7436knw0000gn/T/temp-qqfrym-a.php"

driade avatar Nov 16 '23 18:11 driade

Its reproduced when file include class


<?php

namespace Test;

function F()
{
}

class A
{
}

Executing command: php "/home/d-enk/.vscode/extensions/kokororin.vscode-phpfmt-1.1.27/node_modules/phpfmt/v2/fmt.stub.php" --psr2 --indent_with_space=4 --exclude=DoubleToSingleQuote,OrderAndRemoveUseClauses "/tmp/temp-haezevt-test.php"

d-enk avatar Nov 17 '23 08:11 d-enk

Thanks @d-enk I've been able to reproduce the bug with your latest example.

driade avatar Nov 18 '23 08:11 driade

Hello again, this should be already fixed. Please update to the latest version and kindly tell me if you find it fixed.

Thanks!

driade avatar Nov 18 '23 08:11 driade

@yinsee may you please close the issue? Thanks!

driade avatar Nov 20 '23 18:11 driade

hello @driade It's not fixed yet. I am useing php 8.1 and phpfmt is latest v1.1.34

image

hellohasan avatar Dec 02 '23 12:12 hellohasan

@hellohasan sorry I can't reproduce the issue. Would you please share your config? Thanks.

driade avatar Dec 02 '23 15:12 driade

hello @driade this is my settings: image

hellohasan avatar Dec 02 '23 17:12 hellohasan

@hellohasan thanks, would that be possible for you to paste it in text format?

driade avatar Dec 02 '23 17:12 driade

@driade


"phpfmt.passes": [
      "AlignDoubleArrow",
      "AlignDoubleSlashComments",
      "ShortArray",
      "MergeElseIf",
      "SpaceBetweenMethods",
      "AutoSemicolon",
      "GeneratePHPDoc",
      "IndentTernaryConditions",
      "ReplaceBooleanAndOr",
      "ReindentSwitchBlocks",
      "NewLineBeforeReturn",
      "OrderAndRemoveUseClauses",
      "SortUseNameSpace",
      "RemoveUseLeadingSlash"
  ],
  "phpfmt.exclude": [
      "AllmanStyleBraces",
      "StripNewlineWithinClassBody",
      "NewLineBeforeReturn"
  ],
  "phpfmt.psr2": true,

hellohasan avatar Dec 02 '23 17:12 hellohasan

Thank you. I'm sorry, I'm unable to reproduce, here you've a video. May I suggest removing and installing the extension?

https://github.com/kokororin/vscode-phpfmt/assets/5692232/9717aabb-f921-4d50-8a3f-db700348147c

driade avatar Dec 02 '23 17:12 driade

@yinsee Hello sir, How did you fix your issue, I am also facing the same type of issue in laravel route.php file

hellohasan avatar Dec 02 '23 17:12 hellohasan

@driade

As in my previous reproducer, add class C {} to file

<?php

function f()
{}

class C {}

f(function () {
});

d-enk avatar Dec 02 '23 21:12 d-enk

Thank you @d-enk this should be already fixed in the latest release. May you please confirm?

driade avatar Mar 08 '24 21:03 driade

@hellohasan did you finally got why it was failing?

driade avatar Mar 08 '24 21:03 driade

Hi again @hellohasan I was able to reproduce the error. It should now be fixed in the latest release. May you please confirm?

driade avatar Mar 08 '24 21:03 driade