vscode-phpfmt: Constant arrays on classes causes all keywords before `function` to be removed

If you have a class with a constant on it that is an array, static functions will get re-written to not be static (also, the public keyword gets removed). E.g:

this

<?php

class Bug {
    const BROKEN = array();

    public static function test() {

    }
}

Will get re-written into this:

<?php

class Bug {
    const BROKEN = array();

    function test() {

    }
}

It seems to remove all keywords before the function keyword:

<?php

class Bug {
    const BROKEN = array();

    private function test() {

    }
}

Will get re-written into this:

<?php

class Bug {
    const BROKEN = array();

    function test() {

    }
}

However, this works:

<?php

const WORKS = array();

class Bug {

    public static function test() {

    }
}

These are the settings I’m using:

{
    "phpfmt.exclude": [
        "PSR2CurlyOpenNextLine",
    ],
    "phpfmt.passes": [
        "AlignDoubleArrow"
    ],
    "phpfmt.psr2": true
}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 6
  • Comments: 19 (1 by maintainers)

Most upvoted comments

Yes! it works 😃 Thank you very much

I too found this bug the hard way. However quick test indicates this is enough to disable it:

{
    "phpfmt.exclude": [
        "PSR2ModifierVisibilityStaticOrder"
    ]
}