I have a somewhat complex but very helpful feature idea: a way to configure the PHP formatter to do advanced organization based on a configuration that can also organize blocks. This is really a dream of mine for the formatter. I appreciate any work that may go into implementing it!
Use declarations, classes, class variables, functions, etc. could be formatted based on a configuration.
Example for use declarations:
{
"php.format.organizeUsings": {
"enabled": false, // Allows this to be turned off so organizeUsings can remain on for other languages like JS
"removeUnused": true // Remove unused use declarations
// Orders by namespace with individual configuration
"order": {
"Doctrine": "ascending",
"php": "ascending",
// Default for any remaining namespaces
"default": "ascending",
},
// Would place newline between groups in "order"
"newlineBetweenGroups": true
},
}
If enabled and document formatted:
use Doctrine\ORM{
EntityRepository,
Query
};
use DateTime;
use Exception;
Example for other blocks:
{
"php.format.organizeBlocks": {
"enabled": true,
"baseOrder": {
"abstract class": "ascending",
"class": "ascending",
"trait": "ascending",
},
// Order of groups of blocks by accessor
"memberOrder": {
// Accessor/keyword
"default": {
// Types: order
"object": "ascending",
"array": "ascending",
"scalar": "ascending",
// Default for any remaining types
"default": "ascending",
},
"private": {
// inherits default
},
"abstract": {
// inherits default
}
},
},
}
If enabled and document formatted:
abstract class MyAbstractClass
{
myObj = { };
private myArray = [];
private myFunc() { }
abstract myAbstractFunc();
}
class MyClass { }
class MySecondClass { }
trait MyTrait { }