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dQUFK8xqhiZaYPd30TlmCmSAaGJ0eBpvkVeqA2jGYhAQRqFiAlFC63JKvWvRZO1iRuWCEfUMkdqQ9VQPXziE/BlsOIgrL6RlJfuFcEZ8TK3syIfIGQZNCxYhLLUuet2HE6LJYPQ5c0jH4kDooRpcVZ4rBxNwddpctUO2te9UU5/FjhioZQsPvd92qOTsV+8Cyl2fvNhNKD1Uu9ff5AkVIQn4JU23ozdB/R5oUlebwaTE6WZNBs+TA/qPj+5/we9NH71WRB0hqUoLI2AKKyiPw++FtN4Su1vsdDlrAzDj9ILjpjJKA1ImuVcG329/WTYIKysZ1CWK3zATg9BeCUPAV1pQy8ToXOq+RSYen6winZ2OO93eyHv2Iw5kbn1dqfBw1BuTE29V2FJKicJSu8iEOpfoafwJISXmz1wnnWL3V/0NxTulfWsXugOoLfv0ZIBP1xH9kmf22jjQ2JiHhQZP7ZDsreRrOeIQ/c4yR8IQvMLfC0WKQqrHu5ZzXTH4NO3CwGWSlTY74kE91zXB5mwWAx1jig+UXYc2w4RkVhy0//lOmVya/PEepuuTTI4+UJwC7qbVlh5zfhj8oTNUXgN0AOc+Q0/WFPl1aw5VV/VrO8FCoB15lFVlpKaQ1Yh+DVU8ke+rt9Th0BCHXe0uZOEmH0nOnH/0onD
 
☀ 必装插件
Php Inspections ​(EA Extended)​ // 代码审查分析插件,可帮助开发者找出有性能问题和安全问题的代码并提出优化建议
Chinese PHP Document // 内置函数中文文档
CodeGlance Pro // 在编辑区右侧显示代码迷你地图
PHP Toolbox // 代码自动补全、语法检查等功能
PHP Annotations // 注解工具
SonarLint // 代码质量检测
Rainbow Brackets // 彩虹括号
Baidu Comate // 智能代码助手
 
☀ 开启代码检查,如检查undefined、unused等
Editor > Inspection
 
☀ 屏蔽属性名/变量名过长或过短警告,有时候我们就是要使用类似$age的短单词
File > Settings > Editor > Inspections > PHP > Naming conventions > 修改Property name和Variable name的Min length和Max length即可
 
☀ 自动生成函数或方法的注释
在函数名或方法名的上一行输入“/**”然后回车就可以自动生成注释,修改注释模板教程可看《PhpStorm修改自动生成注释默认模板》。
 
☀ 全局查找和全局替换
项目根目录右键,弹出菜单里的“Find in Path”和“Replace in Path”分别是全局查找和全局替换

☀ 将无关目录排除在项目管理之外,例如:Hyperf项目的runtime目录
目录右键 > Mark Directory as > Excluded

☀ 快捷键方案
File > Settings > Keymap
单行注释:搜索“Comment with Line Comment”,设为F1,重复一次可取消
多行注释:搜索“Comment with Block Comment”,设为F2,重复一次可取消
跳转到定义处:搜索“Declaration”,设为F3,支持跳转到变量、函数、方法、类的定义处
格式化代码:搜索“Reformat Code”,设为F4
展开代码块:搜索“Expand”,设为F5
折叠代码块:搜索“Collapse”,设为F6
展开全部代码:搜索“Expand All”,设为F7
折叠全部代码:搜索“Collapse All”,设为F8
删除光标所在行:搜索“Delete Line”,设为F9
复制光标所在行:搜索“Duplicate Line or Selection”,设为F10
大小写转换:搜索“Toggle Case”,设为F12
文档内搜索:搜索“Find”,设为Ctrl+F
文档内替换:搜索“Replace”,设为Ctrl+R
项目全局搜索:搜索“Find in Path”,设为Ctrl+Shift+F
项目全局替换:搜索“Replace in Path”,设为Ctrl+Shift+R

☀ 单行注释缩进并加空格
File > Settings > Editor > Code Style > PHP > Code Generation > Comment Code
取消:Line comment at first column # 缩进
勾选:Add a space at comment start # 加空格

☀ 修改PHP版本
File > Settings > Languages & Frameworks > PHP > 选择PHP Language level即可

☀ 导入/导出设置(重装PhpStorm就不需要再重新设置一遍快捷键和实时模板了)
File > Import Settings # 导入设置
File > Export Settings # 导出设置,文件保存为:/PhpStorm/bin/PhpStormConfig/config/settings.zip

☀ 快捷录入当前日期时间
该功能依赖实时模板(Live Templates),具体可看《PhpStorm实时模板(Live Templates)的使用》。
 
☀ 跨脚本使用已定义变量提示“Undefined variable”(在A脚本定义变量$var,B脚本包含A脚本并使用变量$var)
File > Settings > Editor > Inspections > PHP > Undefined symbols > Undefined variable > Options
☑ Report that variable is probably undefined
☑ Enable inspection in global space
☑ Search for variable's definition outside the current file

☀ 单行超过120个字符警告(由SonarLint插件报告)
File > Settings > Tools > SonarLint > Rules > PHP > Lines should not be too long > Options > maximumLineLength

Copyright © 2024 码农人生. All Rights Reserved