prettier / prettier/plugin-php
Null coalesce operator getting too verbose sometimes
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- PHP
- Stars
- 1.9k
- Forks
- 139
- PR merge metrics
- No merged PRs in 30d
Description
- @prettier/plugin-php@0.14.1
- prettier@2.0.5
Options
### General
trailingComma: all
printWidth: 80
tabWidth: 4
useTabs: false
singleQuote: true
requirePragma: false
insertPragma: false
### JavaScript
semi: false
### VueJS
vueIndentScriptAndStyle: true
### PHP
phpVersion: "7.4"
trailingCommaPHP: true
braceStyle: psr-2
Input:
return $data['template_name'] ?? $data['templateName'] ?? $this->templateName ?? $this->template_name ?? null;
Output:
return $data['template_name'] ??
($data['templateName'] ??
($this->templateName ?? ($this->template_name ?? null)));
Expected behavior:
return $data['template_name']
?? $data['templateName']
?? $this->templateName
?? $this->template_name
?? null;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are named. Reproduce the issue with the provided PHP input, Prettier 2.0.5, and @prettier/plugin-php 0.14.1, then locate the PHP formatting logic and existing tests for chained null-coalescing expressions. Done means the expression formats with one operator per line without the nested parentheses shown in the current output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100