Uniformly use phpstorm's default formatting.
Press Shift+Alt+L
to auto-format your code.
Best practices examples from INF - By Amir
Dependency injection:
First, make sure your project in phpstorm is in the correct php version.
You can check it in the lower right corner of phpstorm window like PHP: 8.1
By default, it will set as 8.1
because we defined it in composer.json
So, we need to click and change it to 8.2
because we use php8.2 in inf2 server.
The default profile of inspections is not suitable for laravel.
So I created a profile for our project. I also pushed it to inf2 dev branch.
Everyone should import and use it to make sure we are in the same code standard.
- go to
Settings -> Editor -> Inspections
- click the gear icon and select
Import
- choose
INF2 Standard
- click
OK
Click the warning icon in the upper right corner of the editor,
then the results will show in the Problems
window.
We can also find these errors in the scroll bar on the right side of the editor.
Alt+6
to openProblems
window.- choose
Project Errors
tab and clickInspect Code
- choose
Custom scopo
and click...
- add a local scope and include these directories recursively:
- app
- config
- routes
- choose
INF2 Standard
forInspection profile
- click
Analyze
, then we can see the results.
It will be reported as a green wavy line.
We should fix it if it's a misspelling.
If you want to keep the word:
- press
Alt+Enter
on this word. - select
Save 'xxx' to dictionary
andEnter
Most of the problems can be fixed automatically with phpstorm.
Just press Alt+Enter
on the code warned
We need to fix all the issues except Typo and misspellings
, or disable the inspection in specific place.
There will always be warnings that we can't fix or that are hard to fix, and we don't want to update everyone's profiles to disable it.
Then we can disable it one-place-only:
- press
Alt+Enter
on the code warned - press
โ
to find options likeSuppress for file/method/statement
, andEnter