xref: /PHP-Parser/CONTRIBUTING.md (revision eb036d5a)
1## Coding Style
2
3This project uses PSR-12 with consistent brace placement. This means that the opening brace is
4always on the same line, even for class and method declarations.
5
6## Tools
7
8This project uses PHP-CS-Fixer and PHPStan. You can invoke them using `make`:
9
10```shell
11make php-cs-fixer
12make phpstan
13```
14
15## Adding support for new PHP syntax
16
171. If necessary, add emulation support for new tokens.
18   * Add a new subclass of `Lexer\TokenEmulator`. Take inspiration from existing classes.
19   * Add the new class to the array in `Lexer\Emulative`.
20   * Add tests for the emulation in `Lexer\EmulativeTest`. You'll want to modify
21     `provideTestReplaceKeywords()` for new reserved keywords and `provideTestLexNewFeatures()` for
22     other emulations.
232. Add any new node classes that are needed.
243. Add support for the new syntax in `grammar/php.y`. Regenerate the parser by running
25   `php grammar/rebuildParsers.php`. Use `--debug` if there are conflicts.
264. Add pretty-printing support by implementing a `pFooBar()` method in `PrettyPrinter\Standard`.
275. Add tests both in `test/code/parser` and `test/code/prettyPrinter`.
286. Add support for formatting-preserving pretty-printing. This is done by modifying the data tables
29   at the end of `PrettyPrinterAbstract`. Add a test in `test/code/formatPreservation`.
307. Does the new syntax feature namespaced names? If so, add support for name resolution in
31   `NodeVisitor\NameResolver`. Test it in `NodeVisitor\NameResolverTest`.
328. Does the new syntax require any changes to builders? Is so, make them :)
33