mago
mago copied to clipboard
[Formatter] Add a new line before the arrow (`=>`) of short anonymous functions
🚀 Describe the Feature
Hello!
This is probably personal, but I like to write anonymous functions like this and find it more readable :
$shortLine = static fn (string $arg, bool $arg2): string => $arg2 ? $arg : '';
$longLine = static fn (string $arg, bool $arg2): string
=> self::someVeryLongMethodLine($arg) ? 'Do something with ' . $arg : $arg2;
Currently, mago lets the arrow "=>" on the same line as the function definition, and sometimes even starts the body's code on that line before cutting it in weird places, example :
static fn (UserRepository $repository): QueryBuilder => $repository->createQueryBuilder(
'u',
)->orderBy('u.name', 'ASC'),
I would rather have :
static fn (UserRepository $repository): QueryBuilder
=> $repository->createQueryBuilder('u')->orderBy('u.name', 'ASC'),
or even :
```php
static fn (UserRepository $repository): QueryBuilder
=> $repository
->createQueryBuilder('u')
->orderBy('u.name', 'ASC'),
✅ Use Case / Example
I use a lot of functional patterns in my projects.
💡 Proposed Solution
Add a new rule empty-line-before-arrow-short-anonymous-function ?
📌 Priority
Not urgent, just an idea
📝 Additional Context
No response