Getting Started
Shift+Shift(⇧+⇧)
helps you find anything within your project.Alt+Enter(Option+Enter)
provides instant access to contextual actions and quick fixes relevant to the selected code.
Getting started with PHP in PhpStorm
还有个 One Dark theme
但是 Material Theme UI
已经包含这个主题。
配置:
Preferences > Appearance & Behavior > Appearance
下,右侧配置:Theme: Darcula
,勾选 User custom font: .AppleSystemUIFont
Size: 18
。
Preferences > Editor > Font
下,右侧配置:Font: Menlo
Size: 18
Line spacing: 1.2
。
Preferences > Editor > Color Scheme
下,右侧配置:Seheme: Atom One Dark(Material)
点击右侧的三个点 Duplicate
复制一份。
Preferences > Editor > Color Scheme > General
下,右侧配置:
- Editor > Gutter background,右侧
Background: 292929
(设置行号背景色) - Editor > Vertical Scrollar > Thumb 与 Thumb while scrolling,右侧
Background: 305599C0
(设置垂直滑块色) - Editor > Text > Default text,右侧
Background: 292929
(设置面板背景色)
快捷键
command + ,
打开设置command + shift + t
在代码和对应单元测试间用快速切换command + e
查看最近编辑文件列表shift + shift
搜索文件/类/操作/设置command + option + t
快速包裹 if/foreach/while 等控制结构command + option + +/-
快速展开/折叠
option + F12
呼出内置终端command + shift + a
“Quick Lists” 创建高频操作集合- Refactor
control + t
重构代码优化command + n
代码生成option + return
语法修复、代码优化等建议option + 鼠标选择
同时修改多处相同内容
- Git
command + k
Commit Changescommand + shift + k
Push Changescontrol + v
查看版本操作菜单
- Debug
command + F8
# 添加断点control + d
# 启动调试F8
# Step OverF7
# Step Intoshift + F8
# Step Out
技巧
围绕选择输入
设置选择了一个词后,再按单引号或双引号,将选中的单词用引号括起来。
Preferences
中搜索 Surround Selection on typing quote or brace
将其勾选(Editor > General > Smart Keys
下)。
关闭文档提示
鼠标放在方法上会出现文档提示,想关闭。
Preferences
中搜索 Show quick documentation on mouse move
取消勾选(Editor > Code Editing
下)。
使用 PHP-CS-Fixer
The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards.
工作环境:MacBook。
打开 PhpStorm Preferences > Tools > External Tools
添加:
- Program:
/usr/local/bin/php-cs-fixer
- Arguments:
--verbose fix "$FileDir$/$FileName$" --dry-run --rules=@PSR1,@PSR2,@Symfony
(Note that previous verions of PHP-CS-Fixer used –levels instead of –rules. 未找到) - Working directory:
$ProjectFileDir$
- 我取消勾选了
Open console for tool output
,可以不输出日志信息
为了方便使用,保存文件时就可以格式化,设置快捷键 Preferences > Keymap > Macros
:
设置 php-cs-fix 单独的快捷键 Preferences > Keymap > External Tools
:
关闭不常用的插件
Preferences > Plugins > Installed
向下滚动,Bundled
中有不少预装但不常用的可以禁掉。
遇到过的一些问题
文件类型错误
一个文件被新建后,明明扩展名没有错,但是却没有语法高亮,删除文件后也不解决问题。
解决办法:Editor > File Types
找 Text
将里面涉及的文件删除掉。
Undefined function XXX
出现 PHP 的原生方法未定义的警告。
解决方法:File > Invalidate Caches / Restart
Typo: In word XXX
提示单词拼写错误,但是其中没有问题,比如全拼的名字。
解决方法:option + enter -> Save to dictionary
warning: Multiple definitions exists for class
I resolved this by going to Preferences-> Languages & Frameworks-> PHP
; and then under Include path
, remove the conflicting path. (In my case a package reference in the vendor directory to a package I was developing inside my Laravel project)