0

I use Sublime Text 3 and CodeFormatter plugin to auto format my PHP on save. Recently I updated to PHP 7.4 which introduces typed properties:

class Person {
  private string $name;
  private int $age;
}

Unfortunately CodeFormatter doesn't handle these and after saving converts the class to look like this:

class Person {
  stringprivate $name;
  intprivate $age;
}

Seems CodeFormatter relies on phpF which hasn't been updated in years (according to GitHub).

Thoughts (other than trying VS Code)?

Alan P.
  • 2,898
  • 6
  • 28
  • 52

1 Answers1

0
  • php-cs-fixer

    It's an external PHP tool which allows you to format a whole project with defined rules. But there is a plugin Phpcs to call it in ST.

  • LSP + LSP-intelephense (node.js required)

    I mention this just because it provides code formatting too. But I can't find a reason to use it for formatting (unless you don't have PHP installed on your machine but that's weird since you develop PHP) because php-cs-fixer is far more flexible. I use this setup for code completion, refactoring, ... but not code formatting.

I would say don't be bound in ST. If something can be achieved in command line, then it can be done in ST. So you may find external command line tools and write your own plugin to call them too. There are many useful command line tools and they won't be bound to a certain editor.

Jack Cherng
  • 23
  • 1
  • 6