Seu code review não precisa discutir espaçamento
Seu code review não precisa discutir espaçamento
Your code review doesn’t need to discuss spacing
O pull request com 14 comentários (13 são sobre vírgula). Você abre o PR do colega. Quarenta arquivos alterados, uma feature importante. E os comentários são esses: “faltou linha em branco antes do return”, “acho que aqui cabia trailing comma”, “aspas simples, né? o resto do projeto usa simples”, “esse import não tá sendo usado”. Enquanto isso, no meio do diff, tem um método recebendo ?User e chamando $user->email sem checar null. Ninguém viu. Todo mundo estava ocupado contando espaço.
The pull request with 14 comments (13 are about commas). You open your colleague’s PR. Forty files changed, an important feature. And the comments are: “missing blank line before return,” “I think a trailing comma fits here,” “single quotes, right? the rest of the project uses single,” “this import isn’t being used.” Meanwhile, in the middle of the diff, there is a method receiving ?User and calling $user->email without checking for null. Nobody saw it. Everyone was busy counting spaces.
Esse é o custo real da falta de automação: não é o tempo gasto com detalhe, é a atenção que sobra pra revisar o que importa. E tem o lado humano. Ninguém gosta de receber cinco comentários sobre estilo. Cria atrito onde não precisa ter. Três ferramentas resolvem isso. Trinta minutos de setup.
This is the real cost of a lack of automation: it’s not the time spent on details, it’s the attention left over to review what actually matters. And there’s the human side. Nobody likes receiving five comments about style. It creates friction where there doesn’t need to be any. Three tools solve this. Thirty minutes of setup.
1. Pint — o fim da discussão sobre estilo
1. Pint — the end of style discussions
O Pint já vem instalado em projetos Laravel novos. Se o seu é antigo: composer require laravel/pint --dev. E roda: ./vendor/bin/pint. Pronto. Ele formata o projeto inteiro seguindo o padrão Laravel. Aspas, espaçamento, ordem de import, trailing comma — tudo resolvido sem ninguém opinar.
Pint comes pre-installed in new Laravel projects. If yours is old: composer require laravel/pint --dev. Then run: ./vendor/bin/pint. Done. It formats the entire project following the Laravel standard. Quotes, spacing, import order, trailing comma — everything solved without anyone having to give an opinion.
Se quiser ajustar alguma coisa, cria um pint.json na raiz:
If you want to adjust anything, create a pint.json at the root:
{
"preset": "laravel",
"rules": {
"declare_strict_types": true,
"ordered_imports": { "sort_algorithm": "alpha" }
}
}
Dois flags que valem ouro no dia a dia: Two flags that are worth gold in your day-to-day:
./vendor/bin/pint --dirty# só o que você mexeu (rápido) / only what you changed (fast)./vendor/bin/pint --test# não muda nada, só falha se estiver fora do padrão / doesn’t change anything, only fails if it’s off-standard
O --test é o que vai pro CI. Aviso importante: rode o Pint no projeto inteiro em um commit isolado, sozinho, antes de tudo. Se você misturar formatação com mudança de lógica, o diff fica ilegível e o git blame vira sopa.
The --test flag is what goes into CI. Important warning: run Pint on the entire project in an isolated commit, by itself, before anything else. If you mix formatting with logic changes, the diff becomes unreadable and the git blame becomes a mess.
2. Larastan — o bug que aparece antes do deploy
2. Larastan — the bug that appears before deployment
Aqui o jogo muda de nível. O Larastan (PHPStan com esteroides de Laravel) lê seu código sem executar e aponta erro de tipo, método que não existe, variável possivelmente nula.
composer require --dev "larastan/larastan:^3.0"
Here the game levels up. Larastan (PHPStan on Laravel steroids) reads your code without executing it and points out type errors, non-existent methods, and possibly null variables.
composer require --dev "larastan/larastan:^3.0"
Cria o phpstan.neon na raiz:
Create phpstan.neon at the root:
includes:
- vendor/larastan/larastan/extension.neon
parameters:
paths:
- app/
- routes/
level: 5
E roda: ./vendor/bin/phpstan analyse. Na primeira execução ele vai encontrar coisa. Muita coisa. Não entra em pânico e nem tenta corrigir tudo hoje. Comece no nível 0 ou 1. Sério. Zera os erros nesse nível, sobe pro próximo, zera de novo. Um nível por sprint é um ritmo saudável.
And run: ./vendor/bin/phpstan analyse. On the first run, it will find things. A lot of things. Don’t panic and don’t try to fix everything today. Start at level 0 or 1. Seriously. Clear the errors at that level, move to the next, clear them again. One level per sprint is a healthy pace.
Level 5 já pega a maioria dos problemas de verdade; do 6 pra cima começa a exigir docblock em tudo. E se o projeto for grande demais pra começar do zero, tem a saída elegante: ./vendor/bin/phpstan analyse --generate-baseline. Ele guarda todos os erros atuais num arquivo e passa a ignorá-los. A partir de agora, código novo não pode introduzir erro novo. A dívida técnica antiga fica lá, congelada, e você paga aos poucos.
Level 5 already catches most real problems; from 6 upwards, it starts requiring docblocks for everything. And if the project is too big to start from scratch, there is an elegant exit: ./vendor/bin/phpstan analyse --generate-baseline. It saves all current errors in a file and starts ignoring them. From now on, new code cannot introduce new errors. The old technical debt stays there, frozen, and you pay it off little by little.
3. Rector — refatoração automática
3. Rector — automatic refactoring
O Rector reescreve código pra você. É o que você usa quando sobe de versão do PHP ou do Laravel e não quer varrer 800 arquivos na mão.
composer require rector/rector --dev
Rector rewrites code for you. It’s what you use when you upgrade PHP or Laravel versions and don’t want to scan 800 files by hand.
composer require rector/rector --dev
O que ele faz sozinho: converte construtor antigo pra property promotion, troca array() por [], transforma if/else em operador ternário quando cabe, adiciona tipo de retorno, remove use não usado, atualiza chamadas descontinuadas do Laravel. Uma tarde de Rector num projeto legado economiza semanas. Só faz duas coisas: tenha testes e commit separado — igual ao Pint.
What it does on its own: converts old constructors to property promotion, swaps array() for [], transforms if/else into ternary operators when appropriate, adds return types, removes unused use statements, updates deprecated Laravel calls. An afternoon of Rector on a legacy project saves weeks. Just do two things: have tests and a separate commit — just like with Pint.
Colocando pra rodar sozinho
Setting it to run automatically
De nada adianta se depender de alguém lembrar. Dois lugares: It’s useless if it depends on someone remembering. Two places:
No CI: um job que não deixa passar. In CI: a job that doesn’t let it pass.
No pre-commit: pra você nem ver o erro chegar. In pre-commit: so you don’t even see the error arrive.
A pegadinha: ferramenta não substitui revisão
The catch: tools don’t replace review
Vale deixar claro, porque tem gente que liga tudo isso e acha que resolveu code review. Não resolveu. Pint, Larastan e Rector não sabem se o nome da sua classe faz sentido, se a regra de negócio está certa, se aquela query vai derrubar o banco com 100 mil registros ou se você acabou de criar uma falha de autorização. Eles só limpam o ruído pra que a revisão humana sobre pro que só humano faz. Que é justamente o que você quer.
It’s worth making clear, because some people turn all this on and think they’ve solved code review. They haven’t. Pint, Larastan, and Rector don’t know if your class name makes sense, if the business logic is correct, if that query will crash the database with 100,000 records, or if you’ve just created an authorization flaw. They only clear the noise so that human review is left for what only humans can do. Which is exactly what you want.
Bônus: um comando pra tudo
Bonus: one command for everything
Coloca no composer.json e a vida fica mais fácil:
Put this in your composer.json and life gets easier:
"scripts": {
"qa": [
"./vendor/bin/pint",
"./vendor/bin/phpstan analyse",
"php artisan test"
]
}
Agora é composer qa antes de abrir qualquer PR.
Now it’s composer qa before opening any PR.
Antes de você fechar a aba
Before you close the tab
O objetivo não é ter código perfeito. É parar de gastar energia humana com coisa que máquina resolve. Se você tiver tempo pra só uma hoje, instala o Pint. São dois comandos e o retorno é imediato — na próxima revisão, ninguém mais vai comentar sobre vírgula. Seu projeto já usa algum desses?
The goal isn’t to have perfect code. It’s to stop spending human energy on things a machine can solve. If you only have time for one today, install Pint. It’s two commands and the return is immediate — in the next review, no one will comment on commas anymore. Does your project already use any of these?