kokororin / vscode-phpfmt

Integrates phpfmt into VS Code
https://marketplace.visualstudio.com/items?itemName=kokororin.vscode-phpfmt
BSD 3-Clause "New" or "Revised" License
129 stars 30 forks source link

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

Closed yinsee closed 2 months ago

yinsee commented 8 months ago
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 commented 8 months ago

similarly,


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

becomes

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

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

driade commented 8 months ago

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

Thanks.

yinsee commented 8 months ago

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,
driade commented 8 months ago

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.

d-enk commented 7 months ago

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
driade commented 7 months ago

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"

d-enk commented 7 months ago

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"

driade commented 7 months ago

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

driade commented 7 months ago

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

Thanks!

driade commented 7 months ago

@yinsee may you please close the issue? Thanks!

hellohasan commented 7 months ago

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

image

driade commented 7 months ago

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

hellohasan commented 7 months ago

hello @driade this is my settings: image

driade commented 7 months ago

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

hellohasan commented 7 months ago

@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,
driade commented 7 months ago

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

hellohasan commented 7 months ago

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

d-enk commented 7 months ago

@driade

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

<?php

function f()
{}

class C {}

f(function () {
});
driade commented 4 months ago

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

driade commented 4 months ago

@hellohasan did you finally got why it was failing?

driade commented 4 months ago

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